metatag_context.test 3.3 KB

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