toolbar.test 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. class ToolbarTestCase extends DrupalWebTestCase {
  3. protected $admin_user;
  4. public static function getInfo() {
  5. return array(
  6. 'name' => 'Toolbar',
  7. 'description' => 'Test toolbar functionality.',
  8. 'group' => 'Toolbar (core)',
  9. );
  10. }
  11. function setUp() {
  12. parent::setUp();
  13. // Setup users.
  14. $this->admin_user = $this->drupalCreateUser(array('access toolbar'));
  15. $this->drupalLogin($this->admin_user);
  16. }
  17. /**
  18. * Tests toggling the toolbar collapsed cookie.
  19. */
  20. function testToolbarCollapsedCookie() {
  21. $this->drupalGet('toolbar/toggle');
  22. $set_cookie = $this->drupalGetHeader('set-cookie', TRUE);
  23. $this->assertTrue((strpos('Drupal.toolbar.collapsed=1; path=' . base_path() . '; SameSite=Lax', $set_cookie) !== FALSE), 'Toolbar cookie set to collapsed by default.');
  24. // The next request should toggle the toolbar.collapsed cookie to off.
  25. $this->drupalGet('toolbar/toggle');
  26. $set_cookie = $this->drupalGetHeader('set-cookie', TRUE);
  27. $this->assertTrue((bool) preg_match('#Drupal.toolbar.collapsed=deleted; expires=Thu, 01.Jan.1970 00:00:01 GMT;( Max-Age=0;)? path=' . str_replace('/', '\/', base_path()) . '; SameSite=Lax#', $set_cookie), 'Toolbar cookie toggled to off (deleted).');
  28. // The next request should toggle the toolbar.collapsed cookie back to 1.
  29. $this->drupalGet('toolbar/toggle');
  30. $set_cookie = $this->drupalGetHeader('set-cookie', TRUE);
  31. $this->assertTrue((strpos('Drupal.toolbar.collapsed=1; path=' . base_path() . '; SameSite=Lax', $set_cookie) !== FALSE), 'Toolbar cookie toggled to 1.');
  32. }
  33. }