Commit afd8aee5 authored by catch's avatar catch

Issue #2203065 by lokapujya, cwells: Adjust assertFormatterRdfa() parameters...

Issue #2203065 by lokapujya, cwells: Adjust assertFormatterRdfa() parameters to allow for more advanced testing.
parent 16fb258c
...@@ -58,6 +58,6 @@ public function setUp() { ...@@ -58,6 +58,6 @@ public function setUp() {
* Tests the default formatter. * Tests the default formatter.
*/ */
public function testDefaultFormatter() { public function testDefaultFormatter() {
$this->assertFormatterRdfa('datetime_default', 'http://schema.org/dateCreated', $this->testValue . 'Z', 'literal', 'http://www.w3.org/2001/XMLSchema#dateTime'); $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'));
} }
} }
...@@ -53,8 +53,8 @@ public function setUp() { ...@@ -53,8 +53,8 @@ public function setUp() {
*/ */
public function testAllFormatters() { public function testAllFormatters() {
// Test the plain formatter. // Test the plain formatter.
$this->assertFormatterRdfa('string', 'http://schema.org/email', $this->testValue); $this->assertFormatterRdfa(array('type'=>'string'), 'http://schema.org/email', array('value' => $this->testValue));
// Test the mailto formatter. // Test the mailto formatter.
$this->assertFormatterRdfa('email_mailto', 'http://schema.org/email', $this->testValue); $this->assertFormatterRdfa(array('type'=>'email_mailto'), 'http://schema.org/email', array('value' => $this->testValue));
} }
} }
...@@ -57,7 +57,7 @@ public function setUp() { ...@@ -57,7 +57,7 @@ public function setUp() {
*/ */
public function testDefaultFormatter() { public function testDefaultFormatter() {
// Expected value is the output of the datatype callback, not the raw value. // Expected value is the output of the datatype callback, not the raw value.
$this->assertFormatterRdfa('text_default', 'http://schema.org/interactionCount', 'foo' . $this->test_value); $this->assertFormatterRdfa(array('type'=>'text_default'), 'http://schema.org/interactionCount', array('value' => 'foo' . $this->test_value));
} }
} }
......
...@@ -58,34 +58,33 @@ public function setUp() { ...@@ -58,34 +58,33 @@ public function setUp() {
/** /**
* Helper function to test the formatter's RDFa. * Helper function to test the formatter's RDFa.
* *
* @param string $formatter * @param array $formatter
* The machine name of the formatter to test. * 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 * @param string $property
* The property that should be found. * The property that should be found.
* @param string $value * @param array $expected_rdf_value
* The expected value of the property. * An associative array describing the expected value of the property
* @param string $object_type * containing:
* The object's type, either 'uri' or 'literal'. * - value: The actual value of the string or URI.
* @param string $datatype * - type: The type of RDF value, e.g. 'literal' for a string, or 'uri'.
* The data type of the property. * Defaults to 'literal'.
* - datatype: (optional) The datatype of the value (e.g. xsd:dateTime).
*/ */
protected function assertFormatterRdfa($formatter, $property, $value, $object_type = 'literal', $datatype = '') { 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 // The field formatter will be rendered inside the entity. Set the field
// formatter in the entity display options before rendering the entity. // formatter in the entity display options before rendering the entity.
entity_get_display('entity_test', 'entity_test', 'default') entity_get_display('entity_test', 'entity_test', 'default')
->setComponent($this->fieldName, array('type' => $formatter)) ->setComponent($this->fieldName, $formatter)
->save(); ->save();
$build = entity_view($this->entity, 'default'); $build = entity_view($this->entity, 'default');
$output = drupal_render($build); $output = drupal_render($build);
$graph = new \EasyRdf_Graph($this->uri, $output, 'rdfa'); $graph = new \EasyRdf_Graph($this->uri, $output, 'rdfa');
$expected_value = array( $this->assertTrue($graph->hasProperty($this->uri, $property, $expected_rdf_value), "Formatter {$formatter['type']} exposes data correctly for {$this->fieldType} fields.");
'type' => $object_type,
'value' => $value,
);
if ($datatype) {
$expected_value['datatype'] = $datatype;
}
$this->assertTrue($graph->hasProperty($this->uri, $property, $expected_value), "Formatter $formatter exposes data correctly for {$this->fieldType} fields.");
} }
/** /**
......
...@@ -103,7 +103,7 @@ public function setUp() { ...@@ -103,7 +103,7 @@ public function setUp() {
* Tests the plain formatter. * Tests the plain formatter.
*/ */
public function testPlainFormatter() { public function testPlainFormatter() {
$this->assertFormatterRdfa('taxonomy_term_reference_plain', 'http://schema.org/about', $this->term->getName(), 'literal'); $this->assertFormatterRdfa(array('type' => 'taxonomy_term_reference_plain'), 'http://schema.org/about', array('value' => $this->term->getName(), 'type' => 'literal'));
} }
/** /**
...@@ -111,7 +111,7 @@ public function testPlainFormatter() { ...@@ -111,7 +111,7 @@ public function testPlainFormatter() {
*/ */
public function testLinkFormatter() { public function testLinkFormatter() {
$term_uri = $this->getAbsoluteUri($this->term); $term_uri = $this->getAbsoluteUri($this->term);
$this->assertFormatterRdfa('taxonomy_term_reference_link', 'http://schema.org/about', $term_uri, 'uri'); $this->assertFormatterRdfa(array('type'=>'taxonomy_term_reference_link'), 'http://schema.org/about', array('value' => $term_uri, 'type' => 'uri'));
} }
} }
...@@ -66,14 +66,14 @@ public function setUp() { ...@@ -66,14 +66,14 @@ public function setUp() {
* Tests the default formatter. * Tests the default formatter.
*/ */
public function testDefaultFormatter() { public function testDefaultFormatter() {
$this->assertFormatterRdfa('text_default', 'http://schema.org/text', $this->testValue); $this->assertFormatterRdfa(array('type'=>'text_default'), 'http://schema.org/text', array('value' => $this->testValue));
} }
/** /**
* Tests the plain formatter. * Tests the plain formatter.
*/ */
public function testPlainFormatter() { public function testPlainFormatter() {
$this->assertFormatterRdfa('string', 'http://schema.org/text', $this->testValue); $this->assertFormatterRdfa(array('type'=>'string'), 'http://schema.org/text', array('value' => $this->testValue));
} }
/** /**
...@@ -82,7 +82,7 @@ public function testPlainFormatter() { ...@@ -82,7 +82,7 @@ public function testPlainFormatter() {
* @todo Check for the summary mapping. * @todo Check for the summary mapping.
*/ */
public function testSummaryFormatter() { public function testSummaryFormatter() {
$this->assertFormatterRdfa('text_summary_or_trimmed', 'http://schema.org/text', $this->testValue); $this->assertFormatterRdfa(array('type'=>'text_summary_or_trimmed'), 'http://schema.org/text', array('value' => $this->testValue));
} }
/** /**
...@@ -91,6 +91,6 @@ public function testSummaryFormatter() { ...@@ -91,6 +91,6 @@ public function testSummaryFormatter() {
* @todo Check for the summary mapping. * @todo Check for the summary mapping.
*/ */
public function testTrimmedFormatter() { public function testTrimmedFormatter() {
$this->assertFormatterRdfa('text_trimmed', 'http://schema.org/text', $this->testValue); $this->assertFormatterRdfa(array('type'=>'text_trimmed'), 'http://schema.org/text', array('value' => $this->testValue));
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment