metatag.output_caching.test 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. /**
  3. * @file
  4. * Tests for the Metatag module's output caching.
  5. */
  6. /**
  7. * Tests for the Metatag module's output caching.
  8. */
  9. class MetatagCoreOutputCachingTest extends MetatagTestHelper {
  10. /**
  11. * {@inheritdoc}
  12. */
  13. public static function getInfo() {
  14. return array(
  15. 'name' => 'Metatag: output caching',
  16. 'description' => 'Test the output caching functionality in Metatag.',
  17. 'group' => 'Metatag',
  18. 'dependencies' => array('ctools', 'token'),
  19. );
  20. }
  21. /**
  22. * Test how user tokens are handled when cache is enabled.
  23. */
  24. public function testUserTokensCacheEnabled() {
  25. // Enable output caching.
  26. variable_set('metatag_cache_output', TRUE);
  27. // Create two user accounts.
  28. $account1 = $this->drupalCreateUser();
  29. $account2 = $this->drupalCreateUser();
  30. // Log in the first account.
  31. $this->drupalLogin($account1);
  32. // Load the test page.
  33. $this->drupalGet('account-test-page');
  34. $this->assertResponse(200);
  35. // Verify the page loaded correctly and has the correct title.
  36. $this->assertText('Test page for user tokens.');
  37. $this->assertText('Hello ' . $account1->name);
  38. $xpath = $this->xpath("//h1");
  39. $this->verbose($xpath);
  40. $this->assertEqual(trim((string) $xpath[0]), 'Hello ' . $account1->name);
  41. // Confirm the page title itself.
  42. $this->assertTitle('Hello ' . $account1->name . ' | Drupal');
  43. // Log out the user.
  44. $this->drupalLogout() .
  45. // Log in the second account.
  46. $this->drupalLogin($account2);
  47. // Load the test page.
  48. $this->drupalGet('account-test-page');
  49. $this->assertResponse(200);
  50. // Verify the page loaded correctly and now shows the second user account's
  51. // name on the page.
  52. $this->assertText('Test page for user tokens.');
  53. $this->assertText('Hello ' . $account2->name);
  54. $xpath = $this->xpath("//h1");
  55. $this->verbose($xpath);
  56. $this->assertEqual(trim((string) $xpath[0]), 'Hello ' . $account2->name);
  57. // Confirm the page title has not been updated, which is as designed.
  58. $this->assertTitle('Hello ' . $account1->name . ' | Drupal');
  59. $this->assertNoTitle('Hello ' . $account2->name . ' | Drupal');
  60. }
  61. /**
  62. * Test how user tokens are handled when cache is Disabled.
  63. */
  64. public function testUserTokensCacheDisabled() {
  65. // Disable output caching.
  66. variable_set('metatag_cache_output', FALSE);
  67. // Create two user accounts.
  68. $account1 = $this->drupalCreateUser();
  69. $account2 = $this->drupalCreateUser();
  70. // Log in the first account.
  71. $this->drupalLogin($account1);
  72. // Load the test page.
  73. $this->drupalGet('account-test-page');
  74. $this->assertResponse(200);
  75. // Verify the page loaded correctly and has the correct title.
  76. $this->assertText('Test page for user tokens.');
  77. $this->assertText('Hello ' . $account1->name);
  78. $xpath = $this->xpath("//h1");
  79. $this->verbose($xpath);
  80. $this->assertEqual(trim((string) $xpath[0]), 'Hello ' . $account1->name);
  81. // Confirm the page title itself.
  82. $this->assertTitle('Hello ' . $account1->name . ' | Drupal');
  83. // Log out the user.
  84. $this->drupalLogout();
  85. // Log in the second account.
  86. $this->drupalLogin($account2);
  87. // Load the test page.
  88. $this->drupalGet('account-test-page');
  89. $this->assertResponse(200);
  90. // Verify the page loaded correctly and now shows the second user account's
  91. // name on the page.
  92. $this->assertText('Test page for user tokens.');
  93. $this->assertText('Hello ' . $account2->name);
  94. $xpath = $this->xpath("//h1");
  95. $this->verbose($xpath);
  96. $this->assertEqual(trim((string) $xpath[0]), 'Hello ' . $account2->name);
  97. // Confirm the page title has changed, i.e. it shows the second account name
  98. // rather than the first.
  99. $this->assertNoTitle('Hello ' . $account1->name . ' | Drupal');
  100. $this->assertTitle('Hello ' . $account2->name . ' | Drupal');
  101. }
  102. }