You are here

public function RdfExampleRdfaMarkupTestCase::testAttributesInMarkup in Examples for Developers 7

Test whether RDF mapping is define in markup.

Create a recipe node and test whether the RDF mapping defined for this bundle is reflected in the markup.

File

rdf_example/rdf_example.test, line 39
Tests for rdf.module.

Class

RdfExampleRdfaMarkupTestCase
Test RDFa markup generation.

Code

public function testAttributesInMarkup() {
  $node = $this
    ->drupalCreateNode(array(
    'type' => 'recipe',
  ));
  $this
    ->drupalGet('node/' . $node->nid);
  $iso_date = date('c', $node->changed);
  $url = url('node/' . $node->nid);

  // The title is mapped to dc:title and v:name and is exposed in a meta tag
  // in the header.
  $recipe_title = $this
    ->xpath("//span[contains(@property, 'dc:title') and contains(@property, 'v:name') and @content='{$node->title}']");
  $this
    ->assertTrue(!empty($recipe_title), 'Title is exposed with dc:title and v:name in meta element.');

  // Test that the type is applied and that the default mapping for date is
  // used.
  $recipe_meta = $this
    ->xpath("//div[(@about='{$url}') and (@typeof='v:Recipe')]//span[contains(@property, 'dc:date') and contains(@property, 'dc:created') and @datatype='xsd:dateTime' and @content='{$iso_date}']");
  $this
    ->assertTrue(!empty($recipe_meta), 'RDF type is present on post. Properties dc:date and dc:created are present on post date.');
}