diff options
Diffstat (limited to 'www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/PropertyAnnotators/TranslationPropertyAnnotatorTest.php')
-rw-r--r-- | www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/PropertyAnnotators/TranslationPropertyAnnotatorTest.php | 160 |
1 files changed, 160 insertions, 0 deletions
diff --git a/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/PropertyAnnotators/TranslationPropertyAnnotatorTest.php b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/PropertyAnnotators/TranslationPropertyAnnotatorTest.php new file mode 100644 index 00000000..154f6653 --- /dev/null +++ b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/PropertyAnnotators/TranslationPropertyAnnotatorTest.php @@ -0,0 +1,160 @@ +<?php + +namespace SMW\Tests\PropertyAnnotators; + +use SMW\DataItemFactory; +use SMW\SemanticData; +use SMW\PropertyAnnotators\NullPropertyAnnotator; +use SMW\PropertyAnnotators\TranslationPropertyAnnotator; +use SMW\Tests\TestEnvironment; + +/** + * @covers \SMW\PropertyAnnotators\TranslationPropertyAnnotator + * @group semantic-mediawiki + * + * @license GNU GPL v2+ + * @since 3.0 + * + * @author mwjames + */ +class TranslationPropertyAnnotatorTest extends \PHPUnit_Framework_TestCase { + + private $semanticDataValidator; + private $dataItemFactory; + + protected function setUp() { + parent::setUp(); + + $this->semanticDataValidator = TestEnvironment::newValidatorFactory()->newSemanticDataValidator(); + $this->dataItemFactory = new DataItemFactory(); + } + + public function testCanConstruct() { + + $semanticData = $this->getMockBuilder( '\SMW\SemanticData' ) + ->disableOriginalConstructor() + ->getMock(); + + $instance = new TranslationPropertyAnnotator( + new NullPropertyAnnotator( $semanticData ), + [] + ); + + $this->assertInstanceOf( + TranslationPropertyAnnotator::class, + $instance + ); + } + + public function testAddAnnotation() { + + $semanticData = new SemanticData( + $this->dataItemFactory->newDIWikiPage( 'Foo' ) + ); + + $title = $this->getMockBuilder( '\Title' ) + ->disableOriginalConstructor() + ->getMock(); + + $title->expects( $this->once() ) + ->method( 'getDBKey' ) + ->will( $this->returnValue( 'Foobar' ) ); + + $title->expects( $this->once() ) + ->method( 'getNamespace' ) + ->will( $this->returnValue( NS_MAIN ) ); + + $translation = [ + 'languagecode' => 'foo', + 'sourcepagetitle' => $title, + 'messagegroupid' => 'bar' + ]; + + $expected = [ + 'propertyCount' => 3, + 'propertyKeys' => [ '_LCODE', '_TRANS_GROUP', '_TRANS_SOURCE' ], + 'propertyValues' => [ 'foo', 'bar', ':Foobar' ], + ]; + + $instance = new TranslationPropertyAnnotator( + new NullPropertyAnnotator( $semanticData ), + $translation + ); + + $instance->setPredefinedPropertyList( [ '_TRANS' ] ); + + $instance->addAnnotation(); + + $this->semanticDataValidator->assertThatPropertiesAreSet( + [ + 'propertyCount' => 1, + 'propertyKeys' => '_TRANS' + ], + $instance->getSemanticData() + ); + + $this->semanticDataValidator->assertThatPropertiesAreSet( + $expected, + $instance->getSemanticData()->findSubSemanticData( 'trans.foo' ) + ); + } + + public function testAddAnnotation_NotListed() { + + $semanticData = new SemanticData( + $this->dataItemFactory->newDIWikiPage( 'Foo' ) + ); + + $title = $this->getMockBuilder( '\Title' ) + ->disableOriginalConstructor() + ->getMock(); + + $title->expects( $this->never() ) + ->method( 'getDBKey' ) + ->will( $this->returnValue( 'Foobar' ) ); + + $title->expects( $this->never() ) + ->method( 'getNamespace' ) + ->will( $this->returnValue( NS_MAIN ) ); + + $translation = [ + 'languagecode' => 'foo', + 'sourcepagetitle' => $title, + 'messagegroupid' => 'bar' + ]; + + $instance = new TranslationPropertyAnnotator( + new NullPropertyAnnotator( $semanticData ), + $translation + ); + + $instance->setPredefinedPropertyList( [] ); + $instance->addAnnotation(); + } + + public function testAddAnnotation_EmptyData() { + + $semanticData = new SemanticData( + $this->dataItemFactory->newDIWikiPage( 'Foo' ) + ); + + $title = $this->getMockBuilder( '\Title' ) + ->disableOriginalConstructor() + ->getMock(); + + $translation = []; + + $instance = new TranslationPropertyAnnotator( + new NullPropertyAnnotator( $semanticData ), + $translation + ); + + $instance->addAnnotation(); + + $this->assertEquals( + $semanticData, + $instance->getSemanticData() + ); + } + +} |