metatag_context.test 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. /**
  3. * @file
  4. * Functional tests for the Metatag:Context module.
  5. */
  6. /**
  7. * This extends the basic Metatag test class to reduce code duplication.
  8. */
  9. class MetatagContextTest extends MetatagTestHelper {
  10. /**
  11. * {@inheritdoc}
  12. */
  13. public static function getInfo() {
  14. return array(
  15. 'name' => 'Metatag:Context tests',
  16. 'description' => 'Test basic Metatag:Context functionality.',
  17. 'group' => 'Metatag',
  18. );
  19. }
  20. /**
  21. * {@inheritdoc}
  22. */
  23. public function setUp(array $modules = array()) {
  24. $modules[] = 'context';
  25. $modules[] = 'metatag_context';
  26. // Enable the hidden submodule to manage some default configs.
  27. $modules[] = 'metatag_context_tests';
  28. parent::setUp($modules);
  29. // Create user.
  30. $perms = array(
  31. 'bypass node access',
  32. );
  33. $this->adminUser = $this->createAdminUser($perms);
  34. $this->drupalLogin($this->adminUser);
  35. // Create a content type, with underscores.
  36. $type_name = strtolower($this->randomName(8)) . '_test';
  37. $type = $this->createContentType($type_name, $type_name);
  38. $this->type = $type->type;
  39. // Store a valid URL name, with hyphens instead of underscores.
  40. $this->hyphen_type = str_replace('_', '-', $this->type);
  41. }
  42. /**
  43. * Test handling a node.
  44. */
  45. public function testNode() {
  46. // Create a node.
  47. $this->drupalPost('node/add/' . $this->hyphen_type, array('title' => $this->randomName(8)), t('Save'));
  48. $this->assertResponse(200);
  49. // Generate metatags and check content.
  50. $test_object = $this->createTestObject('node_metatags', 'node/1');
  51. $this->generateByPathConfig($test_object);
  52. $this->editByPathConfig($test_object);
  53. $this->checkByPathConfig($test_object);
  54. // Edit metatag and check content.
  55. $test_object->title = 'New title';
  56. $test_object->description = '';
  57. $this->editByPathConfig($test_object);
  58. $this->checkByPathConfig($test_object);
  59. }
  60. /**
  61. * Test handling the front page.
  62. */
  63. public function testFrontPage() {
  64. // Generate metatags and check content.
  65. $test_object = $this->createTestObject('frontpage_metatags', '<front>');
  66. $this->generateByPathConfig($test_object);
  67. $this->editByPathConfig($test_object);
  68. $this->checkByPathConfig($test_object);
  69. // Edit metatag and check content.
  70. $test_object->title = 'A different title';
  71. $test_object->description = '';
  72. $this->editByPathConfig($test_object);
  73. $this->checkByPathConfig($test_object);
  74. }
  75. /**
  76. * Test the Context integration.
  77. */
  78. public function testExportedPage() {
  79. $this->drupalGet('metatag-context-test');
  80. $this->assertResponse(200);
  81. // Test the page title.
  82. $this->assertTitle('Metatag:Context test page title tag');
  83. // Test the description meta tag.
  84. $xpath = $this->xpath("//meta[@name='description']");
  85. $this->assertEqual(count($xpath), 1, 'Exactly one description meta tag found.');
  86. $this->assertEqual($xpath[0]['content'], 'Metatag:Context test description tag.');
  87. // Test the keywords meta tag.
  88. $xpath = $this->xpath("//meta[@name='keywords']");
  89. $this->assertEqual(count($xpath), 1, 'Exactly one keywords meta tag found.');
  90. $this->assertEqual($xpath[0]['content'], 'Test, page, keywords');
  91. }
  92. }