From bea70831ae833665f258aa102e2afd3341d66a02 Mon Sep 17 00:00:00 2001 From: webchick <webchick@24967.no-reply.drupal.org> Date: Sat, 1 Sep 2012 22:33:30 -0700 Subject: [PATCH] Issue #1429442 by Jody Lynn, gnuget, nrambeck, sun: Fixed Access denied page shown after submitting form that creates a unpublished node. --- .../lib/Drupal/forum/Tests/ForumIndexTest.php | 1 + .../lib/Drupal/node/NodeFormController.php | 2 +- .../Drupal/node/Tests/NodeCreationTest.php | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/core/modules/forum/lib/Drupal/forum/Tests/ForumIndexTest.php b/core/modules/forum/lib/Drupal/forum/Tests/ForumIndexTest.php index a9d1a7cd1dd2..7ae7d5f60d3e 100644 --- a/core/modules/forum/lib/Drupal/forum/Tests/ForumIndexTest.php +++ b/core/modules/forum/lib/Drupal/forum/Tests/ForumIndexTest.php @@ -70,6 +70,7 @@ function testForumIndexStatus() { 'status' => FALSE, ); $this->drupalPost("node/{$node->nid}/edit", $edit, t('Save')); + $this->drupalGet("node/{$node->nid}"); $this->assertText(t('Access denied'), 'Unpublished node is no longer accessible.'); // Verify that the node no longer appears on the index. diff --git a/core/modules/node/lib/Drupal/node/NodeFormController.php b/core/modules/node/lib/Drupal/node/NodeFormController.php index 51f43082342a..b99547e6bf2f 100644 --- a/core/modules/node/lib/Drupal/node/NodeFormController.php +++ b/core/modules/node/lib/Drupal/node/NodeFormController.php @@ -391,7 +391,7 @@ public function save(array $form, array &$form_state) { if ($node->nid) { $form_state['values']['nid'] = $node->nid; $form_state['nid'] = $node->nid; - $form_state['redirect'] = 'node/' . $node->nid; + $form_state['redirect'] = node_access('view', $node) ? 'node/' . $node->nid : '<front>'; } else { // In the unlikely case something went wrong on save, the node will be diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeCreationTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeCreationTest.php index a8fbb07bd456..f7763d2a65a1 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeCreationTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeCreationTest.php @@ -95,4 +95,23 @@ function testFailedPageCreation() { $records = db_query("SELECT wid FROM {watchdog} WHERE variables LIKE '%Test exception for rollback.%'")->fetchAll(); $this->assertTrue(count($records) > 0, t('Rollback explanatory error logged to watchdog.')); } + + /** + * Create an unpublished node and confirm correct redirect behavior. + */ + function testUnpublishedNodeCreation() { + // Set "Basic page" content type to be unpublished by default. + variable_set('node_options_page', array()); + // Set the front page to the default "node" page. + config('system.site')->set('page.front', 'node')->save(); + + // Create a node. + $edit = array(); + $edit["title"] = $this->randomName(8); + $edit["body[" . LANGUAGE_NOT_SPECIFIED . "][0][value]"] = $this->randomName(16); + $this->drupalPost('node/add/page', $edit, t('Save')); + + // Check that the user was redirected to the home page. + $this->assertText(t('Welcome to Drupal'), t('The user is redirected to the home page.')); + } } -- GitLab