Skip to content

Commit

Permalink
Improve test (#2121)
Browse files Browse the repository at this point in the history
  • Loading branch information
mwjames committed Dec 18, 2016
1 parent a212e30 commit e5842a0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 41 deletions.
Expand Up @@ -7,8 +7,7 @@
use SMW\ApplicationFactory;
use SMW\DIProperty;
use SMW\MediaWiki\Hooks\NewRevisionFromEditComplete;
use SMW\Settings;
use SMW\Tests\Utils\Validators\SemanticDataValidator;
use SMW\Tests\TestEnvironment;
use Title;
use WikiPage;

Expand All @@ -23,25 +22,25 @@
*/
class NewRevisionFromEditCompleteTest extends \PHPUnit_Framework_TestCase {

private $applicationFactory;
private $semanticDataValidator;
private $testEnvironment;

protected function setUp() {
parent::setUp();

$this->applicationFactory = ApplicationFactory::getInstance();
$this->semanticDataValidator = new SemanticDataValidator();
$this->testEnvironment = new TestEnvironment();

$this->semanticDataValidator = $this->testEnvironment->getUtilityFactory()->newValidatorFactory()->newSemanticDataValidator();

$store = $this->getMockBuilder( '\SMW\Store' )
->disableOriginalConstructor()
->getMockForAbstractClass();

$this->applicationFactory->registerObject( 'Store', $store );
$this->testEnvironment->registerObject( 'Store', $store );
}

protected function tearDown() {
$this->applicationFactory->clear();

$this->testEnvironment->tearDown();
parent::tearDown();
}

Expand Down Expand Up @@ -70,9 +69,8 @@ public function testCanConstruct() {
*/
public function testProcess( $parameters, $expected ) {

$this->applicationFactory->registerObject(
'Settings',
Settings::newFromArray( $parameters['settings'] )
$this->testEnvironment->withConfiguration(
$parameters['settings']
);

$instance = new NewRevisionFromEditComplete(
Expand All @@ -87,7 +85,7 @@ public function testProcess( $parameters, $expected ) {

if ( $editInfo && $editInfo->output instanceof ParserOutput ) {

$parserData = $this->applicationFactory->newParserData(
$parserData = ApplicationFactory::getInstance()->newParserData(
$parameters['wikiPage']->getTitle(),
$editInfo->output
);
Expand Down Expand Up @@ -158,10 +156,7 @@ public function wikiPageDataProvider() {
'revision' => $this->newRevisionStub(),
'settings' => array(
'smwgPageSpecialProperties' => array( DIProperty::TYPE_MODIFICATION_DATE ),
'smwgDVFeatures' => '',
'smwgQueryResultCacheType' => 'hash',
'smwgQueryResultCacheLifetime' => 60,
'smwgQueryResultNonEmbeddedCacheLifetime' => 60
'smwgDVFeatures' => ''
)
),
array(
Expand Down
41 changes: 16 additions & 25 deletions tests/phpunit/Unit/MediaWiki/Hooks/TitleMoveCompleteTest.php
Expand Up @@ -4,7 +4,7 @@

use SMW\ApplicationFactory;
use SMW\MediaWiki\Hooks\TitleMoveComplete;
use SMW\Settings;
use SMW\Tests\TestEnvironment;
use SMW\Tests\Utils\Mock\MockSuperUser;
use SMW\Tests\Utils\Mock\MockTitle;

Expand All @@ -19,19 +19,28 @@
*/
class TitleMoveCompleteTest extends \PHPUnit_Framework_TestCase {

private $applicationFactory;
private $user;
private $testEnvironment;

protected function setUp() {
parent::setUp();

$this->testEnvironment = new TestEnvironment();
$this->user = new MockSuperUser();
$this->applicationFactory = ApplicationFactory::getInstance();

$settings = array(
'smwgCacheType' => 'hash',
'smwgAutoRefreshOnPageMove' => true,
'smwgNamespacesWithSemanticLinks' => array( NS_MAIN => true, NS_HELP => false )
);

$this->testEnvironment->withConfiguration(
$settings
);
}

protected function tearDown() {
$this->applicationFactory->clear();

$this->testEnvironment->tearDown();
parent::tearDown();
}

Expand Down Expand Up @@ -66,16 +75,7 @@ public function testChangeSubjectForSupportedSemanticNamespace() {
$store->expects( $this->never() )
->method( 'changeTitle' );

$this->applicationFactory->registerObject( 'Settings', Settings::newFromArray( array(
'smwgCacheType' => 'hash',
'smwgAutoRefreshOnPageMove' => true,
'smwgNamespacesWithSemanticLinks' => array( NS_MAIN => true ),
'smwgQueryResultCacheType' => 'hash',
'smwgQueryResultCacheLifetime' => 60,
'smwgQueryResultNonEmbeddedCacheLifetime' => 60
) ) );

$this->applicationFactory->registerObject( 'Store', $store );
$this->testEnvironment->registerObject( 'Store', $store );

$instance = new TitleMoveComplete(
$oldTitle,
Expand Down Expand Up @@ -104,16 +104,7 @@ public function testDeleteSubjectForNotSupportedSemanticNamespace() {
->with(
$this->equalTo( $oldTitle ) );

$this->applicationFactory->registerObject( 'Settings', Settings::newFromArray( array(
'smwgCacheType' => 'hash',
'smwgAutoRefreshOnPageMove' => true,
'smwgNamespacesWithSemanticLinks' => array( NS_MAIN => true, NS_HELP => false ),
'smwgQueryResultCacheType' => 'hash',
'smwgQueryResultCacheLifetime' => 60,
'smwgQueryResultNonEmbeddedCacheLifetime' => 60
) ) );

$this->applicationFactory->registerObject( 'Store', $store );
$this->testEnvironment->registerObject( 'Store', $store );

$instance = new TitleMoveComplete(
$oldTitle,
Expand Down

0 comments on commit e5842a0

Please sign in to comment.