diff --git a/core/modules/rdf/lib/Drupal/rdf/Tests/TextFieldRdfaTest.php b/core/modules/rdf/lib/Drupal/rdf/Tests/TextFieldRdfaTest.php index bcf2f20..79f44e6 100644 --- a/core/modules/rdf/lib/Drupal/rdf/Tests/TextFieldRdfaTest.php +++ b/core/modules/rdf/lib/Drupal/rdf/Tests/TextFieldRdfaTest.php @@ -1,53 +1,56 @@ 'Field formatter - text', 'description' => 'Tests RDFa output by text field formatters.', - 'group' => 'RDF' + 'group' => 'RDF', ); } public function setUp() { parent::setUp(); - // Create a field for testing. - entity_create('field_entity', array( - 'field_name' => $this->fieldName, - 'type' => 'text', - ))->save(); - entity_create('field_instance', array( - 'entity_type' => 'entity_test', - 'field_name' => $this->fieldName, - 'bundle' => 'entity_test', - ))->save(); + $this->createTestField(); // Add the mapping. $mapping = rdf_get_mapping('entity_test', 'entity_test'); @@ -55,10 +58,7 @@ public function setUp() { 'properties' => array('schema:text'), ))->save(); - // Set up test values. - $this->uri = 'http://ex.com'; - $this->testValue = 'test_text_value'; - $this->testSummary = 'test_summary_value'; + // Set up test entity. $this->entity = entity_create('entity_test', array()); $this->entity->{$this->fieldName}->value = $this->testValue; $this->entity->{$this->fieldName}->summary = $this->testSummary; @@ -68,14 +68,14 @@ public function setUp() { * Tests the default formatter. */ public function testDefaultFormatter() { - $this->_testFormatter('text_default', 'http://schema.org/text', $this->testValue); + $this->assertFormatterRdfa('text_default', 'http://schema.org/text', $this->testValue); } /** * Tests the plain formatter. */ public function testPlainFormatter() { - $this->_testFormatter('text_plain', 'http://schema.org/text', $this->testValue); + $this->assertFormatterRdfa('text_plain', 'http://schema.org/text', $this->testValue); } /** @@ -84,7 +84,7 @@ public function testPlainFormatter() { * @todo Check for the summary mapping. */ public function testSummaryFormatter() { - $this->_testFormatter('text_summary_or_trimmed', 'http://schema.org/text', $this->testValue); + $this->assertFormatterRdfa('text_summary_or_trimmed', 'http://schema.org/text', $this->testValue); } /** @@ -93,26 +93,6 @@ public function testSummaryFormatter() { * @todo Check for the summary mapping. */ public function testTrimmedFormatter() { - $this->_testFormatter('text_trimmed', 'http://schema.org/text', $this->testValue); - } - - /** - * Helper function to test the formatter. - * - * @param $formatter - * The machine name of the formatter to test. - * @param $property - * The property that should be found. - */ - protected function _testFormatter($formatter, $property, $value) { - $build = field_view_field($this->entity, $this->fieldName, array('type' => $formatter)); - $rendered = "
" . drupal_render($build) . '
'; - $graph = new \EasyRdf_Graph($this->uri, $rendered, 'rdfa'); - - $expected_value = array( - 'type' => 'literal', - 'value' => $value, - ); - $this->assertTrue($graph->hasProperty($this->uri, $property, $expected_value), "Formatter $formatter exposes data correctly."); + $this->assertFormatterRdfa('text_trimmed', 'http://schema.org/text', $this->testValue); } }