danielebarchiesi@2: t('Quicktabs tests'), danielebarchiesi@2: 'description' => t('Add, edit and delete quicktabs.'), danielebarchiesi@2: 'group' => t('Quicktabs'), danielebarchiesi@2: ); danielebarchiesi@2: } danielebarchiesi@2: danielebarchiesi@2: /** danielebarchiesi@2: * Implementation of setUp(). danielebarchiesi@2: */ danielebarchiesi@2: function setUp() { danielebarchiesi@2: parent::setUp('ctools','quicktabs'); danielebarchiesi@2: danielebarchiesi@2: // Create and login user danielebarchiesi@2: $admin_user = $this->drupalCreateUser(array('access administration pages', 'administer quicktabs', 'administer nodes')); danielebarchiesi@2: $this->drupalLogin($admin_user); danielebarchiesi@2: danielebarchiesi@2: // Create some nodes that we can populate our tabs with. danielebarchiesi@2: for ($i = 0; $i < 5; $i++) { danielebarchiesi@2: $node = new stdClass(); danielebarchiesi@2: $node->type = 'page'; danielebarchiesi@2: $node->title = 'This is node number '. ($i+1); danielebarchiesi@2: $node->body[LANGUAGE_NONE][0]['value'] = $this->randomString(255); danielebarchiesi@2: node_object_prepare($node); danielebarchiesi@2: node_save($node); danielebarchiesi@2: } danielebarchiesi@2: } danielebarchiesi@2: danielebarchiesi@2: /** danielebarchiesi@2: * Create a Quicktabs instance through the UI and ensure that it is saved properly. danielebarchiesi@2: */ danielebarchiesi@2: function testQuicktabsAdmin() { danielebarchiesi@2: // Add a new Quicktabs instance using the UI. danielebarchiesi@2: $edit = array( danielebarchiesi@2: 'machine_name' => strtolower($this->randomName()), danielebarchiesi@2: 'title' => $this->randomName(), danielebarchiesi@2: 'ajax' => 0, danielebarchiesi@2: 'hide_empty_tabs' => FALSE, danielebarchiesi@2: 'renderer' => 'quicktabs', danielebarchiesi@2: ); danielebarchiesi@2: danielebarchiesi@2: $saved = $edit; danielebarchiesi@2: // We'll be using the $saved array to compare against the Quicktabs instance danielebarchiesi@2: // that gets created. However, hierarchical form elements are dealt with danielebarchiesi@2: // differenly so we can't include them in the $saved array like this. danielebarchiesi@2: $tab_title_first = $this->randomName(); danielebarchiesi@2: $tab_title_second = $this->randomName(); danielebarchiesi@2: $edit += array( danielebarchiesi@2: 'tabs[0][type]' => 'node', danielebarchiesi@2: 'tabs[0][node][nid]' => 1, danielebarchiesi@2: 'tabs[0][title]' => $tab_title_first, danielebarchiesi@2: 'tabs[0][weight]' => 0, danielebarchiesi@2: 'tabs[1][type]' => 'node', danielebarchiesi@2: 'tabs[1][node][nid]' => 2, danielebarchiesi@2: 'tabs[1][title]' => $tab_title_second, danielebarchiesi@2: 'tabs[1][weight]' => 1, danielebarchiesi@2: ); danielebarchiesi@2: // Now add on the tabs info to the $saved array - it's the same as what we danielebarchiesi@2: // put in the edit form but we need it in proper array format. danielebarchiesi@2: $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: $this->drupalPost('admin/structure/quicktabs/add', $edit, t('Save')); danielebarchiesi@2: danielebarchiesi@2: // Check that the quicktabs object is in the database. danielebarchiesi@2: $quicktabs = quicktabs_load($edit['machine_name']); danielebarchiesi@2: $this->assertTrue($quicktabs != FALSE, t('Quicktabs instance found in database')); danielebarchiesi@2: danielebarchiesi@2: // Check each individual property of the quicktabs and make sure it was set. danielebarchiesi@2: foreach ($saved as $property => $value) { danielebarchiesi@2: if ($property == 'tabs') { danielebarchiesi@2: // Add some extra default values that we didn't include on the form, for danielebarchiesi@2: // the sake of comparing the two tabs arrays. danielebarchiesi@2: foreach ($value as &$val) { danielebarchiesi@2: $val += array('teaser' => 0, 'hide_title' => 1); danielebarchiesi@2: } danielebarchiesi@2: } danielebarchiesi@2: $this->assertEqual($quicktabs->$property, $value, t('Quicktabs property %property properly saved.', array('%property' => $property))); danielebarchiesi@2: } danielebarchiesi@2: danielebarchiesi@2: // Edit the Quicktabs instance through the UI. danielebarchiesi@2: $edit = array( danielebarchiesi@2: 'title' => $this->randomName(), danielebarchiesi@2: 'ajax' => 1, danielebarchiesi@2: 'hide_empty_tabs' => TRUE, danielebarchiesi@2: 'renderer' => 'ui_tabs', danielebarchiesi@2: 'default_tab' => 1, danielebarchiesi@2: ); danielebarchiesi@2: danielebarchiesi@2: $saved = $edit; danielebarchiesi@2: $tab_title_first = $this->randomName(); danielebarchiesi@2: $tab_title_second = $this->randomName(); danielebarchiesi@2: $edit += array( danielebarchiesi@2: 'tabs[0][title]' => $tab_title_first, danielebarchiesi@2: 'tabs[0][weight]' => 1, danielebarchiesi@2: 'tabs[0][node][nid]' => 3, danielebarchiesi@2: 'tabs[0][node][teaser]' => 1, danielebarchiesi@2: 'tabs[0][node][hide_title]' => FALSE, danielebarchiesi@2: 'tabs[1][title]' => $tab_title_second, danielebarchiesi@2: 'tabs[1][weight]' => 0, danielebarchiesi@2: 'tabs[1][node][nid]' => 4, danielebarchiesi@2: 'tabs[1][node][teaser]' => FALSE, danielebarchiesi@2: 'tabs[1][node][hide_title]' => 1, danielebarchiesi@2: ); danielebarchiesi@2: $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: $this->drupalPost('admin/structure/quicktabs/manage/'. $quicktabs->machine_name .'/edit', $edit, t('Save')); danielebarchiesi@2: danielebarchiesi@2: // Reset static vars because ctools will have cached the original $quicktabs object danielebarchiesi@2: drupal_static_reset(); danielebarchiesi@2: // Check that the quicktabs object is in the database. danielebarchiesi@2: $edited_qt = quicktabs_load($quicktabs->machine_name); danielebarchiesi@2: $this->assertTrue($edited_qt != FALSE, t('Quicktabs instance found in database')); danielebarchiesi@2: danielebarchiesi@2: // Check each individual property of the quicktabs and make sure it was set. danielebarchiesi@2: foreach ($saved as $property => $value) { danielebarchiesi@2: $this->assertEqual($edited_qt->$property, $value, t('Quicktabs property %property properly saved.', array('%property' => $property))); danielebarchiesi@2: } danielebarchiesi@2: danielebarchiesi@2: // Delete the Quicktabs instance through the UI. danielebarchiesi@2: $this->drupalPost('admin/structure/quicktabs/manage/'. $quicktabs->machine_name .'/delete', array(), t('Delete')); danielebarchiesi@2: // Reset static vars because ctools will have cached the original $quicktabs object danielebarchiesi@2: drupal_static_reset(); danielebarchiesi@2: // Check that the quicktabs object is no longer in the database. danielebarchiesi@2: $this->assertNull(quicktabs_load($quicktabs->machine_name), t('Quicktabs instance not found in database')); danielebarchiesi@2: } danielebarchiesi@2: danielebarchiesi@2: } danielebarchiesi@2: