diff --git a/core/modules/menu_ui/tests/src/Functional/MenuUiContentModerationTest.php b/core/modules/menu_ui/tests/src/Functional/MenuUiContentModerationTest.php new file mode 100644 index 0000000..3d6fa56 --- /dev/null +++ b/core/modules/menu_ui/tests/src/Functional/MenuUiContentModerationTest.php @@ -0,0 +1,102 @@ +drupalPlaceBlock('system_menu_block:main'); + + // Create a 'page' content type. + $this->drupalCreateContentType([ + 'type' => 'page', + 'name' => 'Basic page', + 'display_submitted' => FALSE, + ]); + + $workflow = Workflow::load('editorial'); + $workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'page'); + $workflow->save(); + } + + /** + * Tests that node drafts can not modify the menu settings. + */ + public function testMenuUiWithForwardRevisions() { + $editor = $this->drupalCreateUser([ + 'administer nodes', + 'administer menu', + 'create page content', + 'edit any page content', + 'use editorial transition create_new_draft', + 'use editorial transition publish', + 'view latest version', + 'view any unpublished content', + ]); + $this->drupalLogin($editor); + + // Create a node. + $node = $this->drupalCreateNode(); + + // Add a menu link and save a new default (published) revision. + $edit = [ + 'menu[enabled]' => 1, + 'menu[title]' => 'Test menu link', + ]; + $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save and Publish')); + + $this->assertSession()->linkExists('Test menu link'); + + // Try to change the menu link title and save a new non-default (draft) + // revision. + $edit = [ + 'menu[enabled]' => 1, + 'menu[title]' => 'Test menu link draft', + ]; + $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save and Create New Draft')); + + // Check that the menu settings were not applied. + $this->assertSession()->pageTextContains('This is not the default revision. You can only change the menu settings for the published version of this content.'); + $this->assertSession()->linkExists('Test menu link'); + $this->assertSession()->linkNotExists('Test menu link draft'); + + // Try to delete the menu link and save a new non-default (draft) revision. + $edit = [ + 'menu[enabled]' => 0, + ]; + $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save and Create New Draft')); + + // Check that the menu settings were not applied. + $this->assertSession()->pageTextContains('This is not the default revision. You can only change the menu settings for the published version of this content.'); + $this->assertSession()->linkExists('Test menu link'); + + // Try to save a new non-default (draft) revision without any changes and + // check that the error message is not shown. + $this->drupalPostForm('node/' . $node->id() . '/edit', [], t('Save and Create New Draft')); + + // Check that the menu settings were not applied. + $this->assertSession()->pageTextNotContains('This is not the default revision. You can only change the menu settings for the published version of this content.'); + $this->assertSession()->linkExists('Test menu link'); + } + +}