diff options
Diffstat (limited to 'www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/Query/ProfileAnnotators/ParametersProfileAnnotatorTest.php')
-rw-r--r-- | www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/Query/ProfileAnnotators/ParametersProfileAnnotatorTest.php | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/Query/ProfileAnnotators/ParametersProfileAnnotatorTest.php b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/Query/ProfileAnnotators/ParametersProfileAnnotatorTest.php new file mode 100644 index 00000000..00409cf9 --- /dev/null +++ b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/Query/ProfileAnnotators/ParametersProfileAnnotatorTest.php @@ -0,0 +1,90 @@ +<?php + +namespace SMW\Tests\Query\ProfileAnnotators; + +use SMW\DIWikiPage; +use SMW\Query\ProfileAnnotators\NullProfileAnnotator; +use SMW\Query\ProfileAnnotators\ParametersProfileAnnotator; +use SMW\Tests\Utils\UtilityFactory; +use SMWContainerSemanticData as ContainerSemanticData; +use SMWDIContainer as DIContainer; + +/** + * @covers \SMW\Query\ProfileAnnotators\ParametersProfileAnnotator + * @group semantic-mediawiki + * + * @license GNU GPL v2+ + * @since 1.9 + * + * @author mwjames + */ +class ParametersProfileAnnotatorTest extends \PHPUnit_Framework_TestCase { + + private $semanticDataValidator; + + protected function setUp() { + parent::setUp(); + + $this->semanticDataValidator = UtilityFactory::getInstance()->newValidatorFactory()->newSemanticDataValidator(); + } + + public function testCanConstruct() { + + $profileAnnotator = $this->getMockBuilder( '\SMW\Query\ProfileAnnotator' ) + ->disableOriginalConstructor() + ->getMock(); + + $query = $this->getMockBuilder( '\SMWQuery' ) + ->disableOriginalConstructor() + ->getMock(); + + $this->assertInstanceOf( + '\SMW\Query\ProfileAnnotators\ParametersProfileAnnotator', + new ParametersProfileAnnotator( $profileAnnotator, $query ) + ); + } + + public function testCreateProfile() { + + $subject =new DIWikiPage( __METHOD__, NS_MAIN, '', 'foo' ); + + $container = new DIContainer( + new ContainerSemanticData( $subject ) + ); + + $query = $this->getMockBuilder( '\SMWQuery' ) + ->disableOriginalConstructor() + ->getMock(); + + $query->expects( $this->once() ) + ->method( 'getLimit' ) + ->will( $this->returnValue( 42 ) ); + + $query->expects( $this->once() ) + ->method( 'getOffset' ) + ->will( $this->returnValue( 0 ) ); + + $query->expects( $this->once() ) + ->method( 'getQueryMode' ) + ->will( $this->returnValue( 1 ) ); + + $instance = new ParametersProfileAnnotator( + new NullProfileAnnotator( $container ), + $query + ); + + $instance->addAnnotation(); + + $expected = [ + 'propertyCount' => 1, + 'propertyKeys' => [ '_ASKPA' ], + 'propertyValues' => [ '{"limit":42,"offset":0,"sort":[],"order":[],"mode":1}' ] + ]; + + $this->semanticDataValidator->assertThatPropertiesAreSet( + $expected, + $instance->getContainer()->getSemanticData() + ); + } + +} |