metatag.core_tag_removal.test 2.4 KB

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