rdf_example.test 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /**
  3. * @file
  4. * Tests for rdf.module.
  5. */
  6. /**
  7. * Test RDFa markup generation.
  8. *
  9. * @ingroup rdf_example
  10. */
  11. class RdfExampleRdfaMarkupTestCase extends DrupalWebTestCase {
  12. /**
  13. * {@inheritdoc}
  14. */
  15. public static function getInfo() {
  16. return array(
  17. 'name' => 'RDFa markup',
  18. 'description' => 'Test RDFa markup generation.',
  19. 'group' => 'Examples',
  20. );
  21. }
  22. /**
  23. * {@inheritdoc}
  24. */
  25. public function setUp() {
  26. parent::setUp('rdf', 'field_test', 'rdf_example');
  27. }
  28. /**
  29. * Test whether RDF mapping is define in markup.
  30. *
  31. * Create a recipe node and test whether the RDF mapping defined for this
  32. * bundle is reflected in the markup.
  33. */
  34. public function testAttributesInMarkup() {
  35. $node = $this->drupalCreateNode(array('type' => 'recipe'));
  36. $this->drupalGet('node/' . $node->nid);
  37. $iso_date = date('c', $node->changed);
  38. $url = url('node/' . $node->nid);
  39. // The title is mapped to dc:title and v:name and is exposed in a meta tag
  40. // in the header.
  41. $recipe_title = $this->xpath("//span[contains(@property, 'dc:title') and contains(@property, 'v:name') and @content='$node->title']");
  42. $this->assertTrue(!empty($recipe_title), 'Title is exposed with dc:title and v:name in meta element.');
  43. // Test that the type is applied and that the default mapping for date is
  44. // used.
  45. $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']");
  46. $this->assertTrue(!empty($recipe_meta), 'RDF type is present on post. Properties dc:date and dc:created are present on post date.');
  47. }
  48. }