diff --git a/core/modules/rdf/src/Tests/Field/FieldRdfaTestBase.php b/core/modules/rdf/src/Tests/Field/FieldRdfaTestBase.php index 8e4b50e..c0bd8b9 100644 --- a/core/modules/rdf/src/Tests/Field/FieldRdfaTestBase.php +++ b/core/modules/rdf/src/Tests/Field/FieldRdfaTestBase.php @@ -91,6 +91,7 @@ protected function assertFormatterRdfa($formatter, $property, $expected_rdf_valu $build = entity_view($this->entity, 'default'); $output = drupal_render($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. @@ -132,4 +133,52 @@ protected function getAbsoluteUri($entity) { return $entity->url('canonical', array('absolute' => TRUE)); } + /** + * Parse 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('' . $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; + } + } + } diff --git a/core/modules/rdf/src/Tests/Field/NumberFieldRdfaTest.php b/core/modules/rdf/src/Tests/Field/NumberFieldRdfaTest.php index c9246d0..dbfcfaa 100644 --- a/core/modules/rdf/src/Tests/Field/NumberFieldRdfaTest.php +++ b/core/modules/rdf/src/Tests/Field/NumberFieldRdfaTest.php @@ -64,6 +64,12 @@ public function testFloatFormatter() { $this->createTestField(); $this->createTestEntity(); $this->assertFormatterRdfa(array('type' => $this->fieldType), 'http://schema.org/baseSalary', array('value' => $this->testValue)); + + // Test that the content attribute is not created. + $xpath = "/div[@class='field-name-field-test']/div[@class='field-item']"; // and @content + $args = array(); + $result = $this->xpathContent($this->getRawContent(), $xpath, $args); + debug($result); } /** @@ -141,7 +147,7 @@ public function testDecimalFormatterWithSettings() { } /** - * Create the RDF mapping for the field. + * Creates the RDF mapping for the field. */ protected function createTestEntity() { // Add the mapping.