diff options
author | Angie Byron <webchick@24967.no-reply.drupal.org> | 2009-10-24 04:23:51 +0000 |
---|---|---|
committer | Angie Byron <webchick@24967.no-reply.drupal.org> | 2009-10-24 04:23:51 +0000 |
commit | dec6514c3b2d889c3a9fb19731e49e83d554392c (patch) | |
tree | 1317324c3677c89e86343214be64e6b7363c1ad5 | |
parent | 6c5e31abcbfe199a983ed6161207613d66423412 (diff) | |
download | brdo-dec6514c3b2d889c3a9fb19731e49e83d554392c.tar.gz brdo-dec6514c3b2d889c3a9fb19731e49e83d554392c.tar.bz2 |
#595876 by c960657: Fixed taxonomy term reordering (with tests).
-rw-r--r-- | modules/simpletest/drupal_web_test_case.php | 1 | ||||
-rw-r--r-- | modules/taxonomy/taxonomy.admin.inc | 2 | ||||
-rw-r--r-- | modules/taxonomy/taxonomy.test | 63 |
3 files changed, 65 insertions, 1 deletions
diff --git a/modules/simpletest/drupal_web_test_case.php b/modules/simpletest/drupal_web_test_case.php index ef4f49151..323781b31 100644 --- a/modules/simpletest/drupal_web_test_case.php +++ b/modules/simpletest/drupal_web_test_case.php @@ -1581,6 +1581,7 @@ class DrupalWebTestCase extends DrupalTestCase { switch ($type) { case 'text': case 'textarea': + case 'hidden': case 'password': $post[$name] = $edit[$name]; unset($edit[$name]); diff --git a/modules/taxonomy/taxonomy.admin.inc b/modules/taxonomy/taxonomy.admin.inc index 7a12fbdc4..e605c8e81 100644 --- a/modules/taxonomy/taxonomy.admin.inc +++ b/modules/taxonomy/taxonomy.admin.inc @@ -240,7 +240,7 @@ function taxonomy_overview_terms($form, &$form_state, $vocabulary) { // Check for confirmation forms. if (isset($form_state['confirm_reset_alphabetical'])) { - return taxonomy_vocabulary_confirm_reset_alphabetical($form_state, $vocabulary->vid); + return taxonomy_vocabulary_confirm_reset_alphabetical($form, $form_state, $vocabulary->vid); } $form['#vocabulary'] = $vocabulary; diff --git a/modules/taxonomy/taxonomy.test b/modules/taxonomy/taxonomy.test index 6b64bf8cc..27508f572 100644 --- a/modules/taxonomy/taxonomy.test +++ b/modules/taxonomy/taxonomy.test @@ -479,6 +479,69 @@ class TaxonomyTermTestCase extends TaxonomyWebTestCase { } /** + * Save, edit and delete a term using the user interface. + */ + function testTermReorder() { + $this->createTerm($this->vocabulary); + $this->createTerm($this->vocabulary); + $this->createTerm($this->vocabulary); + + // Fetch the created terms in the default alphabetical order, i.e. term1 + // precedes term2 alphabetically, and term2 precedes term3. + drupal_static_reset('taxonomy_get_tree'); + drupal_static_reset('taxonomy_get_treeparent'); + drupal_static_reset('taxonomy_get_treeterms'); + list($term1, $term2, $term3) = taxonomy_get_tree($this->vocabulary->vid); + + // Change the order to term2, term3, term1. Emulate the reordering done by + // tabledrag.js by changing the page HTML source. Each term has three hidden + // fields, "tid:1:0[tid]", "tid:1:0[parent]", and "tid:1:0[depth]". The + // order of the input fields in the page is used when the form is processed. + $this->drupalGet('admin/structure/taxonomy/' . $this->vocabulary->vid . '/list'); + $reorder = array( + 'tid:' . $term1->tid . ':0' => 'tid:' . $term2->tid . ':0', + 'tid:' . $term2->tid . ':0' => 'tid:' . $term3->tid . ':0', + 'tid:' . $term3->tid . ':0' => 'tid:' . $term1->tid . ':0', + ); + $this->drupalSetContent(strtr($this->drupalGetContent(), $reorder)); + + // Make term3 a child of term2, and update all hidden fields. + $edit = array( + 'tid:' . $term2->tid . ':0[tid]' => $term2->tid, + 'tid:' . $term2->tid . ':0[parent]' => 0, + 'tid:' . $term2->tid . ':0[depth]' => 0, + 'tid:' . $term3->tid . ':0[tid]' => $term3->tid, + 'tid:' . $term3->tid . ':0[parent]' => $term2->tid, + 'tid:' . $term3->tid . ':0[depth]' => 1, + 'tid:' . $term1->tid . ':0[tid]' => $term1->tid, + 'tid:' . $term1->tid . ':0[parent]' => 0, + 'tid:' . $term1->tid . ':0[depth]' => 0, + ); + $this->drupalPost(NULL, $edit, t('Save')); + + drupal_static_reset('taxonomy_get_tree'); + drupal_static_reset('taxonomy_get_treeparent'); + drupal_static_reset('taxonomy_get_treeterms'); + $terms = taxonomy_get_tree($this->vocabulary->vid); + $this->assertEqual($terms[0]->tid, $term2->tid, t('Term 2 was moved above term 1.')); + $this->assertEqual($terms[1]->parents, array($term2->tid), t('Term 3 was made a child of term 2.')); + $this->assertEqual($terms[2]->tid, $term1->tid, t('Term 1 was moved below term 2.')); + + $this->drupalPost('admin/structure/taxonomy/' . $this->vocabulary->vid . '/list', array(), t('Reset to alphabetical')); + // Submit confirmation form. + $this->drupalPost(NULL, array(), t('Reset to alphabetical')); + + drupal_static_reset('taxonomy_get_tree'); + drupal_static_reset('taxonomy_get_treeparent'); + drupal_static_reset('taxonomy_get_treeterms'); + $terms = taxonomy_get_tree($this->vocabulary->vid); + $this->assertEqual($terms[0]->tid, $term1->tid, t('Term 1 was moved to back above term 2.')); + $this->assertEqual($terms[1]->tid, $term2->tid, t('Term 2 was moved to back below term 1.')); + $this->assertEqual($terms[2]->tid, $term3->tid, t('Term 3 is still below term 2.')); + $this->assertEqual($terms[2]->parents, array($term2->tid), t('Term 3 is still a child of term 2.').var_export($terms[1]->tid,1)); + } + + /** * Test taxonomy_get_term_by_name(). */ function testTaxonomyGetTermByName() { |