diff options
Diffstat (limited to 'www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/DataValues/ValueParsers/MonolingualTextValueParserTest.php')
-rw-r--r-- | www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/DataValues/ValueParsers/MonolingualTextValueParserTest.php | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/DataValues/ValueParsers/MonolingualTextValueParserTest.php b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/DataValues/ValueParsers/MonolingualTextValueParserTest.php new file mode 100644 index 00000000..2025d29a --- /dev/null +++ b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/DataValues/ValueParsers/MonolingualTextValueParserTest.php @@ -0,0 +1,91 @@ +<?php + +namespace SMW\Tests\DataValues\ValueParsers; + +use SMW\DataValues\ValueParsers\MonolingualTextValueParser; + +/** + * @covers \SMW\DataValues\ValueParsers\MonolingualTextValueParser + * @group semantic-mediawiki + * + * @license GNU GPL v2+ + * @since 2.4 + * + * @author mwjames + */ +class MonolingualTextValueParserTest extends \PHPUnit_Framework_TestCase { + + public function testCanConstruct() { + + $this->assertInstanceOf( + '\SMW\DataValues\ValueParsers\MonolingualTextValueParser', + new MonolingualTextValueParser() + ); + } + + /** + * @dataProvider fullStringProvider + */ + public function testFullParsableString( $value, $expectedText, $expectedLanguageCode ) { + + $instance = new MonolingualTextValueParser(); + list( $text, $languageCode ) = $instance->parse( $value ); + + $this->assertEquals( + $expectedText, + $text + ); + + $this->assertEquals( + $expectedLanguageCode, + $languageCode + ); + } + + public function testParsableStringWithMissingLanguageCode() { + + $instance = new MonolingualTextValueParser(); + list( $text, $languageCode ) = $instance->parse( 'FooBar' ); + + $this->assertEquals( + 'FooBar', + $text + ); + } + + public function fullStringProvider() { + + $provider[] = [ + 'Foo@EN', + 'Foo', + 'en' + ]; + + $provider[] = [ + 'testWith@example.org@zh-hans', + 'testWith@example.org', + 'zh-Hans' + ]; + + $provider[] = [ + [ 'EN' =>'Foo' ], + 'Foo', + 'en' + ]; + + $provider[] = [ + [ 'EN', 'Foo' ], + 'Foo', + '' + ]; + + $provider[] = [ + [ 'EN', [] ], + '', + '' + ]; + + return $provider; + } + +} |