metatag.output_caching.test 3.8 KB

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