quicktabs.test 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. class QuicktabsAdminTestCase extends DrupalWebTestCase {
  3. /**
  4. * Implementation of getInfo().
  5. */
  6. function getInfo() {
  7. return array(
  8. 'name' => t('Quicktabs tests'),
  9. 'description' => t('Add, edit and delete quicktabs.'),
  10. 'group' => t('Quicktabs'),
  11. );
  12. }
  13. /**
  14. * Implementation of setUp().
  15. */
  16. function setUp() {
  17. parent::setUp('ctools','quicktabs');
  18. // Create and login user
  19. $admin_user = $this->drupalCreateUser(array('access administration pages', 'administer quicktabs', 'administer nodes'));
  20. $this->drupalLogin($admin_user);
  21. // Create some nodes that we can populate our tabs with.
  22. for ($i = 0; $i < 5; $i++) {
  23. $node = new stdClass();
  24. $node->type = 'page';
  25. $node->title = 'This is node number '. ($i+1);
  26. $node->body[LANGUAGE_NONE][0]['value'] = $this->randomString(255);
  27. node_object_prepare($node);
  28. node_save($node);
  29. }
  30. }
  31. /**
  32. * Create a Quicktabs instance through the UI and ensure that it is saved properly.
  33. */
  34. function testQuicktabsAdmin() {
  35. // Add a new Quicktabs instance using the UI.
  36. $edit = array(
  37. 'machine_name' => strtolower($this->randomName()),
  38. 'title' => $this->randomName(),
  39. 'ajax' => 0,
  40. 'hide_empty_tabs' => FALSE,
  41. 'renderer' => 'quicktabs',
  42. );
  43. $saved = $edit;
  44. // We'll be using the $saved array to compare against the Quicktabs instance
  45. // that gets created. However, hierarchical form elements are dealt with
  46. // differenly so we can't include them in the $saved array like this.
  47. $tab_title_first = $this->randomName();
  48. $tab_title_second = $this->randomName();
  49. $edit += array(
  50. 'tabs[0][type]' => 'node',
  51. 'tabs[0][node][nid]' => 1,
  52. 'tabs[0][title]' => $tab_title_first,
  53. 'tabs[0][weight]' => 0,
  54. 'tabs[1][type]' => 'node',
  55. 'tabs[1][node][nid]' => 2,
  56. 'tabs[1][title]' => $tab_title_second,
  57. 'tabs[1][weight]' => 1,
  58. );
  59. // Now add on the tabs info to the $saved array - it's the same as what we
  60. // put in the edit form but we need it in proper array format.
  61. $saved['tabs'] = array(0 => array('type' => 'node', 'nid' => 1, 'title' => $tab_title_first, 'weight' => 0), 1 => array('type' => 'node', 'nid' => 2, 'title' => $tab_title_second, 'weight' => 1));
  62. $this->drupalPost('admin/structure/quicktabs/add', $edit, t('Save'));
  63. // Check that the quicktabs object is in the database.
  64. $quicktabs = quicktabs_load($edit['machine_name']);
  65. $this->assertTrue($quicktabs != FALSE, t('Quicktabs instance found in database'));
  66. // Check each individual property of the quicktabs and make sure it was set.
  67. foreach ($saved as $property => $value) {
  68. if ($property == 'tabs') {
  69. // Add some extra default values that we didn't include on the form, for
  70. // the sake of comparing the two tabs arrays.
  71. foreach ($value as &$val) {
  72. $val += array('teaser' => 0, 'hide_title' => 1);
  73. }
  74. }
  75. $this->assertEqual($quicktabs->$property, $value, t('Quicktabs property %property properly saved.', array('%property' => $property)));
  76. }
  77. // Edit the Quicktabs instance through the UI.
  78. $edit = array(
  79. 'title' => $this->randomName(),
  80. 'ajax' => 1,
  81. 'hide_empty_tabs' => TRUE,
  82. 'renderer' => 'ui_tabs',
  83. 'default_tab' => 1,
  84. );
  85. $saved = $edit;
  86. $tab_title_first = $this->randomName();
  87. $tab_title_second = $this->randomName();
  88. $edit += array(
  89. 'tabs[0][title]' => $tab_title_first,
  90. 'tabs[0][weight]' => 1,
  91. 'tabs[0][node][nid]' => 3,
  92. 'tabs[0][node][teaser]' => 1,
  93. 'tabs[0][node][hide_title]' => FALSE,
  94. 'tabs[1][title]' => $tab_title_second,
  95. 'tabs[1][weight]' => 0,
  96. 'tabs[1][node][nid]' => 4,
  97. 'tabs[1][node][teaser]' => FALSE,
  98. 'tabs[1][node][hide_title]' => 1,
  99. );
  100. $saved['tabs'] = array(0 => array('type' => 'node', 'nid' => 4, 'title' => $tab_title_second, 'weight' => 0, 'teaser' => 0, 'hide_title' => 1), 1 => array('type' => 'node', 'nid' => 3, 'title' => $tab_title_first, 'weight' => 1, 'teaser' => 1, 'hide_title' => 0));
  101. $this->drupalPost('admin/structure/quicktabs/manage/'. $quicktabs->machine_name .'/edit', $edit, t('Save'));
  102. // Reset static vars because ctools will have cached the original $quicktabs object
  103. drupal_static_reset();
  104. // Check that the quicktabs object is in the database.
  105. $edited_qt = quicktabs_load($quicktabs->machine_name);
  106. $this->assertTrue($edited_qt != FALSE, t('Quicktabs instance found in database'));
  107. // Check each individual property of the quicktabs and make sure it was set.
  108. foreach ($saved as $property => $value) {
  109. $this->assertEqual($edited_qt->$property, $value, t('Quicktabs property %property properly saved.', array('%property' => $property)));
  110. }
  111. // Delete the Quicktabs instance through the UI.
  112. $this->drupalPost('admin/structure/quicktabs/manage/'. $quicktabs->machine_name .'/delete', array(), t('Delete'));
  113. // Reset static vars because ctools will have cached the original $quicktabs object
  114. drupal_static_reset();
  115. // Check that the quicktabs object is no longer in the database.
  116. $this->assertNull(quicktabs_load($quicktabs->machine_name), t('Quicktabs instance not found in database'));
  117. }
  118. }