diff --git a/core/modules/taxonomy/tests/src/Functional/TaxonomyTermContentModerationTest.php b/core/modules/taxonomy/tests/src/Functional/TaxonomyTermContentModerationTest.php index 2d09f8e..d7c9664 100644 --- a/core/modules/taxonomy/tests/src/Functional/TaxonomyTermContentModerationTest.php +++ b/core/modules/taxonomy/tests/src/Functional/TaxonomyTermContentModerationTest.php @@ -2,7 +2,6 @@ namespace Drupal\Tests\taxonomy\Functional; -use Drupal\Core\Language\LanguageInterface; use Drupal\workflows\Entity\Workflow; /** @@ -25,7 +24,7 @@ class TaxonomyTermContentModerationTest extends TaxonomyTestBase { * * @var array */ - public static $modules = ['node', 'taxonomy', 'content_moderation']; + public static $modules = ['taxonomy', 'content_moderation']; /** * {@inheritdoc} @@ -50,13 +49,13 @@ protected function setUp() { public function testTaxonomyTermParents() { // Create a simple hierarchy in the vocabulary, a root term and three parent // terms. - $root = $this->createTerm($this->vocabulary, ['langcode' => 'en']); - $parent_1 = $this->createTerm($this->vocabulary, ['langcode' => 'en', 'parent' => $root->id()]); - $parent_2 = $this->createTerm($this->vocabulary, ['langcode' => 'en', 'parent' => $root->id()]); - $parent_3 = $this->createTerm($this->vocabulary, ['langcode' => 'en', 'parent' => $root->id()]); + $root = $this->createTerm($this->vocabulary, ['langcode' => 'en', 'moderation_state' => 'published']); + $parent_1 = $this->createTerm($this->vocabulary, ['langcode' => 'en', 'moderation_state' => 'published', 'parent' => $root->id()]); + $parent_2 = $this->createTerm($this->vocabulary, ['langcode' => 'en', 'moderation_state' => 'published', 'parent' => $root->id()]); + $parent_3 = $this->createTerm($this->vocabulary, ['langcode' => 'en', 'moderation_state' => 'published', 'parent' => $root->id()]); // Create a child term and assign one of the parents above. - $child = $this->createTerm($this->vocabulary, ['langcode' => 'en', 'parent' => $parent_1->id()]); + $child = $this->createTerm($this->vocabulary, ['langcode' => 'en', 'moderation_state' => 'published', 'parent' => $parent_1->id()]); $taxonomy_storage = \Drupal::entityTypeManager()->getStorage('taxonomy_term'); $validation_message = 'You can only change the parent for the published version of this term.'; @@ -67,13 +66,60 @@ public function testTaxonomyTermParents() { $this->assertSession()->pageTextNotContains($validation_message); - // Try to add a pending revision and change the parent. + // Add a pending revision and change the parent. $this->drupalGet('taxonomy/term/' . $child->id() . '/edit'); $this->drupalPostForm(NULL, [ 'parent[]' => [$parent_2->id()], ], 'Save and Create New Draft'); + // Check that parents were not changed. $this->assertSession()->pageTextContains($validation_message); + $taxonomy_storage->resetCache(); + $this->assertEquals([$parent_1->id()], array_keys($taxonomy_storage->loadParents($child->id()))); + + // Add a pending revision and add a new parent. + $this->drupalGet('taxonomy/term/' . $child->id() . '/edit'); + $this->drupalPostForm(NULL, [ + 'parent[]' => [$parent_1->id(), $parent_3->id()], + ], 'Save and Create New Draft'); + + // Check that parents were not changed. + $this->assertSession()->pageTextContains($validation_message); + $taxonomy_storage->resetCache(); + $this->assertEquals([$parent_1->id()], array_keys($taxonomy_storage->loadParents($child->id()))); + + // Add a pending revision and use the root term as a parent. + $this->drupalGet('taxonomy/term/' . $child->id() . '/edit'); + $this->drupalPostForm(NULL, [ + 'parent[]' => [$root->id()], + ], 'Save and Create New Draft'); + + // Check that parents were not changed. + $this->assertSession()->pageTextContains($validation_message); + $taxonomy_storage->resetCache(); + $this->assertEquals([$parent_1->id()], array_keys($taxonomy_storage->loadParents($child->id()))); + + // Add a pending revision and remove the parent. + $this->drupalGet('taxonomy/term/' . $child->id() . '/edit'); + $this->drupalPostForm(NULL, [ + 'parent[]' => [], + ], 'Save and Create New Draft'); + + // Check that parents were not changed. + $this->assertSession()->pageTextContains($validation_message); + $taxonomy_storage->resetCache(); + $this->assertEquals([$parent_1->id()], array_keys($taxonomy_storage->loadParents($child->id()))); + + // Add a published revision and change the parent. + $this->drupalGet('taxonomy/term/' . $child->id() . '/edit'); + $this->drupalPostForm(NULL, [ + 'parent[]' => [$parent_2->id()], + ], 'Save and Publish'); + + // Check that parents were changed. + $this->assertSession()->pageTextNotContains($validation_message); + $taxonomy_storage->resetCache(); + $this->assertEquals([$parent_2->id()], array_keys($taxonomy_storage->loadParents($child->id()))); } }