summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/MediaWiki/Api/Browse/ArticleAugmentorTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/MediaWiki/Api/Browse/ArticleAugmentorTest.php')
-rw-r--r--www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/MediaWiki/Api/Browse/ArticleAugmentorTest.php154
1 files changed, 154 insertions, 0 deletions
diff --git a/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/MediaWiki/Api/Browse/ArticleAugmentorTest.php b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/MediaWiki/Api/Browse/ArticleAugmentorTest.php
new file mode 100644
index 00000000..7b15550b
--- /dev/null
+++ b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/MediaWiki/Api/Browse/ArticleAugmentorTest.php
@@ -0,0 +1,154 @@
+<?php
+
+namespace SMW\Tests\MediaWiki\Api\Browse;
+
+use SMW\MediaWiki\Api\Browse\ArticleAugmentor;
+
+/**
+ * @covers \SMW\MediaWiki\Api\Browse\ArticleAugmentor
+ * @group semantic-mediawiki
+ *
+ * @license GNU GPL v2+
+ * @since 3.0
+ *
+ * @author mwjames
+ */
+class ArticleAugmentorTest extends \PHPUnit_Framework_TestCase {
+
+ public function testCanConstruct() {
+
+ $titleFactory = $this->getMockBuilder( '\SMW\MediaWiki\TitleFactory' )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $this->assertInstanceOf(
+ ArticleAugmentor::class,
+ new ArticleAugmentor( $titleFactory )
+ );
+ }
+
+ public function testAugmentOnFullText() {
+
+ $res = [
+ 'query' => [
+ 'Foo#0' => [
+ 'id' => 42,
+ 'label' => 'Foo',
+ 'key' => 'Foo',
+ 'ns' => 0
+ ]
+ ],
+ 'query-continue-offset' => 0,
+ 'version' => 1,
+ 'meta' => [
+ 'type' => 'property',
+ 'limit' => 50,
+ 'count' => 1
+ ]
+ ];
+
+ $parameters = [
+ 'fullText' => true
+ ];
+
+ $expected = [
+ 'Foo#0' => [
+ 'label' => 'Foo',
+ 'key' => 'Foo',
+ 'ns' => 0,
+ 'fullText' => 'NS:FOO'
+ ]
+ ];
+
+ $title = $this->getMockBuilder( '\Title' )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $title->expects( $this->any() )
+ ->method( 'getFullText' )
+ ->will( $this->returnValue( 'NS:FOO' ) );
+
+ $titleFactory = $this->getMockBuilder( '\SMW\MediaWiki\TitleFactory' )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $titleFactory->expects( $this->any() )
+ ->method( 'newFromID' )
+ ->with( $this->equalTo( 42 ) )
+ ->will( $this->returnValue( $title ) );
+
+ $instance = new ArticleAugmentor(
+ $titleFactory
+ );
+
+ $instance->augment( $res, $parameters );
+
+ $this->assertEquals(
+ $res['query'],
+ $expected
+ );
+ }
+
+ public function testAugmentOnFullURL() {
+
+ $res = [
+ 'query' => [
+ 'Foo#0' => [
+ 'id' => 42,
+ 'label' => 'Foo',
+ 'key' => 'Foo',
+ 'ns' => 0
+ ]
+ ],
+ 'query-continue-offset' => 0,
+ 'version' => 1,
+ 'meta' => [
+ 'type' => 'property',
+ 'limit' => 50,
+ 'count' => 1
+ ]
+ ];
+
+ $parameters = [
+ 'fullURL' => true
+ ];
+
+ $expected = [
+ 'Foo#0' => [
+ 'label' => 'Foo',
+ 'key' => 'Foo',
+ 'ns' => 0,
+ 'fullURL' => 'http://example.org/FOO'
+ ]
+ ];
+
+ $title = $this->getMockBuilder( '\Title' )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $title->expects( $this->any() )
+ ->method( 'getFullURL' )
+ ->will( $this->returnValue( 'http://example.org/FOO' ) );
+
+ $titleFactory = $this->getMockBuilder( '\SMW\MediaWiki\TitleFactory' )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $titleFactory->expects( $this->any() )
+ ->method( 'newFromID' )
+ ->with( $this->equalTo( 42 ) )
+ ->will( $this->returnValue( $title ) );
+
+ $instance = new ArticleAugmentor(
+ $titleFactory
+ );
+
+ $instance->augment( $res, $parameters );
+
+ $this->assertEquals(
+ $res['query'],
+ $expected
+ );
+ }
+
+}