diff options
Diffstat (limited to 'www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/SQLStore/QueryEngine/HierarchyTempTableBuilderTest.php')
-rw-r--r-- | www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/SQLStore/QueryEngine/HierarchyTempTableBuilderTest.php | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/SQLStore/QueryEngine/HierarchyTempTableBuilderTest.php b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/SQLStore/QueryEngine/HierarchyTempTableBuilderTest.php new file mode 100644 index 00000000..b01b114e --- /dev/null +++ b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/SQLStore/QueryEngine/HierarchyTempTableBuilderTest.php @@ -0,0 +1,110 @@ +<?php + +namespace SMW\Tests\SQLStore\QueryEngine; + +use SMW\SQLStore\QueryEngine\HierarchyTempTableBuilder; +use SMW\Tests\PHPUnitCompat; + +/** + * @covers \SMW\SQLStore\QueryEngine\HierarchyTempTableBuilder + * @group semantic-mediawiki + * + * @license GNU GPL v2+ + * @since 2.3 + * + * @author mwjames + */ +class HierarchyTempTableBuilderTest extends \PHPUnit_Framework_TestCase { + + use PHPUnitCompat; + + private $connection; + private $temporaryTableBuilder; + + protected function setUp() { + + $this->connection = $this->getMockBuilder( '\SMW\MediaWiki\Database' ) + ->disableOriginalConstructor() + ->getMock(); + + $this->temporaryTableBuilder = $this->getMockBuilder( '\SMW\SQLStore\TableBuilder\TemporaryTableBuilder' ) + ->disableOriginalConstructor() + ->getMock(); + } + + public function testCanConstruct() { + + $this->assertInstanceOf( + '\SMW\SQLStore\QueryEngine\HierarchyTempTableBuilder', + new HierarchyTempTableBuilder( $this->connection, $this->temporaryTableBuilder ) + ); + } + + public function testGetHierarchyTableDefinitionForType() { + + $this->connection->expects( $this->once() ) + ->method( 'tableName' ) + ->with( + $this->stringContains( 'bar') ) + ->will( $this->returnValue( '_bar' ) ); + + $instance = new HierarchyTempTableBuilder( + $this->connection, + $this->temporaryTableBuilder + ); + + $instance->setPropertyHierarchyTableDefinition( 'bar', 3 ); + + $this->assertEquals( + [ '_bar', 3 ], + $instance->getHierarchyTableDefinitionForType( 'property' ) + ); + } + + public function testTryToGetHierarchyTableDefinitionForUnregisteredTypeThrowsException() { + + $instance = new HierarchyTempTableBuilder( + $this->connection, + $this->temporaryTableBuilder + ); + + $this->setExpectedException( 'RuntimeException' ); + $instance->getHierarchyTableDefinitionForType( 'foo' ); + } + + public function testCreateHierarchyTempTable() { + + $this->connection->expects( $this->once() ) + ->method( 'tableName' ) + ->with( + $this->stringContains( 'bar') ) + ->will( $this->returnValue( '_bar' ) ); + + $this->connection->expects( $this->atLeastOnce() ) + ->method( 'query' ); + + $instance = new HierarchyTempTableBuilder( + $this->connection, + $this->temporaryTableBuilder + ); + + $instance->setClassHierarchyTableDefinition( 'bar', 3 ); + $instance->createHierarchyTempTableFor( 'class', 'foobar', '(42)' ); + + $expected = [ + '(42)' => 'foobar' + ]; + + $this->assertEquals( + $expected, + $instance->getHierarchyCache() + ); + + $instance->emptyHierarchyCache(); + + $this->assertEmpty( + $instance->getHierarchyCache() + ); + } + +} |