metatag.core_tag_removal.test 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * Tests for the Metatag module to ensure removal of core tags works correctly.
  4. */
  5. class MetatagCoreTagRemovalTest extends MetatagTestHelper {
  6. /**
  7. * {@inheritdoc}
  8. */
  9. public static function getInfo() {
  10. return array(
  11. 'name' => 'Metatag core tag handling',
  12. 'description' => 'Test Metatag integration with the locale module.',
  13. 'group' => 'Metatag',
  14. 'dependencies' => array('ctools', 'token'),
  15. );
  16. }
  17. /**
  18. * Test that the core meta tags work correctly.
  19. */
  20. function testCoreTagRemoval() {
  21. // The default generator string that both Metatag and Drupal core use.
  22. $generator_default = 'Drupal 7 (http://drupal.org)';
  23. // Load the front page.
  24. $this->drupalGet('<front>');
  25. $this->assertResponse(200);
  26. // Confirm that the Generator tag is the default.
  27. $xpath = $this->xpath("//meta[@name='generator']");
  28. $this->assertEqual(count($xpath), 1, 'Exactly one generator meta tag found.');
  29. $this->assertEqual($xpath[0]['content'], $generator_default);
  30. // Update the global config to remove the 'generator' value.
  31. $config = metatag_config_load('global');
  32. unset($config->config['generator']);
  33. metatag_config_save($config);
  34. // Dump out the current config, to aid with debugging.
  35. $this->verbose($config);
  36. // Load the front page.
  37. $this->drupalGet('<front>');
  38. $this->assertResponse(200);
  39. // Confirm that the Generator tag no longer exists.
  40. $xpath = $this->xpath("//meta[@name='generator']");
  41. $this->assertEqual(count($xpath), 0, 'No generator meta tag found.');
  42. // Tell Metatag to leave core's meta tags in place.
  43. variable_set('metatag_leave_core_tags', TRUE);
  44. // Clear the Metatag caches.
  45. metatag_flush_caches();
  46. // Clear the page caches.
  47. drupal_flush_all_caches();
  48. // Load the front page again.
  49. $this->drupalGet('<front>');
  50. $this->assertResponse(200);
  51. // Confirm that the Generator tag is the default again, i.e. core is
  52. // responsible for adding it. Also, core uses the meta tag name "Generator"
  53. // instead of 'generator' like Metatag uses.
  54. $xpath = $this->xpath("//meta[@name='Generator']");
  55. $this->assertEqual(count($xpath), 1, 'Exactly one generator meta tag found.');
  56. $this->assertEqual($xpath[0]['content'], $generator_default);
  57. }
  58. }