Update to Drupal 8.1.0. For more information, see https://www.drupal.org/drupal-8.1.0-release-notes
This commit is contained in:
parent
b11a755ba8
commit
c0a0d5a94c
6920 changed files with 64395 additions and 57312 deletions
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\rdf\Kernel\Field;
|
||||
|
||||
use Drupal\entity_test\Entity\EntityTest;
|
||||
|
||||
/**
|
||||
* Tests RDFa output by datetime field formatters.
|
||||
*
|
||||
* @group rdf
|
||||
*/
|
||||
class DateTimeFieldRdfaTest extends FieldRdfaTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $fieldType = 'datetime';
|
||||
|
||||
/**
|
||||
* The 'value' property value for testing.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $testValue = '2014-01-28T06:01:01';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = array('datetime');
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->createTestField();
|
||||
|
||||
// Add the mapping.
|
||||
$mapping = rdf_get_mapping('entity_test', 'entity_test');
|
||||
$mapping->setFieldMapping($this->fieldName, array(
|
||||
'properties' => array('schema:dateCreated'),
|
||||
))->save();
|
||||
|
||||
// Set up test entity.
|
||||
$this->entity = EntityTest::create(array());
|
||||
$this->entity->{$this->fieldName}->value = $this->testValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the default formatter.
|
||||
*/
|
||||
public function testDefaultFormatter() {
|
||||
$this->assertFormatterRdfa(array('type'=>'datetime_default'), 'http://schema.org/dateCreated', array('value' => $this->testValue . 'Z', 'type' => 'literal', 'datatype' => 'http://www.w3.org/2001/XMLSchema#dateTime'));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\rdf\Kernel\Field;
|
||||
|
||||
use Drupal\entity_test\Entity\EntityTest;
|
||||
|
||||
/**
|
||||
* Tests RDFa output by email field formatters.
|
||||
*
|
||||
* @group rdf
|
||||
*/
|
||||
class EmailFieldRdfaTest extends FieldRdfaTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $fieldType = 'email';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = array('text');
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->createTestField();
|
||||
|
||||
// Add the mapping.
|
||||
$mapping = rdf_get_mapping('entity_test', 'entity_test');
|
||||
$mapping->setFieldMapping($this->fieldName, array(
|
||||
'properties' => array('schema:email'),
|
||||
))->save();
|
||||
|
||||
// Set up test values.
|
||||
$this->testValue = 'test@example.com';
|
||||
$this->entity = EntityTest::create(array());
|
||||
$this->entity->{$this->fieldName}->value = $this->testValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests all email formatters.
|
||||
*/
|
||||
public function testAllFormatters() {
|
||||
// Test the plain formatter.
|
||||
$this->assertFormatterRdfa(array('type'=>'string'), 'http://schema.org/email', array('value' => $this->testValue));
|
||||
// Test the mailto formatter.
|
||||
$this->assertFormatterRdfa(array('type'=>'email_mailto'), 'http://schema.org/email', array('value' => $this->testValue));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,95 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\rdf\Kernel\Field;
|
||||
|
||||
use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;
|
||||
use Drupal\user\Entity\Role;
|
||||
use Drupal\user\RoleInterface;
|
||||
|
||||
/**
|
||||
* Tests the RDFa output of the entity reference field formatter.
|
||||
*
|
||||
* @group rdf
|
||||
*/
|
||||
class EntityReferenceRdfaTest extends FieldRdfaTestBase {
|
||||
|
||||
use EntityReferenceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $fieldType = 'entity_reference';
|
||||
|
||||
/**
|
||||
* The entity type used in this test.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $entityType = 'entity_test';
|
||||
|
||||
/**
|
||||
* The bundle used in this test.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $bundle = 'entity_test';
|
||||
|
||||
/**
|
||||
* The term for testing.
|
||||
*
|
||||
* @var \Drupal\taxonomy\Entity\Term
|
||||
*/
|
||||
protected $targetEntity;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['text', 'filter'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->installEntitySchema('entity_test_rev');
|
||||
|
||||
// Give anonymous users permission to view test entities.
|
||||
$this->installConfig(array('user'));
|
||||
Role::load(RoleInterface::ANONYMOUS_ID)
|
||||
->grantPermission('view test entity')
|
||||
->save();
|
||||
|
||||
$this->createEntityReferenceField($this->entityType, $this->bundle, $this->fieldName, 'Field test', $this->entityType);
|
||||
|
||||
// Add the mapping.
|
||||
$mapping = rdf_get_mapping('entity_test', 'entity_test');
|
||||
$mapping->setFieldMapping($this->fieldName, array(
|
||||
'properties' => array('schema:knows'),
|
||||
))->save();
|
||||
|
||||
// Create the entity to be referenced.
|
||||
$this->targetEntity = $this->container->get('entity_type.manager')
|
||||
->getStorage($this->entityType)
|
||||
->create(array('name' => $this->randomMachineName()));
|
||||
$this->targetEntity->save();
|
||||
|
||||
// Create the entity that will have the entity reference field.
|
||||
$this->entity = $this->container->get('entity_type.manager')
|
||||
->getStorage($this->entityType)
|
||||
->create(array('name' => $this->randomMachineName()));
|
||||
$this->entity->save();
|
||||
$this->entity->{$this->fieldName}->entity = $this->targetEntity;
|
||||
$this->uri = $this->getAbsoluteUri($this->entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests all the entity reference formatters.
|
||||
*/
|
||||
public function testAllFormatters() {
|
||||
$entity_uri = $this->getAbsoluteUri($this->targetEntity);
|
||||
|
||||
// Tests the label formatter.
|
||||
$this->assertFormatterRdfa(array('type' => 'entity_reference_label'), 'http://schema.org/knows', array('value' => $entity_uri, 'type' => 'uri'));
|
||||
// Tests the entity formatter.
|
||||
$this->assertFormatterRdfa(array('type' => 'entity_reference_entity_view'), 'http://schema.org/knows', array('value' => $entity_uri, 'type' => 'uri'));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\rdf\Kernel\Field;
|
||||
|
||||
use Drupal\entity_test\Entity\EntityTest;
|
||||
|
||||
/**
|
||||
* Tests the RDFa output of a text field formatter with a datatype callback.
|
||||
*
|
||||
* @group rdf
|
||||
*/
|
||||
class FieldRdfaDatatypeCallbackTest extends FieldRdfaTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $fieldType = 'text';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = array('text', 'filter');
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->createTestField();
|
||||
|
||||
$this->installConfig(array('filter'));
|
||||
|
||||
// Add the mapping.
|
||||
$mapping = rdf_get_mapping('entity_test', 'entity_test');
|
||||
$mapping->setFieldMapping($this->fieldName, array(
|
||||
'properties' => array('schema:interactionCount'),
|
||||
'datatype_callback' => array(
|
||||
'callable' => 'Drupal\rdf\Tests\Field\TestDataConverter::convertFoo',
|
||||
),
|
||||
))->save();
|
||||
|
||||
// Set up test values.
|
||||
$this->testValue = $this->randomMachineName();
|
||||
$this->entity = EntityTest::create();
|
||||
$this->entity->{$this->fieldName}->value = $this->testValue;
|
||||
$this->entity->save();
|
||||
|
||||
$this->uri = $this->getAbsoluteUri($this->entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the default formatter.
|
||||
*/
|
||||
public function testDefaultFormatter() {
|
||||
// Expected value is the output of the datatype callback, not the raw value.
|
||||
$this->assertFormatterRdfa(array('type'=>'text_default'), 'http://schema.org/interactionCount', array('value' => 'foo' . $this->testValue));
|
||||
}
|
||||
|
||||
}
|
||||
|
189
core/modules/rdf/tests/src/Kernel/Field/FieldRdfaTestBase.php
Normal file
189
core/modules/rdf/tests/src/Kernel/Field/FieldRdfaTestBase.php
Normal file
|
@ -0,0 +1,189 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\rdf\Kernel\Field;
|
||||
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\Tests\field\Kernel\FieldKernelTestBase;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
|
||||
abstract class FieldRdfaTestBase extends FieldKernelTestBase {
|
||||
|
||||
/**
|
||||
* The machine name of the field type to test.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $fieldType;
|
||||
|
||||
/**
|
||||
* The name of the field to create for testing.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $fieldName = 'field_test';
|
||||
|
||||
/**
|
||||
* The URI to identify the entity.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $uri = 'http://ex.com';
|
||||
|
||||
/**
|
||||
* The entity to render for testing.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\ContentEntityBase
|
||||
*/
|
||||
protected $entity;
|
||||
|
||||
/**
|
||||
* TRUE if verbose debugging is enabled.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $debug = FALSE;
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('rdf');
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $testValue;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
\Drupal::service('router.builder')->rebuild();
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to test the formatter's RDFa.
|
||||
*
|
||||
* @param array $formatter
|
||||
* An associative array describing the formatter to test and its settings
|
||||
* containing:
|
||||
* - type: The machine name of the field formatter to test.
|
||||
* - settings: The settings of the field formatter to test.
|
||||
* @param string $property
|
||||
* The property that should be found.
|
||||
* @param array $expected_rdf_value
|
||||
* An associative array describing the expected value of the property
|
||||
* containing:
|
||||
* - value: The actual value of the string or URI.
|
||||
* - type: The type of RDF value, e.g. 'literal' for a string, or 'uri'.
|
||||
* Defaults to 'literal'.
|
||||
* - datatype: (optional) The datatype of the value (e.g. xsd:dateTime).
|
||||
*/
|
||||
protected function assertFormatterRdfa($formatter, $property, $expected_rdf_value) {
|
||||
$expected_rdf_value += array('type' => 'literal');
|
||||
|
||||
// The field formatter will be rendered inside the entity. Set the field
|
||||
// formatter in the entity display options before rendering the entity.
|
||||
entity_get_display('entity_test', 'entity_test', 'default')
|
||||
->setComponent($this->fieldName, $formatter)
|
||||
->save();
|
||||
$build = entity_view($this->entity, 'default');
|
||||
$output = \Drupal::service('renderer')->renderRoot($build);
|
||||
$graph = new \EasyRdf_Graph($this->uri, $output, 'rdfa');
|
||||
$this->setRawContent($output);
|
||||
|
||||
// If verbose debugging is turned on, display the HTML and parsed RDF
|
||||
// in the results.
|
||||
if ($this->debug) {
|
||||
print_r($output);
|
||||
print_r($graph->toRdfPhp());
|
||||
}
|
||||
|
||||
$this->assertTrue($graph->hasProperty($this->uri, $property, $expected_rdf_value), "Formatter {$formatter['type']} exposes data correctly for {$this->fieldType} fields.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the field for testing.
|
||||
*
|
||||
* @param array $field_settings
|
||||
* (optional) An array of field settings.
|
||||
*/
|
||||
protected function createTestField($field_settings = array()) {
|
||||
FieldStorageConfig::create(array(
|
||||
'field_name' => $this->fieldName,
|
||||
'entity_type' => 'entity_test',
|
||||
'type' => $this->fieldType,
|
||||
))->save();
|
||||
FieldConfig::create([
|
||||
'entity_type' => 'entity_test',
|
||||
'field_name' => $this->fieldName,
|
||||
'bundle' => 'entity_test',
|
||||
'settings' => $field_settings,
|
||||
])->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the absolute URI of an entity.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\ContentEntityBase $entity
|
||||
* The entity for which to generate the URI.
|
||||
*
|
||||
* @return string
|
||||
* The absolute URI.
|
||||
*/
|
||||
protected function getAbsoluteUri($entity) {
|
||||
return $entity->url('canonical', array('absolute' => TRUE));
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a content and return the html element.
|
||||
*
|
||||
* @param string $content
|
||||
* The html to parse.
|
||||
*
|
||||
* @return array
|
||||
* An array containing simplexml objects.
|
||||
*/
|
||||
protected function parseContent($content) {
|
||||
$htmlDom = new \DOMDocument();
|
||||
@$htmlDom->loadHTML('<?xml encoding="UTF-8">' . $content);
|
||||
$elements = simplexml_import_dom($htmlDom);
|
||||
|
||||
return $elements;
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs an xpath search on a certain content.
|
||||
*
|
||||
* The search is relative to the root element of the $content variable.
|
||||
*
|
||||
* @param string $content
|
||||
* The html to parse.
|
||||
* @param string $xpath
|
||||
* The xpath string to use in the search.
|
||||
* @param array $arguments
|
||||
* Some arguments for the xpath.
|
||||
*
|
||||
* @return array|FALSE
|
||||
* The return value of the xpath search. For details on the xpath string
|
||||
* format and return values see the SimpleXML documentation,
|
||||
* http://php.net/manual/function.simplexml-element-xpath.php.
|
||||
*/
|
||||
protected function xpathContent($content, $xpath, array $arguments = array()) {
|
||||
if ($elements = $this->parseContent($content)) {
|
||||
$xpath = $this->buildXPathQuery($xpath, $arguments);
|
||||
$result = $elements->xpath($xpath);
|
||||
// Some combinations of PHP / libxml versions return an empty array
|
||||
// instead of the documented FALSE. Forcefully convert any falsish values
|
||||
// to an empty array to allow foreach(...) constructions.
|
||||
return $result ? $result : array();
|
||||
}
|
||||
else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
184
core/modules/rdf/tests/src/Kernel/Field/LinkFieldRdfaTest.php
Normal file
184
core/modules/rdf/tests/src/Kernel/Field/LinkFieldRdfaTest.php
Normal file
|
@ -0,0 +1,184 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\rdf\Kernel\Field;
|
||||
|
||||
use Drupal\entity_test\Entity\EntityTest;
|
||||
|
||||
/**
|
||||
* Tests the placement of RDFa in link field formatters.
|
||||
*
|
||||
* @group rdf
|
||||
*/
|
||||
class LinkFieldRdfaTest extends FieldRdfaTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $fieldType = 'link';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = array('link', 'text');
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->createTestField();
|
||||
|
||||
// Add the mapping.
|
||||
$mapping = rdf_get_mapping('entity_test', 'entity_test');
|
||||
$mapping->setFieldMapping($this->fieldName, array(
|
||||
'properties' => array('schema:link'),
|
||||
))->save();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests all formatters with link to external page.
|
||||
*/
|
||||
public function testAllFormattersExternal() {
|
||||
// Set up test values.
|
||||
$this->testValue = 'http://test.me/foo/bar/neque/porro/quisquam/est/qui-dolorem?foo/bar/neque/porro/quisquam/est/qui-dolorem';
|
||||
$this->entity = EntityTest::create(array());
|
||||
$this->entity->{$this->fieldName}->uri = $this->testValue;
|
||||
|
||||
// Set up the expected result.
|
||||
$expected_rdf = array(
|
||||
'value' => $this->testValue,
|
||||
'type' => 'uri',
|
||||
);
|
||||
|
||||
$this->runTestAllFormatters($expected_rdf, 'external');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests all formatters with link to internal page.
|
||||
*/
|
||||
public function testAllFormattersInternal() {
|
||||
// Set up test values.
|
||||
$this->testValue = 'admin';
|
||||
$this->entity = EntityTest::create(array());
|
||||
$this->entity->{$this->fieldName}->uri = 'internal:/admin';
|
||||
|
||||
// Set up the expected result.
|
||||
// AssertFormatterRdfa looks for a full path.
|
||||
$expected_rdf = array(
|
||||
'value' => $this->uri . '/' . $this->testValue,
|
||||
'type' => 'uri',
|
||||
);
|
||||
|
||||
$this->runTestAllFormatters($expected_rdf, 'internal');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests all formatters with link to frontpage.
|
||||
*/
|
||||
public function testAllFormattersFront() {
|
||||
// Set up test values.
|
||||
$this->testValue = '/';
|
||||
$this->entity = EntityTest::create(array());
|
||||
$this->entity->{$this->fieldName}->uri = 'internal:/';
|
||||
|
||||
// Set up the expected result.
|
||||
$expected_rdf = array(
|
||||
'value' => $this->uri . '/',
|
||||
'type' => 'uri',
|
||||
);
|
||||
|
||||
$this->runTestAllFormatters($expected_rdf, 'front');
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to test all link formatters.
|
||||
*/
|
||||
public function runTestAllFormatters($expected_rdf, $type = NULL) {
|
||||
|
||||
// Test the link formatter: trim at 80, no other settings.
|
||||
$formatter = array(
|
||||
'type' => 'link',
|
||||
'settings' => array(
|
||||
'trim_length' => 80,
|
||||
'url_only' => FALSE,
|
||||
'url_plain' => FALSE,
|
||||
'rel' => '',
|
||||
'target' => '',
|
||||
),
|
||||
);
|
||||
$this->assertFormatterRdfa($formatter, 'http://schema.org/link', $expected_rdf);
|
||||
|
||||
// Test the link formatter: trim at 40, nofollow, new window.
|
||||
$formatter = array(
|
||||
'type' => 'link',
|
||||
'settings' => array(
|
||||
'trim_length' => 40,
|
||||
'url_only' => FALSE,
|
||||
'url_plain' => FALSE,
|
||||
'rel' => 'nofollow',
|
||||
'target' => '_blank',
|
||||
),
|
||||
);
|
||||
$this->assertFormatterRdfa($formatter, 'http://schema.org/link', $expected_rdf);
|
||||
|
||||
// Test the link formatter: trim at 40, URL only (not plaintext) nofollow,
|
||||
// new window.
|
||||
$formatter = array(
|
||||
'type' => 'link',
|
||||
'settings' => array(
|
||||
'trim_length' => 40,
|
||||
'url_only' => TRUE,
|
||||
'url_plain' => FALSE,
|
||||
'rel' => 'nofollow',
|
||||
'target' => '_blank',
|
||||
),
|
||||
);
|
||||
$this->assertFormatterRdfa($formatter, 'http://schema.org/link', $expected_rdf);
|
||||
|
||||
// Test the link_separate formatter: trim at 40, nofollow, new window.
|
||||
$formatter = array(
|
||||
'type' => 'link_separate',
|
||||
'settings' => array(
|
||||
'trim_length' => 40,
|
||||
'rel' => 'nofollow',
|
||||
'target' => '_blank',
|
||||
),
|
||||
);
|
||||
$this->assertFormatterRdfa($formatter, 'http://schema.org/link', $expected_rdf);
|
||||
|
||||
// Change the expected value here to literal. When formatted as plaintext
|
||||
// then the RDF is expecting a 'literal' not a 'uri'.
|
||||
$expected_rdf = array(
|
||||
'value' => $this->testValue,
|
||||
'type' => 'literal',
|
||||
);
|
||||
// Test the link formatter: trim at 20, url only (as plaintext.)
|
||||
$formatter = array(
|
||||
'type' => 'link',
|
||||
'settings' => array(
|
||||
'trim_length' => 20,
|
||||
'url_only' => TRUE,
|
||||
'url_plain' => TRUE,
|
||||
'rel' => '0',
|
||||
'target' => '0',
|
||||
),
|
||||
);
|
||||
$this->assertFormatterRdfa($formatter, 'http://schema.org/link', $expected_rdf);
|
||||
|
||||
// Test the link formatter: do not trim, url only (as plaintext.)
|
||||
$formatter = array(
|
||||
'type' => 'link',
|
||||
'settings' => array(
|
||||
'trim_length' => 0,
|
||||
'url_only' => TRUE,
|
||||
'url_plain' => TRUE,
|
||||
'rel' => '0',
|
||||
'target' => '0',
|
||||
),
|
||||
);
|
||||
$this->assertFormatterRdfa($formatter, 'http://schema.org/link', $expected_rdf);
|
||||
}
|
||||
|
||||
}
|
203
core/modules/rdf/tests/src/Kernel/Field/NumberFieldRdfaTest.php
Normal file
203
core/modules/rdf/tests/src/Kernel/Field/NumberFieldRdfaTest.php
Normal file
|
@ -0,0 +1,203 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\rdf\Kernel\Field;
|
||||
|
||||
use Drupal\entity_test\Entity\EntityTest;
|
||||
|
||||
/**
|
||||
* Tests RDFa output by number field formatters.
|
||||
*
|
||||
* @group rdf
|
||||
*/
|
||||
class NumberFieldRdfaTest extends FieldRdfaTestBase {
|
||||
|
||||
/**
|
||||
* Tests the integer formatter.
|
||||
*/
|
||||
public function testIntegerFormatter() {
|
||||
$this->fieldType = 'integer';
|
||||
$testValue = 3;
|
||||
$this->createTestField();
|
||||
$this->createTestEntity($testValue);
|
||||
$this->assertFormatterRdfa(array('type' => 'number_integer'), 'http://schema.org/baseSalary', array('value' => $testValue));
|
||||
|
||||
// Test that the content attribute is not created.
|
||||
$result = $this->xpathContent($this->getRawContent(), '//div[contains(@class, "field__items") and @content]');
|
||||
$this->assertFalse($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the integer formatter with settings.
|
||||
*/
|
||||
public function testIntegerFormatterWithSettings() {
|
||||
\Drupal::service('theme_handler')->install(['classy']);
|
||||
\Drupal::service('theme_handler')->setDefault('classy');
|
||||
$this->fieldType = 'integer';
|
||||
$formatter = array(
|
||||
'type' => 'number_integer',
|
||||
'settings' => array(
|
||||
'thousand_separator' => '.',
|
||||
'prefix_suffix' => TRUE,
|
||||
),
|
||||
);
|
||||
$testValue = 3333333.33;
|
||||
$field_settings = array(
|
||||
'prefix' => '#',
|
||||
'suffix' => ' llamas.',
|
||||
);
|
||||
$this->createTestField($field_settings);
|
||||
$this->createTestEntity($testValue);
|
||||
$this->assertFormatterRdfa($formatter, 'http://schema.org/baseSalary', array('value' => $testValue));
|
||||
|
||||
// Test that the content attribute is created.
|
||||
$result = $this->xpathContent($this->getRawContent(), '//div[contains(@class, "field__item") and @content=:testValue]', array(':testValue' => $testValue));
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the float formatter.
|
||||
*/
|
||||
public function testFloatFormatter() {
|
||||
$this->fieldType = 'float';
|
||||
$testValue = 3.33;
|
||||
$this->createTestField();
|
||||
$this->createTestEntity($testValue);
|
||||
$this->assertFormatterRdfa(array('type' => 'number_unformatted'), 'http://schema.org/baseSalary', array('value' => $testValue));
|
||||
|
||||
// Test that the content attribute is not created.
|
||||
$result = $this->xpathContent($this->getRawContent(), '//div[contains(@class, "field__items") and @content]');
|
||||
$this->assertFalse($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the float formatter with settings.
|
||||
*/
|
||||
public function testFloatFormatterWithSettings() {
|
||||
\Drupal::service('theme_handler')->install(['classy']);
|
||||
\Drupal::service('theme_handler')->setDefault('classy');
|
||||
$this->fieldType = 'float';
|
||||
$formatter = array(
|
||||
'type' => 'number_decimal',
|
||||
'settings' => array(
|
||||
'thousand_separator' => '.',
|
||||
'decimal_separator' => ',',
|
||||
'prefix_suffix' => TRUE,
|
||||
),
|
||||
);
|
||||
$testValue = 3333333.33;
|
||||
$field_settings = array(
|
||||
'prefix' => '$',
|
||||
'suffix' => ' more.',
|
||||
);
|
||||
$this->createTestField($field_settings);
|
||||
$this->createTestEntity($testValue);
|
||||
$this->assertFormatterRdfa($formatter, 'http://schema.org/baseSalary', array('value' => $testValue));
|
||||
|
||||
// Test that the content attribute is created.
|
||||
$result = $this->xpathContent($this->getRawContent(), '//div[contains(@class, "field__item") and @content=:testValue]', array(':testValue' => $testValue));
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the float formatter with a scale. Scale is not exercised.
|
||||
*/
|
||||
public function testFloatFormatterWithScale() {
|
||||
$this->fieldType = 'float';
|
||||
$formatter = array(
|
||||
'type' => 'number_decimal',
|
||||
'settings' => array(
|
||||
'scale' => 5,
|
||||
),
|
||||
);
|
||||
$testValue = 3.33;
|
||||
$this->createTestField();
|
||||
$this->createTestEntity($testValue);
|
||||
$this->assertFormatterRdfa($formatter, 'http://schema.org/baseSalary', array('value' => $testValue));
|
||||
|
||||
// Test that the content attribute is not created.
|
||||
$result = $this->xpathContent($this->getRawContent(), '//div[contains(@class, "field__items") and @content]');
|
||||
$this->assertFalse($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the float formatter with a scale. Scale is exercised.
|
||||
*/
|
||||
public function testFloatFormatterWithScaleExercised() {
|
||||
\Drupal::service('theme_handler')->install(['classy']);
|
||||
\Drupal::service('theme_handler')->setDefault('classy');
|
||||
$this->fieldType = 'float';
|
||||
$formatter = array(
|
||||
'type' => 'number_decimal',
|
||||
'settings' => array(
|
||||
'scale' => 5,
|
||||
),
|
||||
);
|
||||
$testValue = 3.1234567;
|
||||
$this->createTestField();
|
||||
$this->createTestEntity($testValue);
|
||||
$this->assertFormatterRdfa($formatter, 'http://schema.org/baseSalary', array('value' => $testValue));
|
||||
|
||||
// Test that the content attribute is created.
|
||||
$result = $this->xpathContent($this->getRawContent(), '//div[contains(@class, "field__item") and @content=:testValue]', array(':testValue' => $testValue));
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the decimal formatter.
|
||||
*/
|
||||
public function testDecimalFormatter() {
|
||||
$this->fieldType = 'decimal';
|
||||
$testValue = 3.33;
|
||||
$this->createTestField();
|
||||
$this->createTestEntity($testValue);
|
||||
$this->assertFormatterRdfa(array('type' => 'number_decimal'), 'http://schema.org/baseSalary', array('value' => $testValue));
|
||||
|
||||
// Test that the content attribute is not created.
|
||||
$result = $this->xpathContent($this->getRawContent(), '//div[contains(@class, "field__items") and @content]');
|
||||
$this->assertFalse($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the decimal formatter with settings.
|
||||
*/
|
||||
public function testDecimalFormatterWithSettings() {
|
||||
\Drupal::service('theme_handler')->install(['classy']);
|
||||
\Drupal::service('theme_handler')->setDefault('classy');
|
||||
$this->fieldType = 'decimal';
|
||||
$formatter = array(
|
||||
'type' => 'number_decimal',
|
||||
'settings' => array(
|
||||
'thousand_separator' => 't',
|
||||
'decimal_separator' => '#',
|
||||
'prefix_suffix' => TRUE,
|
||||
),
|
||||
);
|
||||
$testValue = 3333333.33;
|
||||
$field_settings = array(
|
||||
'prefix' => '$',
|
||||
'suffix' => ' more.',
|
||||
);
|
||||
$this->createTestField($field_settings);
|
||||
$this->createTestEntity($testValue);
|
||||
$this->assertFormatterRdfa($formatter, 'http://schema.org/baseSalary', array('value' => $testValue));
|
||||
|
||||
// Test that the content attribute is created.
|
||||
$result = $this->xpathContent($this->getRawContent(), '//div[contains(@class, "field__item") and @content=:testValue]', array(':testValue' => $testValue));
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the RDF mapping for the field.
|
||||
*/
|
||||
protected function createTestEntity($testValue) {
|
||||
// Add the mapping.
|
||||
$mapping = rdf_get_mapping('entity_test', 'entity_test');
|
||||
$mapping->setFieldMapping($this->fieldName, array(
|
||||
'properties' => array('schema:baseSalary'),
|
||||
))->save();
|
||||
|
||||
// Set up test entity.
|
||||
$this->entity = EntityTest::create(array());
|
||||
$this->entity->{$this->fieldName}->value = $testValue;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\rdf\Kernel\Field;
|
||||
|
||||
use Drupal\entity_test\Entity\EntityTest;
|
||||
|
||||
/**
|
||||
* Tests RDFa output by text field formatters.
|
||||
*
|
||||
* @group rdf
|
||||
*/
|
||||
class StringFieldRdfaTest extends FieldRdfaTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $fieldType = 'string';
|
||||
|
||||
/**
|
||||
* The 'value' property value for testing.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $testValue = 'test_text_value';
|
||||
|
||||
/**
|
||||
* The 'summary' property value for testing.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $testSummary = 'test_summary_value';
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->createTestField();
|
||||
|
||||
// Add the mapping.
|
||||
$mapping = rdf_get_mapping('entity_test', 'entity_test');
|
||||
$mapping->setFieldMapping($this->fieldName, array(
|
||||
'properties' => array('schema:text'),
|
||||
))->save();
|
||||
|
||||
// Set up test entity.
|
||||
$this->entity = EntityTest::create();
|
||||
$this->entity->{$this->fieldName}->value = $this->testValue;
|
||||
$this->entity->{$this->fieldName}->summary = $this->testSummary;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests string formatters.
|
||||
*/
|
||||
public function testStringFormatters() {
|
||||
// Tests the string formatter.
|
||||
$this->assertFormatterRdfa(array('type'=>'string'), 'http://schema.org/text', array('value' => $this->testValue));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\rdf\Kernel\Field;
|
||||
|
||||
use Drupal\entity_test\Entity\EntityTest;
|
||||
|
||||
/**
|
||||
* Tests RDFa output by telephone field formatters.
|
||||
*
|
||||
* @group rdf
|
||||
*/
|
||||
class TelephoneFieldRdfaTest extends FieldRdfaTestBase {
|
||||
|
||||
/**
|
||||
* A test value for the telephone field.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $testValue;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $fieldType = 'telephone';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = array('telephone', 'text');
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->createTestField();
|
||||
|
||||
// Add the mapping.
|
||||
$mapping = rdf_get_mapping('entity_test', 'entity_test');
|
||||
$mapping->setFieldMapping($this->fieldName, array(
|
||||
'properties' => array('schema:telephone'),
|
||||
))->save();
|
||||
|
||||
// Set up test values.
|
||||
$this->testValue = '555-555-5555';
|
||||
$this->entity = EntityTest::create(array());
|
||||
$this->entity->{$this->fieldName}->value = $this->testValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the field formatters.
|
||||
*/
|
||||
public function testAllFormatters() {
|
||||
// Tests the plain formatter.
|
||||
$this->assertFormatterRdfa(array('type' => 'string'), 'http://schema.org/telephone', array('value' => $this->testValue));
|
||||
// Tests the telephone link formatter.
|
||||
$this->assertFormatterRdfa(array('type' => 'telephone_link'), 'http://schema.org/telephone', array('value' => 'tel:' . $this->testValue, 'type' => 'uri'));
|
||||
|
||||
$formatter = array(
|
||||
'type' => 'telephone_link',
|
||||
'settings' => array('title' => 'Contact us'),
|
||||
);
|
||||
$expected_rdf_value = array(
|
||||
'value' => 'tel:' . $this->testValue,
|
||||
'type' => 'uri',
|
||||
);
|
||||
// Tests the telephone link formatter with custom title.
|
||||
$this->assertFormatterRdfa($formatter, 'http://schema.org/telephone', $expected_rdf_value);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\rdf\Kernel\Field;
|
||||
|
||||
use Drupal\entity_test\Entity\EntityTest;
|
||||
|
||||
/**
|
||||
* Tests RDFa output by text field formatters.
|
||||
*
|
||||
* @group rdf
|
||||
*/
|
||||
class TextFieldRdfaTest extends FieldRdfaTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $fieldType = 'text';
|
||||
|
||||
/**
|
||||
* The 'value' property value for testing.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $testValue = 'test_text_value';
|
||||
|
||||
/**
|
||||
* The 'summary' property value for testing.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $testSummary = 'test_summary_value';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = array('text', 'filter');
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->installConfig(array('filter'));
|
||||
|
||||
$this->createTestField();
|
||||
|
||||
// Add the mapping.
|
||||
$mapping = rdf_get_mapping('entity_test', 'entity_test');
|
||||
$mapping->setFieldMapping($this->fieldName, array(
|
||||
'properties' => array('schema:text'),
|
||||
))->save();
|
||||
|
||||
// Set up test entity.
|
||||
$this->entity = EntityTest::create();
|
||||
$this->entity->{$this->fieldName}->value = $this->testValue;
|
||||
$this->entity->{$this->fieldName}->summary = $this->testSummary;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests all formatters.
|
||||
*
|
||||
* @todo Check for the summary mapping.
|
||||
*/
|
||||
public function testAllFormatters() {
|
||||
$formatted_value = strip_tags($this->entity->{$this->fieldName}->processed);
|
||||
|
||||
// Tests the default formatter.
|
||||
$this->assertFormatterRdfa(array('type'=>'text_default'), 'http://schema.org/text', array('value' => $formatted_value));
|
||||
// Tests the summary formatter.
|
||||
$this->assertFormatterRdfa(array('type'=>'text_summary_or_trimmed'), 'http://schema.org/text', array('value' => $formatted_value));
|
||||
// Tests the trimmed formatter.
|
||||
$this->assertFormatterRdfa(array('type'=>'text_trimmed'), 'http://schema.org/text', array('value' => $formatted_value));
|
||||
}
|
||||
}
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\rdf\Unit\RdfMappingConfigEntityUnitTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\rdf\Unit;
|
||||
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
|
|
Reference in a new issue