diff options
Diffstat (limited to 'www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/DataValues/ValueParsers/AllowsListValueParserTest.php')
-rw-r--r-- | www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/DataValues/ValueParsers/AllowsListValueParserTest.php | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/DataValues/ValueParsers/AllowsListValueParserTest.php b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/DataValues/ValueParsers/AllowsListValueParserTest.php new file mode 100644 index 00000000..71c129a9 --- /dev/null +++ b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/DataValues/ValueParsers/AllowsListValueParserTest.php @@ -0,0 +1,76 @@ +<?php + +namespace SMW\Tests\DataValues\ValueParsers; + +use SMW\DataValues\ValueParsers\AllowsListValueParser; + +/** + * @covers \SMW\DataValues\ValueParsers\AllowsListValueParser + * @group semantic-mediawiki + * + * @license GNU GPL v2+ + * @since 2.5 + * + * @author mwjames + */ +class AllowsListValueParserTest extends \PHPUnit_Framework_TestCase { + + private $mediaWikiNsContentReader; + + protected function setUp() { + $this->mediaWikiNsContentReader = $this->getMockBuilder( '\SMW\MediaWiki\MediaWikiNsContentReader' ) + ->disableOriginalConstructor() + ->getMock(); + } + + public function testCanConstruct() { + + $this->assertInstanceOf( + '\SMW\DataValues\ValueParsers\AllowsListValueParser', + new AllowsListValueParser( $this->mediaWikiNsContentReader ) + ); + } + + public function testParseAndMatchFromResource() { + + $this->mediaWikiNsContentReader->expects( $this->once() ) + ->method( 'read' ) + ->will( $this->returnValue( " \n*Foo\n**Foobar|bar\n" ) ); + + $instance = new AllowsListValueParser( + $this->mediaWikiNsContentReader + ); + + $this->assertEquals( + [ + 'Foo' => 'Foo', + 'Foobar' => 'bar' + ], + $instance->parse( 'Bar' ) + ); + } + + public function testParseAndMatchFromJSON() { + + $contents = json_encode( [ 'Foo' => 'Foo', 'Foobar' => 'fooooo bar' ] ); + + $this->mediaWikiNsContentReader->expects( $this->once() ) + ->method( 'read' ) + ->will( $this->returnValue( $contents ) ); + + $instance = new AllowsListValueParser( + $this->mediaWikiNsContentReader + ); + + $instance->clear(); + + $this->assertEquals( + [ + 'Foo' => 'Foo', + 'Foobar' => 'fooooo bar' + ], + $instance->parse( 'Bar' ) + ); + } + +} |