diff options
Diffstat (limited to 'www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/DataValues/ValueParsers/PropertyValueParserTest.php')
-rw-r--r-- | www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/DataValues/ValueParsers/PropertyValueParserTest.php | 171 |
1 files changed, 171 insertions, 0 deletions
diff --git a/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/DataValues/ValueParsers/PropertyValueParserTest.php b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/DataValues/ValueParsers/PropertyValueParserTest.php new file mode 100644 index 00000000..ef475a98 --- /dev/null +++ b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/DataValues/ValueParsers/PropertyValueParserTest.php @@ -0,0 +1,171 @@ +<?php + +namespace SMW\Tests\DataValues\ValueParsers; + +use SMW\DataValues\ValueParsers\PropertyValueParser; + +/** + * @covers \SMW\DataValues\ValueParsers\PropertyValueParser + * @group semantic-mediawiki + * + * @license GNU GPL v2+ + * @since 2.5 + * + * @author mwjames + */ +class PropertyValueParserTest extends \PHPUnit_Framework_TestCase { + + public function testCanConstruct() { + + $this->assertInstanceOf( + PropertyValueParser::class, + new PropertyValueParser() + ); + } + + /** + * @dataProvider nameProvider + */ + public function testParse( $value, $invalidCharacterList, $expectedPropertyName, $expectedInverse ) { + + $instance = new PropertyValueParser(); + $instance->setInvalidCharacterList( + $invalidCharacterList + ); + + list( $propertyName, $capitalizedName, $inverse ) = $instance->parse( $value ); + + $this->assertSame( + $expectedPropertyName, + $propertyName + ); + + $this->assertSame( + $expectedInverse, + $inverse + ); + } + + public function testEnforceFirstCharUpperCase() { + + $instance = new PropertyValueParser(); + $instance->isCapitalLinks( false ); + $instance->reqCapitalizedFirstChar( true ); + + list( $propertyName, $capitalizedName, $inverse ) = $instance->parse( 'foo' ); + + $this->assertSame( + 'foo', + $propertyName + ); + + $this->assertSame( + 'Foo', + $capitalizedName + ); + } + + public function nameProvider() { + + $provider[] = [ + 'Foo', + [], + 'Foo', + false + ]; + + $provider[] = [ + '[ Foo', + [], + 'Foo', + false + ]; + + $provider[] = [ + '[Foo', + [], + 'Foo', + false + ]; + + $provider[] = [ + 'Foo ]', + [], + 'Foo', + false + ]; + + $provider[] = [ + 'Foo]', + [], + 'Foo', + false + ]; + + $provider[] = [ + '-Foo', + [], + 'Foo', + true + ]; + + $provider[] = [ + '<Foo>', + [ '<', '>' ], + null, + null + ]; + + $provider[] = [ + '<Foo-<Bar>', + [ '<', '>' ], + null, + null + ]; + + $provider[] = [ + 'Foo-<Bar', + [ '<', '>' ], + 'Foo-', + false + ]; + + $provider[] = [ + 'Foo#Bar', + [], + null, + null + ]; + + $provider[] = [ + 'Foo|Bar', + [ '|' ], + null, + null + ]; + + $provider[] = [ + 'Foo.Bar', + [], + null, + null + ]; + + $provider[] = [ + 'Foo[Bar', + [ '[', ']' ], + null, + null + ]; + + $provider[] = [ + 'Foo]Bar', + [ '[', ']' ], + null, + null + ]; + + return $provider; + } + +} |