diff options
Diffstat (limited to 'www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/PropertyAnnotators/RedirectPropertyAnnotatorTest.php')
-rw-r--r-- | www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/PropertyAnnotators/RedirectPropertyAnnotatorTest.php | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/PropertyAnnotators/RedirectPropertyAnnotatorTest.php b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/PropertyAnnotators/RedirectPropertyAnnotatorTest.php new file mode 100644 index 00000000..73b8b8cc --- /dev/null +++ b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/PropertyAnnotators/RedirectPropertyAnnotatorTest.php @@ -0,0 +1,116 @@ +<?php + +namespace SMW\Tests\PropertyAnnotators; + +use SMW\MediaWiki\RedirectTargetFinder; +use SMW\PropertyAnnotators\NullPropertyAnnotator; +use SMW\PropertyAnnotators\RedirectPropertyAnnotator; +use SMW\Tests\Utils\UtilityFactory; + +/** + * @covers \SMW\PropertyAnnotators\RedirectPropertyAnnotator + * @group semantic-mediawiki + * + * @license GNU GPL v2+ + * @since 1.9 + * + * @author mwjames + */ +class RedirectPropertyAnnotatorTest extends \PHPUnit_Framework_TestCase { + + private $semanticDataFactory; + private $semanticDataValidator; + + protected function setUp() { + parent::setUp(); + + $this->semanticDataFactory = UtilityFactory::getInstance()->newSemanticDataFactory(); + $this->semanticDataValidator = UtilityFactory::getInstance()->newValidatorFactory()->newSemanticDataValidator(); + } + + public function testCanConstruct() { + + $semanticData = $this->getMockBuilder( '\SMW\SemanticData' ) + ->disableOriginalConstructor() + ->getMock(); + + $redirectTargetFinder = $this->getMockBuilder( '\SMW\MediaWiki\RedirectTargetFinder' ) + ->disableOriginalConstructor() + ->getMock(); + + $instance = new RedirectPropertyAnnotator( + new NullPropertyAnnotator( $semanticData ), + $redirectTargetFinder + ); + + $this->assertInstanceOf( + '\SMW\PropertyAnnotators\RedirectPropertyAnnotator', + $instance + ); + } + + /** + * @dataProvider redirectsDataProvider + */ + public function testAddAnnotation( array $parameter, array $expected ) { + + $semanticData = $this->semanticDataFactory->newEmptySemanticData( __METHOD__ ); + + $redirectTargetFinder = new RedirectTargetFinder(); + + $instance = new RedirectPropertyAnnotator( + new NullPropertyAnnotator( $semanticData ), + $redirectTargetFinder->findRedirectTargetFromText( $parameter['text'] ) + ); + + $instance->addAnnotation(); + + $this->semanticDataValidator->assertThatPropertiesAreSet( + $expected, + $instance->getSemanticData() + ); + } + + public function redirectsDataProvider() { + + // #0 Free text + $provider[] = [ + [ 'text' => '#REDIRECT [[:Lala]]' ], + [ + 'propertyCount' => 1, + 'propertyKeys' => '_REDI', + 'propertyValues' => ':Lala' + ] + ]; + + // #1 Free text + $provider[] = [ + [ 'text' => '#REDIRECT [[Lala]]' ], + [ + 'propertyCount' => 1, + 'propertyKeys' => '_REDI', + 'propertyValues' => ':Lala' + ] + ]; + + + // #2 Invalid free text + $provider[] = [ + [ 'text' => '#REDIR [[:Lala]]' ], + [ + 'propertyCount' => 0, + ] + ]; + + // #3 Empty + $provider[] = [ + [ 'text' => '' ], + [ + 'propertyCount' => 0, + ] + ]; + + return $provider; + } + +} |