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