summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathaniel Catchpole2013-10-16 11:08:52 (GMT)
committerNathaniel Catchpole2013-10-16 11:08:52 (GMT)
commit1eb27ae08c38e4fc3b5df979486a555425fbcbd5 (patch)
tree98a07a64f61d6197bfa472335df375aaac0f7888
parent034d523504cf7d0a252c72a284e611b919f6e972 (diff)
Issue #2077387 by wadmiraal, guschilds: Fixed Taxonomy term is improperly deleted when only one of two parents is deleted.
-rw-r--r--core/modules/taxonomy/lib/Drupal/taxonomy/Entity/Term.php4
-rw-r--r--core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermUnitTest.php21
2 files changed, 22 insertions, 3 deletions
diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Entity/Term.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Entity/Term.php
index 066e8f2..acfd78f 100644
--- a/core/modules/taxonomy/lib/Drupal/taxonomy/Entity/Term.php
+++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Entity/Term.php
@@ -157,9 +157,7 @@ class Term extends ContentEntityBase implements TermInterface {
foreach ($children as $child) {
// If the term has multiple parents, we don't delete it.
$parents = taxonomy_term_load_parents($child->id());
- // Because the parent has already been deleted, the parent count might
- // be 0.
- if (count($parents) <= 1) {
+ if (empty($parents)) {
$orphans[] = $child->id();
}
}
diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermUnitTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermUnitTest.php
index 4a81f05..83132c3 100644
--- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermUnitTest.php
+++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermUnitTest.php
@@ -33,6 +33,27 @@ class TermUnitTest extends TaxonomyTestBase {
}
/**
+ * Deleting a parent of a term with multiple parents does not delete the term.
+ */
+ function testMultipleParentDelete() {
+ $vocabulary = $this->createVocabulary();
+ $parent_term1 = $this->createTerm($vocabulary);
+ $parent_term2 = $this->createTerm($vocabulary);
+ $child_term = $this->createTerm($vocabulary);
+ $child_term->parent = array($parent_term1->id(), $parent_term2->id());
+ $child_term->save();
+ $child_term_id = $child_term->id();
+
+ $parent_term1->delete();
+ $child_term = entity_load('taxonomy_term', $child_term_id, TRUE);
+ $this->assertTrue(!empty($child_term), 'Child term is not deleted if only one of its parents is removed.');
+
+ $parent_term2->delete();
+ $child_term = entity_load('taxonomy_term', $child_term_id, TRUE);
+ $this->assertTrue(empty($child_term), 'Child term is deleted if all of its parents are removed.');
+ }
+
+ /**
* Test a taxonomy with terms that have multiple parents of different depths.
*/
function testTaxonomyVocabularyTree() {