diff options
Diffstat (limited to 'www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/Maintenance/ConceptCacheRebuilderTest.php')
-rw-r--r-- | www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/Maintenance/ConceptCacheRebuilderTest.php | 224 |
1 files changed, 224 insertions, 0 deletions
diff --git a/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/Maintenance/ConceptCacheRebuilderTest.php b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/Maintenance/ConceptCacheRebuilderTest.php new file mode 100644 index 00000000..0751d743 --- /dev/null +++ b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/Maintenance/ConceptCacheRebuilderTest.php @@ -0,0 +1,224 @@ +<?php + +namespace SMW\Tests\Maintenance; + +use SMW\DIConcept; +use SMW\Maintenance\ConceptCacheRebuilder; + +/** + * @covers \SMW\Maintenance\ConceptCacheRebuilder + * @group semantic-mediawiki + * + * @license GNU GPL v2+ + * @since 1.9.2 + * + * @author mwjames + */ +class ConceptCacheRebuilderTest extends \PHPUnit_Framework_TestCase { + + public function testCanConstruct() { + + $store = $this->getMockForAbstractClass( '\SMW\Store' ); + + $settings = $this->getMockBuilder( '\SMW\Settings' ) + ->disableOriginalConstructor() + ->getMock(); + + $this->assertInstanceOf( + '\SMW\Maintenance\ConceptCacheRebuilder', + new ConceptCacheRebuilder( $store, $settings ) + ); + } + + /** + * @depends testCanConstruct + */ + public function testRebuildWithoutOptionsAndActions() { + + $store = $this->getMockForAbstractClass( '\SMW\Store' ); + + $settings = $this->getMockBuilder( '\SMW\Settings' ) + ->disableOriginalConstructor() + ->getMock(); + + $instance = new ConceptCacheRebuilder( + $store, + $settings + ); + + $this->assertFalse( $instance->rebuild() ); + } + + /** + * @dataProvider actionProvider + */ + public function testRebuildFullConceptWithoutRangeSelectionOnMockStore( $action ) { + + $concept = new DIConcept( 'Foo', '', '', '', '' ); + + $concept->setCacheStatus( 'full' ); + $concept->setCacheDate( '1358515326' ); + $concept->setCacheCount( '1000' ); + + $instance = $this->acquireInstanceFor( $concept ); + + $instance->setParameters( [ + $action => true + ] ); + + $this->assertTrue( $instance->rebuild() ); + } + + /** + * @dataProvider actionProvider + */ + public function testRebuildEmptyConceptWithoutRangeSelectionOnMockStore( $action ) { + + $concept = new DIConcept( 'Foo', '', '', '', '' ); + $concept->setCacheStatus( 'empty' ); + + $instance = $this->acquireInstanceFor( $concept ); + + $instance->setParameters( [ + $action => true + ] ); + + $this->assertTrue( $instance->rebuild() ); + } + + /** + * @dataProvider actionProvider + */ + public function testRebuildFullConceptWithRangeSelectionOnMockStore( $action ) { + + $concept = new DIConcept( 'Foo', '', '', '', '' ); + + $concept->setCacheStatus( 'full' ); + $concept->setCacheDate( '1358515326' ); + $concept->setCacheCount( '1000' ); + + $instance = $this->acquireInstanceFor( $concept ); + + $instance->setParameters( [ + $action => true, + 's' => 0, + 'e' => 90000 + ] ); + + $this->assertTrue( $instance->rebuild() ); + } + + /** + * @dataProvider actionProvider + */ + public function testRebuildSingleEmptyConceptWithRangeSelectionOnMockStore( $action ) { + + $concept = new DIConcept( 'Foo', '', '', '', '' ); + $concept->setCacheStatus( 'empty' ); + + $instance = $this->acquireInstanceFor( $concept ); + + $instance->setParameters( [ + $action => true, + 's' => 0, + 'e' => 90000 + ] ); + + $this->assertTrue( $instance->rebuild() ); + } + + /** + * @dataProvider actionProvider + */ + public function testRebuildSingleFullConceptOnMockStore( $action ) { + + $concept = new DIConcept( 'Foo', '', '', '', '' ); + + $concept->setCacheStatus( 'full' ); + $concept->setCacheDate( '1358515326' ); + $concept->setCacheCount( '1000' ); + + $instance = $this->acquireInstanceFor( $concept ); + + $instance->setParameters( [ + $action => true, + 'old' => 10, + 'concept' => 'Bar' + ] ); + + $this->assertTrue( $instance->rebuild() ); + } + + /** + * @dataProvider actionProvider + */ + public function testRebuildWithNullConceptOnMockStore( $action ) { + + $instance = $this->acquireInstanceFor( null ); + + $instance->setParameters( [ + $action => true, + 'concept' => 'Bar' + ] ); + + $this->assertTrue( $instance->rebuild() ); + } + + private function acquireInstanceFor( $concept = null ) { + + $expectedToRun = $concept !== null ? $this->any() : $this->never(); + $refreshConceptCacheReturn = $concept !== null ? $concept->getConceptQuery() : null; + + $row = new \stdClass; + $row->page_namespace = 0; + $row->page_title = 1; + + $database = $this->getMockBuilder( '\SMW\MediaWiki\Database' ) + ->disableOriginalConstructor() + ->getMock(); + + $database->expects( $expectedToRun ) + ->method( 'select' ) + ->will( $this->returnValue( [ $row ] ) ); + + $store = $this->getMockBuilder( 'SMWSQLStore3' ) + ->disableOriginalConstructor() + ->getMock(); + + $store->expects( $this->once() ) + ->method( 'getConceptCacheStatus' ) + ->will( $this->returnValue( $concept ) ); + + $store->expects( $expectedToRun ) + ->method( 'refreshConceptCache' ) + ->will( $this->returnValue( [ $refreshConceptCacheReturn ] ) ); + + $store->expects( $expectedToRun ) + ->method( 'getConnection' ) + ->will( $this->returnValue( $database ) ); + + $settings = $this->getMockBuilder( '\SMW\Settings' ) + ->disableOriginalConstructor() + ->getMock(); + + $instance = new ConceptCacheRebuilder( + $store, + $settings + ); + + $instance->setParameters( [ + 'quiet' => true, + ] ); + + return $instance; + } + + public function actionProvider() { + return [ + [ 'status' ], + [ 'create' ], + [ 'delete' ] + ]; + } + +} |