summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/PropertyAnnotators/SchemaPropertyAnnotatorTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/PropertyAnnotators/SchemaPropertyAnnotatorTest.php')
-rw-r--r--www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/PropertyAnnotators/SchemaPropertyAnnotatorTest.php81
1 files changed, 81 insertions, 0 deletions
diff --git a/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/PropertyAnnotators/SchemaPropertyAnnotatorTest.php b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/PropertyAnnotators/SchemaPropertyAnnotatorTest.php
new file mode 100644
index 00000000..d2b23d1c
--- /dev/null
+++ b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/PropertyAnnotators/SchemaPropertyAnnotatorTest.php
@@ -0,0 +1,81 @@
+<?php
+
+namespace SMW\Tests\PropertyAnnotators;
+
+use SMW\DataItemFactory;
+use SMW\PropertyAnnotators\NullPropertyAnnotator;
+use SMW\PropertyAnnotators\SchemaPropertyAnnotator;
+use SMW\Schema\SchemaDefinition;
+use SMW\Tests\TestEnvironment;
+
+/**
+ * @covers \SMW\PropertyAnnotators\SchemaPropertyAnnotator
+ * @group semantic-mediawiki
+ *
+ * @license GNU GPL v2+
+ * @since 3.0
+ *
+ * @author mwjames
+ */
+class SchemaPropertyAnnotatorTest extends \PHPUnit_Framework_TestCase {
+
+ private $semanticDataFactory;
+ private $semanticDataValidator;
+ private $dataItemFactory;
+
+ protected function setUp() {
+ parent::setUp();
+
+ $testEnvironment = new TestEnvironment();
+ $this->semanticDataFactory = $testEnvironment->getUtilityFactory()->newSemanticDataFactory();
+ $this->semanticDataValidator = $testEnvironment->newValidatorFactory()->newSemanticDataValidator();
+ $this->dataItemFactory = new DataItemFactory();
+ }
+
+ public function testCanConstruct() {
+
+ $semanticData = $this->getMockBuilder( '\SMW\SemanticData' )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $instance = new SchemaPropertyAnnotator(
+ new NullPropertyAnnotator( $semanticData ),
+ new SchemaDefinition( 'foo', [] )
+ );
+
+ $this->assertInstanceOf(
+ SchemaPropertyAnnotator::class,
+ $instance
+ );
+ }
+
+ public function testAddAnnotation() {
+
+ $def = [
+ SchemaDefinition::SCHEMA_TYPE => 'bar',
+ SchemaDefinition::SCHEMA_DESCRIPTION => '...',
+ SchemaDefinition::SCHEMA_TAG => [ 'foobar' ],
+ ];
+
+ $semanticData = $this->semanticDataFactory->newEmptySemanticData( __METHOD__ );
+
+ $instance = new SchemaPropertyAnnotator(
+ new NullPropertyAnnotator( $semanticData ),
+ new SchemaDefinition( 'foo', $def )
+ );
+
+ $instance->addAnnotation();
+
+ $expected = [
+ 'propertyCount' => 4,
+ 'propertyKeys' => [ '_SCHEMA_TYPE', '_SCHEMA_DEF', '_SCHEMA_DESC', '_SCHEMA_TAG' ],
+ 'propertyValues' => [ 'bar', '...', 'foobar', '{"type":"bar","description":"...","tags":["foobar"]}' ],
+ ];
+
+ $this->semanticDataValidator->assertThatPropertiesAreSet(
+ $expected,
+ $instance->getSemanticData()
+ );
+ }
+
+}