summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/Query/ProfileAnnotatorFactoryTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/Query/ProfileAnnotatorFactoryTest.php')
-rw-r--r--www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/Query/ProfileAnnotatorFactoryTest.php229
1 files changed, 229 insertions, 0 deletions
diff --git a/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/Query/ProfileAnnotatorFactoryTest.php b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/Query/ProfileAnnotatorFactoryTest.php
new file mode 100644
index 00000000..dcb030e4
--- /dev/null
+++ b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/Query/ProfileAnnotatorFactoryTest.php
@@ -0,0 +1,229 @@
+<?php
+
+namespace SMW\Tests\Query;
+
+use SMW\DIWikiPage;
+use SMW\Query\ProfileAnnotatorFactory;
+use SMWQuery as Query;
+
+/**
+ * @covers \SMW\Query\ProfileAnnotatorFactory
+ * @group semantic-mediawiki
+ *
+ * @license GNU GPL v2+
+ * @since 2.1
+ *
+ * @author mwjames
+ */
+class ProfileAnnotatorFactoryTest extends \PHPUnit_Framework_TestCase {
+
+ public function testCanConstruct() {
+
+ $this->assertInstanceOf(
+ '\SMW\Query\ProfileAnnotatorFactory',
+ new ProfileAnnotatorFactory()
+ );
+ }
+
+ public function testConstructDescriptionProfileAnnotator() {
+
+ $description = $this->getMockBuilder( '\SMW\Query\Language\Description' )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $query = $this->getMockBuilder( '\SMWQuery' )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $query->expects( $this->atLeastOnce() )
+ ->method( 'getContextPage' )
+ ->will( $this->returnValue( DIWikiPage::newFromText( __METHOD__ ) ) );
+
+ $query->expects( $this->once() )
+ ->method( 'getDescription' )
+ ->will( $this->returnValue( $description ) );
+
+ $instance = new ProfileAnnotatorFactory();
+
+ $this->assertInstanceOf(
+ '\SMW\Query\ProfileAnnotators\DescriptionProfileAnnotator',
+ $instance->newDescriptionProfileAnnotator( $query )
+ );
+ }
+
+ public function testConstructCombinedProfileAnnotator() {
+
+ $description = $this->getMockBuilder( '\SMW\Query\Language\Description' )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $query = $this->getMockBuilder( '\SMWQuery' )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $query->expects( $this->atLeastOnce() )
+ ->method( 'getContextPage' )
+ ->will( $this->returnValue( DIWikiPage::newFromText( __METHOD__ ) ) );
+
+ $query->expects( $this->once() )
+ ->method( 'getDescription' )
+ ->will( $this->returnValue( $description ) );
+
+ $instance = new ProfileAnnotatorFactory();
+
+ $this->assertInstanceOf(
+ '\SMW\Query\ProfileAnnotator',
+ $instance->newProfileAnnotator( $query, '' )
+ );
+ }
+
+ public function testConstructProfileAnnotatorsWithSourceAnnotator() {
+
+ $description = $this->getMockBuilder( '\SMW\Query\Language\Description' )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $query = $this->getMockBuilder( '\SMWQuery' )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $query->expects( $this->atLeastOnce() )
+ ->method( 'getContextPage' )
+ ->will( $this->returnValue( DIWikiPage::newFromText( __METHOD__ ) ) );
+
+ $query->expects( $this->once() )
+ ->method( 'getDescription' )
+ ->will( $this->returnValue( $description ) );
+
+ $query->expects( $this->once() )
+ ->method( 'getQuerySource' )
+ ->will( $this->returnValue( 'Foo' ) );
+
+ $instance = new ProfileAnnotatorFactory();
+
+ $this->assertInstanceOf(
+ '\SMW\Query\ProfileAnnotators\SourceProfileAnnotator',
+ $instance->newProfileAnnotator( $query, 'SomeFormat' )
+ );
+ }
+
+ public function testConstructProfileAnnotatorsWithDurationAnnotator() {
+
+ $description = $this->getMockBuilder( '\SMW\Query\Language\Description' )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $query = $this->getMockBuilder( '\SMWQuery' )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $query->expects( $this->atLeastOnce() )
+ ->method( 'getContextPage' )
+ ->will( $this->returnValue( DIWikiPage::newFromText( __METHOD__ ) ) );
+
+ $query->expects( $this->once() )
+ ->method( 'getDescription' )
+ ->will( $this->returnValue( $description ) );
+
+ $query->expects( $this->at( 4 ) )
+ ->method( 'getOption' )
+ ->with( $this->equalTo( Query::PROC_QUERY_TIME ) )
+ ->will( $this->returnValue( 42 ) );
+
+ $instance = new ProfileAnnotatorFactory();
+
+ $this->assertInstanceOf(
+ '\SMW\Query\ProfileAnnotators\DurationProfileAnnotator',
+ $instance->newProfileAnnotator( $query, 'SomeFormat' )
+ );
+ }
+
+ public function testConstructProfileAnnotatorsWithStatCodeAnnotator() {
+
+ $description = $this->getMockBuilder( '\SMW\Query\Language\Description' )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $query = $this->getMockBuilder( '\SMWQuery' )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $query->expects( $this->atLeastOnce() )
+ ->method( 'getContextPage' )
+ ->will( $this->returnValue( DIWikiPage::newFromText( __METHOD__ ) ) );
+
+ $query->expects( $this->once() )
+ ->method( 'getDescription' )
+ ->will( $this->returnValue( $description ) );
+
+ $query->expects( $this->at( 6 ) )
+ ->method( 'getOption' )
+ ->with( $this->equalTo( Query::PROC_STATUS_CODE ) )
+ ->will( $this->returnValue( [ 100 ] ) );
+
+ $instance = new ProfileAnnotatorFactory();
+
+ $this->assertInstanceOf(
+ '\SMW\Query\ProfileAnnotators\StatusCodeProfileAnnotator',
+ $instance->newProfileAnnotator( $query, 'SomeFormat' )
+ );
+ }
+
+ public function testConstructCombinedProfileAnnotatorOnNullContextPage() {
+
+ $description = $this->getMockBuilder( '\SMW\Query\Language\Description' )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $query = $this->getMockBuilder( '\SMWQuery' )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $query->expects( $this->atLeastOnce() )
+ ->method( 'getContextPage' )
+ ->will( $this->returnValue( null ) );
+
+ $query->expects( $this->once() )
+ ->method( 'getDescription' )
+ ->will( $this->returnValue( $description ) );
+
+ $instance = new ProfileAnnotatorFactory();
+
+ $this->assertInstanceOf(
+ '\SMW\Query\ProfileAnnotator',
+ $instance->newProfileAnnotator( $query, '' )
+ );
+ }
+
+ public function testConstructProfileAnnotators_SchemaLink() {
+
+ $description = $this->getMockBuilder( '\SMW\Query\Language\Description' )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $query = $this->getMockBuilder( '\SMWQuery' )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $query->expects( $this->atLeastOnce() )
+ ->method( 'getContextPage' )
+ ->will( $this->returnValue( DIWikiPage::newFromText( __METHOD__ ) ) );
+
+ $query->expects( $this->once() )
+ ->method( 'getDescription' )
+ ->will( $this->returnValue( $description ) );
+
+ $query->expects( $this->at( 7 ) )
+ ->method( 'getOption' )
+ ->with( $this->equalTo( 'schema_link' ) )
+ ->will( $this->returnValue( 'Foo' ) );
+
+ $instance = new ProfileAnnotatorFactory();
+
+ $this->assertInstanceOf(
+ '\SMW\Query\ProfileAnnotators\SchemaLinkProfileAnnotator',
+ $instance->newProfileAnnotator( $query, 'SomeFormat' )
+ );
+ }
+
+}