summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/PropertyAnnotators/SortKeyPropertyAnnotatorTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/PropertyAnnotators/SortKeyPropertyAnnotatorTest.php')
-rw-r--r--www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/PropertyAnnotators/SortKeyPropertyAnnotatorTest.php131
1 files changed, 131 insertions, 0 deletions
diff --git a/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/PropertyAnnotators/SortKeyPropertyAnnotatorTest.php b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/PropertyAnnotators/SortKeyPropertyAnnotatorTest.php
new file mode 100644
index 00000000..abc4095e
--- /dev/null
+++ b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/PropertyAnnotators/SortKeyPropertyAnnotatorTest.php
@@ -0,0 +1,131 @@
+<?php
+
+namespace SMW\Tests\PropertyAnnotators;
+
+use SMW\DataItemFactory;
+use SMW\PropertyAnnotators\NullPropertyAnnotator;
+use SMW\PropertyAnnotators\SortKeyPropertyAnnotator;
+use SMW\Tests\Utils\UtilityFactory;
+
+/**
+ * @covers \SMW\PropertyAnnotators\SortKeyPropertyAnnotator
+ * @group semantic-mediawiki
+ *
+ * @license GNU GPL v2+
+ * @since 1.9
+ *
+ * @author mwjames
+ */
+class SortKeyPropertyAnnotatorTest extends \PHPUnit_Framework_TestCase {
+
+ private $semanticDataFactory;
+ private $semanticDataValidator;
+ private $dataItemFactory;
+
+ protected function setUp() {
+ parent::setUp();
+
+ $this->semanticDataFactory = UtilityFactory::getInstance()->newSemanticDataFactory();
+ $this->semanticDataValidator = UtilityFactory::getInstance()->newValidatorFactory()->newSemanticDataValidator();
+ $this->dataItemFactory = new DataItemFactory();
+ }
+
+ public function testCanConstruct() {
+
+ $semanticData = $this->getMockBuilder( '\SMW\SemanticData' )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $instance = new SortKeyPropertyAnnotator(
+ new NullPropertyAnnotator( $semanticData ),
+ 'Foo'
+ );
+
+ $this->assertInstanceOf(
+ '\SMW\PropertyAnnotators\SortKeyPropertyAnnotator',
+ $instance
+ );
+ }
+
+ /**
+ * @dataProvider defaultSortDataProvider
+ */
+ public function testAddAnnotation( array $parameters, array $expected ) {
+
+ $semanticData = $this->semanticDataFactory->setTitle( $parameters['title'] )->newEmptySemanticData();
+
+ $instance = new SortKeyPropertyAnnotator(
+ new NullPropertyAnnotator( $semanticData ),
+ $parameters['sort']
+ );
+
+ $instance->addAnnotation();
+
+ $this->semanticDataValidator->assertThatPropertiesAreSet(
+ $expected,
+ $instance->getSemanticData()
+ );
+ }
+
+ public function testDontOverrideAnnotationIfAlreadyAvailable() {
+
+ $semanticData = $this->semanticDataFactory->newEmptySemanticData( __METHOD__ );
+
+ $semanticData->addPropertyObjectValue(
+ $this->dataItemFactory->newDIProperty( '_SKEY' ),
+ $this->dataItemFactory->newDIBlob( 'FOO' )
+ );
+
+ $instance = new SortKeyPropertyAnnotator(
+ new NullPropertyAnnotator( $semanticData ),
+ 'bar'
+ );
+
+ $instance->addAnnotation();
+
+ $expected = [
+ 'propertyCount' => 1,
+ 'propertyKeys' => '_SKEY',
+ 'propertyValues' => [ 'FOO' ],
+ ];
+
+ $this->semanticDataValidator->assertThatPropertiesAreSet(
+ $expected,
+ $instance->getSemanticData()
+ );
+ }
+
+ public function defaultSortDataProvider() {
+
+ $provider = [];
+
+ // Sort entry
+ $provider[] = [
+ [
+ 'title' => 'Foo',
+ 'sort' => 'Lala'
+ ],
+ [
+ 'propertyCount' => 1,
+ 'propertyKeys' => '_SKEY',
+ 'propertyValues' => [ 'Lala' ],
+ ]
+ ];
+
+ // Empty
+ $provider[] = [
+ [
+ 'title' => 'Bar',
+ 'sort' => ''
+ ],
+ [
+ 'propertyCount' => 1,
+ 'propertyKeys' => '_SKEY',
+ 'propertyValues' => [ 'Bar' ],
+ ]
+ ];
+
+ return $provider;
+ }
+
+}