summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/PropertyAnnotators/ChainablePropertyAnnotatorTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/PropertyAnnotators/ChainablePropertyAnnotatorTest.php')
-rw-r--r--www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/PropertyAnnotators/ChainablePropertyAnnotatorTest.php117
1 files changed, 117 insertions, 0 deletions
diff --git a/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/PropertyAnnotators/ChainablePropertyAnnotatorTest.php b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/PropertyAnnotators/ChainablePropertyAnnotatorTest.php
new file mode 100644
index 00000000..f5f3723d
--- /dev/null
+++ b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/PropertyAnnotators/ChainablePropertyAnnotatorTest.php
@@ -0,0 +1,117 @@
+<?php
+
+namespace SMW\Tests\PropertyAnnotators;
+
+use SMW\DIProperty;
+use SMW\PropertyAnnotators\CategoryPropertyAnnotator;
+use SMW\PropertyAnnotators\NullPropertyAnnotator;
+use SMW\PropertyAnnotators\PredefinedPropertyAnnotator;
+use SMW\PropertyAnnotators\SortKeyPropertyAnnotator;
+use SMW\Tests\Utils\UtilityFactory;
+
+/**
+ * @group semantic-mediawiki
+ *
+ * @license GNU GPL v2+
+ * @since 1.9
+ *
+ * @author mwjames
+ */
+class ChainablePropertyAnnotatorTest extends \PHPUnit_Framework_TestCase {
+
+ private $semanticDataFactory;
+ private $semanticDataValidator;
+
+ protected function setUp() {
+ parent::setUp();
+
+ $this->semanticDataFactory = UtilityFactory::getInstance()->newSemanticDataFactory();
+ $this->semanticDataValidator = UtilityFactory::getInstance()->newValidatorFactory()->newSemanticDataValidator();
+ }
+
+ /**
+ * @dataProvider annotationDataProvider
+ */
+ public function testChainableDecoratorAnnotation( array $parameters, array $expected ) {
+
+ $pageInfoProvider = $this->getMockBuilder( '\SMW\PageInfo' )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $pageInfoProvider->expects( $this->atLeastOnce() )
+ ->method( 'getModificationDate' )
+ ->will( $this->returnValue( $parameters['modificationDate'] ) );
+
+ $semanticData = $this->semanticDataFactory->newEmptySemanticData( __METHOD__ );
+
+ $categoryPropertyAnnotator = new CategoryPropertyAnnotator(
+ new NullPropertyAnnotator( $semanticData ),
+ $parameters['categories']
+ );
+
+ $categoryPropertyAnnotator->showHiddenCategories(
+ $parameters['settings']['showHiddenCategories']
+ );
+
+ $categoryPropertyAnnotator->useCategoryInstance(
+ $parameters['settings']['categoriesAsInstances']
+ );
+
+ $categoryPropertyAnnotator->useCategoryHierarchy(
+ $parameters['settings']['categoryHierarchy']
+ );
+
+ $categoryPropertyAnnotator->useCategoryRedirect(
+ false
+ );
+
+ $sortKeyPropertyAnnotator = new SortKeyPropertyAnnotator(
+ $categoryPropertyAnnotator,
+ $parameters['sortkey']
+ );
+
+ $predefinedPropertyAnnotator = new PredefinedPropertyAnnotator(
+ $sortKeyPropertyAnnotator,
+ $pageInfoProvider
+ );
+
+ $predefinedPropertyAnnotator->setPredefinedPropertyList(
+ $parameters['settings']['smwgPageSpecialProperties']
+ );
+
+ $predefinedPropertyAnnotator->addAnnotation();
+
+ $this->semanticDataValidator->assertThatPropertiesAreSet(
+ $expected,
+ $predefinedPropertyAnnotator->getSemanticData()
+ );
+ }
+
+ public function annotationDataProvider() {
+
+ $provider = [];
+
+ // #0
+ $provider[] = [
+ [
+ 'modificationDate' => 1272508903,
+ 'categories' => [ 'Foo', 'Bar' ],
+ 'sortkey' => 'Lala',
+ 'settings' => [
+ 'categoryHierarchy' => false,
+ 'categoriesAsInstances' => true,
+ 'showHiddenCategories' => true,
+ 'smwgPageSpecialProperties' => [ DIProperty::TYPE_MODIFICATION_DATE ]
+ ]
+ ],
+ [
+ 'propertyCount' => 3,
+ 'propertyKeys' => [ '_INST', '_MDAT', '_SKEY' ],
+ 'propertyValues' => [ 'Foo', 'Bar', '2010-04-29T02:41:43', 'Lala' ],
+ ]
+ ];
+
+ return $provider;
+ }
+
+}