diff options
Diffstat (limited to 'www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/SQLStore/Lookup/UnusedPropertyListLookupTest.php')
-rw-r--r-- | www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/SQLStore/Lookup/UnusedPropertyListLookupTest.php | 217 |
1 files changed, 217 insertions, 0 deletions
diff --git a/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/SQLStore/Lookup/UnusedPropertyListLookupTest.php b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/SQLStore/Lookup/UnusedPropertyListLookupTest.php new file mode 100644 index 00000000..01599519 --- /dev/null +++ b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/SQLStore/Lookup/UnusedPropertyListLookupTest.php @@ -0,0 +1,217 @@ +<?php + +namespace SMW\Tests\SQLStore\Lookup; + +use SMW\DIProperty; +use SMW\RequestOptions; +use SMW\SQLStore\Lookup\UnusedPropertyListLookup; +use SMW\Tests\PHPUnitCompat; + +/** + * @covers \SMW\SQLStore\Lookup\UnusedPropertyListLookup + * @group semantic-mediawiki + * + * @license GNU GPL v2+ + * @since 2.2 + * + * @author mwjames + */ +class UnusedPropertyListLookupTest extends \PHPUnit_Framework_TestCase { + + use PHPUnitCompat; + + private $store; + private $propertyStatisticsStore; + private $requestOptions; + + protected function setUp() { + + $this->store = $this->getMockBuilder( '\SMW\SQLStore\SQLStore' ) + ->disableOriginalConstructor() + ->getMock(); + + $this->propertyStatisticsStore = $this->getMockBuilder( '\SMW\SQLStore\PropertyStatisticsStore' ) + ->disableOriginalConstructor() + ->getMock(); + + $this->requestOptions = $this->getMockBuilder( '\SMWRequestOptions' ) + ->disableOriginalConstructor() + ->getMock(); + } + + public function testCanConstruct() { + + $this->assertInstanceOf( + '\SMW\SQLStore\Lookup\UnusedPropertyListLookup', + new UnusedPropertyListLookup( $this->store, $this->propertyStatisticsStore, null ) + ); + } + + public function testListLookupInterfaceMethodAccess() { + + $instance = new UnusedPropertyListLookup( + $this->store, + $this->propertyStatisticsStore, + $this->requestOptions + ); + + $this->assertInternalType( + 'string', + $instance->getTimestamp() + ); + + $this->assertFalse( + $instance->isFromCache() + ); + + $this->assertContains( + 'UnusedPropertyListLookup', + $instance->getHash() + ); + } + + public function testLookupIdentifierChangedByRequestOptions() { + + $requestOptions = new RequestOptions(); + + $instance = new UnusedPropertyListLookup( + $this->store, + $this->propertyStatisticsStore, + $requestOptions + ); + + $lookupIdentifier = $instance->getHash(); + + $requestOptions->limit = 100; + + $instance = new UnusedPropertyListLookup( + $this->store, + $this->propertyStatisticsStore, + $requestOptions + ); + + $this->assertNotSame( + $lookupIdentifier, + $instance->getHash() + ); + } + + public function testTryTofetchListForMissingOptionsThrowsException() { + + $instance = new UnusedPropertyListLookup( + $this->store, + $this->propertyStatisticsStore + ); + + $this->setExpectedException( 'RuntimeException' ); + $instance->fetchList(); + } + + public function testfetchListForValidProperty() { + + $idTable = $this->getMockBuilder( '\stdClass' ) + ->disableOriginalConstructor() + ->setMethods( [ 'getIdTable' ] ) + ->getMock(); + + $row = new \stdClass; + $row->smw_title = 'Foo'; + + $connection = $this->getMockBuilder( '\SMW\MediaWiki\Database' ) + ->disableOriginalConstructor() + ->getMock(); + + $connection->expects( $this->any() ) + ->method( 'select' ) + ->will( $this->returnValue( [ $row ] ) ); + + $this->store->expects( $this->any() ) + ->method( 'getConnection' ) + ->will( $this->returnValue( $connection ) ); + + $this->store->expects( $this->any() ) + ->method( 'getObjectIds' ) + ->will( $this->returnValue( $idTable ) ); + + $instance = new UnusedPropertyListLookup( + $this->store, + $this->propertyStatisticsStore, + $this->requestOptions + ); + + $result = $instance->fetchList(); + + $this->assertInternalType( + 'array', + $result + ); + + $expected = [ + new DIProperty( 'Foo' ) + ]; + + $this->assertEquals( + $expected, + $result + ); + } + + public function testfetchListForInvalidProperty() { + + $idTable = $this->getMockBuilder( '\stdClass' ) + ->disableOriginalConstructor() + ->setMethods( [ 'getIdTable' ] ) + ->getMock(); + + $row = new \stdClass; + $row->smw_title = '-Foo'; + + $connection = $this->getMockBuilder( '\SMW\MediaWiki\Database' ) + ->disableOriginalConstructor() + ->getMock(); + + $connection->expects( $this->any() ) + ->method( 'select' ) + ->with( + $this->anything(), + $this->anything(), + $this->anything(), + $this->anything(), + $this->equalTo( [ 'ORDER BY' => 'smw_sort', 'LIMIT' => 1001, 'OFFSET' => 0 ] ), + $this->anything() ) + ->will( $this->returnValue( [ $row ] ) ); + + $this->store->expects( $this->any() ) + ->method( 'getConnection' ) + ->will( $this->returnValue( $connection ) ); + + $this->store->expects( $this->any() ) + ->method( 'getObjectIds' ) + ->will( $this->returnValue( $idTable ) ); + + $requestOptions = $this->getMockBuilder( '\SMWRequestOptions' ) + ->disableOriginalConstructor() + ->getMock(); + + $this->requestOptions->limit = 1001; + + $instance = new UnusedPropertyListLookup( + $this->store, + $this->propertyStatisticsStore, + $this->requestOptions + ); + + $result = $instance->fetchList(); + + $this->assertInternalType( + 'array', + $result + ); + + $this->assertInstanceOf( + '\SMWDIError', + $result[0] + ); + } + +} |