comparison sites/all/modules/quicktabs/tests/quicktabs.test @ 2:b74b41bb73f0

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