PanelsEntityViewWebTestCase.test 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. /**
  3. * @file
  4. * Some rudimentary tests for entity handling, will be overridden by others.
  5. */
  6. abstract class PanelsEntityViewWebTestCase extends DrupalWebTestCase {
  7. /**
  8. * Admin user.
  9. *
  10. * @var \StdClass
  11. */
  12. protected $adminUser;
  13. /**
  14. * The task handler used for managing a specific entity type.
  15. *
  16. * @var \StdClass
  17. */
  18. protected $view_name = 'node_view';
  19. /**
  20. * The label used for this entity's task handler.
  21. *
  22. * @var \StdClass
  23. */
  24. protected $view_label = 'Node template';
  25. /**
  26. * {@inheritdoc}
  27. */
  28. function setUp(array $modules = array()) {
  29. $modules[] = 'panels';
  30. $modules[] = 'page_manager';
  31. parent::setUp($modules);
  32. $permissions = array(
  33. // Allow the user to access the Page Manager admin page.
  34. 'use page manager',
  35. // Basic permissions for the module.
  36. 'use panels dashboard',
  37. // General admin access.
  38. 'access administration pages',
  39. );
  40. // Reset the static variable used to identify permissions, otherwise it's
  41. // possible the permissions check in drupalCreateUser will fail.
  42. $this->checkPermissions(array(), TRUE);
  43. cache_clear_all();
  44. // Create the admin user.
  45. $this->adminUser = $this->drupalCreateUser($permissions);
  46. }
  47. /**
  48. * Ensure that the {ENTITY}_view toggle works correctly.
  49. */
  50. function testToggle() {
  51. // Log in as the admin user.
  52. $this->drupalLogin($this->adminUser);
  53. // Load the Panels dashboard.
  54. $this->drupalGet('admin/structure/panels');
  55. $this->assertResponse(200, 'Loaded the main Panels admin page.');
  56. // Confirm that the Node View task handler is disabled.
  57. $this->assertText(t($this->view_label));
  58. $this->assertLinkByHref(url('admin/structure/pages/edit/' . $this->view_name, array('absolute' => FALSE)));
  59. $xpath = $this->xpath("//tr[contains(@class,:tr)]/td/div/div/ul/li[contains(@class,:li)]/a", array(':tr' => 'page-task-' . $this->view_name, ':li' => 'first'));
  60. $this->assertEqual($xpath[0][0], t('Enable'));
  61. // Set the Node View handler to "off".
  62. variable_set('page_manager_' . $this->view_name . '_disabled', TRUE);
  63. // Load the Panels dashboard again.
  64. $this->drupalGet('admin/structure/panels');
  65. $this->assertResponse(200, 'Loaded the main Panels admin page.');
  66. // Confirm that the Node View task handler is still disabled.
  67. $this->assertText(t($this->view_label));
  68. $this->assertNoLinkByHref(url('admin/structure/pages/nojs/disable/' . $this->view_name, array('absolute' => FALSE)));
  69. $xpath = $this->xpath("//tr[contains(@class,:tr)]/td/div/div/ul/li[contains(@class,:li)]/a", array(':tr' => 'page-task-' . $this->view_name, ':li' => 'first'));
  70. $this->assertEqual($xpath[0][0], t('Enable'));
  71. // Set the Node View handler to "on".
  72. variable_set('page_manager_' . $this->view_name . '_disabled', FALSE);
  73. // Load the Panels dashboard again.
  74. $this->drupalGet('admin/structure/panels');
  75. $this->assertResponse(200, 'Loaded the main Panels admin page.');
  76. // Confirm that the Node View task handler is now enabled.
  77. $this->assertLinkByHref(url('admin/structure/pages/nojs/disable/' . $this->view_name, array('absolute' => FALSE)));
  78. $xpath = $this->xpath("//tr[contains(@class,:tr)]/td/div/div/ul/li[contains(@class,:li)]/a", array(':tr' => 'page-task-' . $this->view_name, ':li' => 'last'));
  79. $this->assertEqual($xpath[0][0], t('Disable'));
  80. }
  81. }