diff -u b/redirect.module b/redirect.module --- b/redirect.module +++ b/redirect.module @@ -517,6 +517,8 @@ ]), 'attributes' => [ 'class' => 'button', + // @todo Perhaps this could be more slick and use the off_canvas dialog? + // @see https://www.drupal.org/node/2931770 'target' => '_blank', ], ]; only in patch2: unchanged: --- /dev/null +++ b/tests/src/Functional/RedirectNodeFormTest.php @@ -0,0 +1,95 @@ +profile != 'standard') { + $this->drupalCreateContentType([ + 'type' => 'page', + 'name' => 'Basic page', + 'display_submitted' => FALSE, + ]); + } + + $this->webUser = $this->drupalCreateUser([ + 'access content', + 'create page content', + 'edit own page content', + ]); + + $this->adminUser = $this->drupalCreateUser([ + 'access content', + 'administer redirects', + 'bypass node access', + ]); + } + + public function testNodeForm() { + // Login as a regular user. + $this->drupalLogin($this->webUser); + + // Create "Basic page" content with title. + // Add the node to the frontpage so we can test if teaser links are + // clickable. + $settings = [ + 'title' => $this->randomMachineName(8), + ]; + $node = $this->drupalCreateNode($settings); + + // Load the node edit form. + $this->drupalGet('node/' . $node->id() . '/edit'); + + // Make sure the redirect add button is not visible to this regular user. + $this->assertNoRaw('Add URL redirect to this '); + + // Now edit the same node as an admin user. + $this->drupalLogin($this->adminUser); + $this->drupalGet('node/' . $node->id() . '/edit'); + + // Make sure the redirect add button is visible for the admin user, and that + // the node type is correctly rendered as a placeholder. + $this->assertRaw('Add URL redirect to this Basic page'); + + // Make sure the link works as expected. + $this->clickLink('Add URL redirect to this Basic page'); + $this->assertUrl('admin/config/search/redirect/add'); + $this->assertFieldsByValue($this->xpath("//input[@id = 'edit-redirect-redirect-0-uri']"), '/node/' . $node->id(), 'To: field correctly pre-filled.'); + } + +}