diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php index 3c47f15..6d7d8e8 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php @@ -95,6 +95,61 @@ function testTaxonomyTermHierarchy() { } /** + * Tests that many terms with parents show on each page + */ + function testTaxonomyTermChildTerms() { + // Set limit to 10 terms per page. Set variable to 9 so 10 terms appear. + config('taxonomy.settings')->set('terms_per_page_admin', '9')->save(); + $term1 = $this->createTerm($this->vocabulary); + $terms_array = ''; + + // Create 40 terms. Terms 1-12 get parent of $term1. All others are + // individual terms. + for ($x = 1; $x <= 40; $x++) { + $term = $this->createTerm($this->vocabulary); + + $edit = array(); + // Set terms in order so we know which terms will be on which pages. + $edit['weight'] = $x; + + // Set terms 1-20 to be children of first term created. + if ($x <= 12) { + $edit['parent[]'] = $term1->tid; + } + $this->drupalPost('taxonomy/term/' . $term->tid . '/edit', $edit, t('Save')); + $children = taxonomy_term_load_children($term1->tid); + $parents = taxonomy_term_load_parents($term->tid); + $terms_array[$x] = taxonomy_term_load($term->tid); + } + + // Get Page 1. + $this->drupalGet('admin/structure/taxonomy/' . $this->vocabulary->machine_name); + $this->assertText($term1->name, 'Parent Term is displayed on Page 1'); + for ($x = 1; $x <= 13; $x++) { + $this->assertText($terms_array[$x]->name, $terms_array[$x]->name . ' found on Page 1'); + } + + // Get Page 2. + $this->drupalGet('admin/structure/taxonomy/' . $this->vocabulary->machine_name, array('query' => array('page' => 1))); + $this->assertText($term1->name, 'Parent Term is displayed on Page 2'); + for ($x = 1; $x <= 18; $x++) { + $this->assertText($terms_array[$x]->name, $terms_array[$x]->name . ' found on Page 2'); + } + + // Get Page 3. + $this->drupalGet('admin/structure/taxonomy/' . $this->vocabulary->machine_name, array('query' => array('page' => 2))); + $this->assertNoText($term1->name, 'Parent Term is not displayed on Page 3'); + for ($x = 1; $x <= 17; $x++) { + $this->assertNoText($terms_array[$x]->name, $terms_array[$x]->name . ' not found on Page 3'); + } + for ($x =18; $x <= 25; $x++) { + $this->assertText($terms_array[$x]->name, $terms_array[$x]->name . ' found on Page 3'); + } + } + + + + /** * Test that hook_node_$op implementations work correctly. * * Save & edit a node and assert that taxonomy terms are saved/loaded properly. diff --git a/core/modules/taxonomy/taxonomy.admin.inc b/core/modules/taxonomy/taxonomy.admin.inc index 5578936..0d486ab 100644 --- a/core/modules/taxonomy/taxonomy.admin.inc +++ b/core/modules/taxonomy/taxonomy.admin.inc @@ -169,10 +169,10 @@ function taxonomy_overview_terms($form, &$form_state, Vocabulary $vocabulary) { $delta = 0; $term_deltas = array(); $tree = taxonomy_get_tree($vocabulary->vid, 0, NULL, TRUE); - $term = current($tree); + $tree_index = 0; do { // In case this tree is completely empty. - if (empty($term)) { + if (empty($tree[$tree_index])) { break; } $delta++; @@ -188,13 +188,14 @@ function taxonomy_overview_terms($form, &$form_state, Vocabulary $vocabulary) { } // Do not let a term start the page that is not at the root. + $term = $tree[$tree_index]; if (isset($term->depth) && ($term->depth > 0) && !isset($back_step)) { $back_step = 0; - while ($pterm = prev($tree)) { + while ($pterm = $tree[--$tree_index]) { $before_entries--; $back_step++; if ($pterm->depth == 0) { - prev($tree); + $tree_index--; continue 2; // Jump back to the start of the root level parent. } } @@ -226,7 +227,7 @@ function taxonomy_overview_terms($form, &$form_state, Vocabulary $vocabulary) { $root_entries++; } $current_page[$key] = $term; - } while ($term = next($tree)); + } while (isset($tree[++$tree_index])); // Because we didn't use a pager query, set the necessary pager variables. $total_entries = $before_entries + $page_entries + $after_entries;