diff options
Diffstat (limited to 'www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/MediaWiki/Jobs/ChangePropagationDispatchJobTest.php')
-rw-r--r-- | www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/MediaWiki/Jobs/ChangePropagationDispatchJobTest.php | 229 |
1 files changed, 229 insertions, 0 deletions
diff --git a/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/MediaWiki/Jobs/ChangePropagationDispatchJobTest.php b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/MediaWiki/Jobs/ChangePropagationDispatchJobTest.php new file mode 100644 index 00000000..9609828b --- /dev/null +++ b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/MediaWiki/Jobs/ChangePropagationDispatchJobTest.php @@ -0,0 +1,229 @@ +<?php + +namespace SMW\Tests\MediaWiki\Jobs; + +use SMW\DIWikiPage; +use SMW\MediaWiki\Jobs\ChangePropagationDispatchJob; +use SMW\Tests\TestEnvironment; + +/** + * @covers \SMW\MediaWiki\Jobs\ChangePropagationDispatchJob + * @group semantic-mediawiki + * + * @license GNU GPL v2+ + * @since 3.0 + * + * @author mwjames + */ +class ChangePropagationDispatchJobTest extends \PHPUnit_Framework_TestCase { + + private $testEnvironment; + + protected function setUp() { + parent::setUp(); + + $this->testEnvironment = new TestEnvironment(); + + $store = $this->getMockBuilder( '\SMW\SQLStore\SQLStore' ) + ->disableOriginalConstructor() + ->getMock(); + + $this->testEnvironment->registerObject( 'Store', $store ); + } + + protected function tearDown() { + $this->testEnvironment->tearDown(); + parent::tearDown(); + } + + public function testCanConstruct() { + + $title = $this->getMockBuilder( 'Title' ) + ->disableOriginalConstructor() + ->getMock(); + + $this->assertInstanceOf( + ChangePropagationDispatchJob::class, + new ChangePropagationDispatchJob( $title ) + ); + } + + public function testCleanUp() { + + $subject = DIWikiPage::newFromText(__METHOD__, SMW_NS_PROPERTY ); + + $cache = $this->getMockBuilder( '\Onoi\Cache\Cache' ) + ->getMockForAbstractClass(); + + $cache->expects( $this->once() ) + ->method( 'delete' ); + + $this->testEnvironment->registerObject( 'Cache', $cache ); + + ChangePropagationDispatchJob::cleanUp( $subject ); + } + + public function testHasPendingJobs() { + + $subject = DIWikiPage::newFromText( 'Foo' ); + + $jobQueue = $this->getMockBuilder( '\SMW\MediaWiki\JobQueue' ) + ->disableOriginalConstructor() + ->getMock(); + + $this->testEnvironment->registerObject( 'JobQueue', $jobQueue ); + + $cache = $this->getMockBuilder( '\Onoi\Cache\Cache' ) + ->getMockForAbstractClass(); + + $cache->expects( $this->once() ) + ->method( 'fetch' ) + ->will( $this->returnValue( 42 ) ); + + $this->testEnvironment->registerObject( 'Cache', $cache ); + + $this->assertTrue( + ChangePropagationDispatchJob::hasPendingJobs( $subject ) + ); + } + + public function testGetPendingJobsCount() { + + $subject = DIWikiPage::newFromText( 'Foo' ); + + $jobQueue = $this->getMockBuilder( '\SMW\MediaWiki\JobQueue' ) + ->disableOriginalConstructor() + ->getMock(); + + $this->testEnvironment->registerObject( 'JobQueue', $jobQueue ); + + $cache = $this->getMockBuilder( '\Onoi\Cache\Cache' ) + ->getMockForAbstractClass(); + + $cache->expects( $this->atLeastOnce() ) + ->method( 'fetch' ) + ->will( $this->returnValue( 42 ) ); + + $this->testEnvironment->registerObject( 'Cache', $cache ); + + $this->assertSame( + 42, + ChangePropagationDispatchJob::getPendingJobsCount( $subject ) + ); + } + + public function testFindAndDispatchOnNonPropertyEntity() { + + $subject = DIWikiPage::newFromText( 'Foo' ); + + $jobQueue = $this->getMockBuilder( '\SMW\MediaWiki\JobQueue' ) + ->disableOriginalConstructor() + ->getMock(); + + $jobQueue->expects( $this->never() ) + ->method( 'lazyPush' ); + + $this->testEnvironment->registerObject( 'JobQueue', $jobQueue ); + + $instance = new ChangePropagationDispatchJob( + $subject->getTitle() + ); + + $instance->run(); + } + + public function testPlanAsJob() { + + $subject = DIWikiPage::newFromText( 'Foo' ); + + $jobQueue = $this->getMockBuilder( '\SMW\MediaWiki\JobQueue' ) + ->disableOriginalConstructor() + ->getMock(); + + $jobQueue->expects( $this->once() ) + ->method( 'lazyPush' ); + + $this->testEnvironment->registerObject( 'JobQueue', $jobQueue ); + + ChangePropagationDispatchJob::planAsJob( $subject ); + } + + public function testFindAndDispatchOnPropertyEntity() { + + $subject = DIWikiPage::newFromText( 'Foo', SMW_NS_PROPERTY ); + + $tempFile = $this->getMockBuilder( '\SMW\Utils\TempFile' ) + ->disableOriginalConstructor() + ->getMock(); + + $tempFile->expects( $this->atLeastOnce() ) + ->method( 'write' ); + + $this->testEnvironment->registerObject( 'TempFile', $tempFile ); + + $jobQueue = $this->getMockBuilder( '\SMW\MediaWiki\JobQueue' ) + ->disableOriginalConstructor() + ->getMock(); + + $jobQueue->expects( $this->atLeastOnce() ) + ->method( 'lazyPush' ); + + $this->testEnvironment->registerObject( 'JobQueue', $jobQueue ); + + $idTable = $this->getMockBuilder( '\stdClass' ) + ->setMethods( [ 'getSMWPropertyID' ] ) + ->getMock(); + + $propertyTableInfoFetcher = $this->getMockBuilder( '\SMW\SQLStore\PropertyTableInfoFetcher' ) + ->disableOriginalConstructor() + ->getMock(); + + $propertyTableInfoFetcher->expects( $this->atLeastOnce() ) + ->method( 'getDefaultDataItemTables' ) + ->will( $this->returnValue( [] ) ); + + $connection = $this->getMockBuilder( '\SMW\MediaWiki\Database' ) + ->disableOriginalConstructor() + ->getMock(); + + $store = $this->getMockBuilder( '\SMW\SQLStore\SQLStore' ) + ->disableOriginalConstructor() + ->getMock(); + + $store->expects( $this->atLeastOnce() ) + ->method( 'getPropertyTableInfoFetcher' ) + ->will( $this->returnValue( $propertyTableInfoFetcher ) ); + + $store->expects( $this->atLeastOnce() ) + ->method( 'getAllPropertySubjects' ) + ->will( $this->returnValue( [] ) ); + + $store->expects( $this->atLeastOnce() ) + ->method( 'getPropertySubjects' ) + ->will( $this->returnValue( [] ) ); + + $store->expects( $this->any() ) + ->method( 'getPropertyValues' ) + ->will( $this->returnValue( [] ) ); + + $store->expects( $this->atLeastOnce() ) + ->method( 'getObjectIds' ) + ->will( $this->returnValue( $idTable ) ); + + $store->expects( $this->atLeastOnce() ) + ->method( 'getConnection' ) + ->will( $this->returnValue( $connection ) ); + + $this->testEnvironment->registerObject( 'Store', $store ); + + $instance = new ChangePropagationDispatchJob( + $subject->getTitle(), + [ + 'isTypePropagation' => true + ] + ); + + $instance->run(); + } + +} |