metatag_context.test 3.2 KB

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