summaryrefslogtreecommitdiffstats
path: root/core/modules/system/src/Tests/Form/ConfirmFormTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'core/modules/system/src/Tests/Form/ConfirmFormTest.php')
-rw-r--r--core/modules/system/src/Tests/Form/ConfirmFormTest.php33
1 files changed, 33 insertions, 0 deletions
diff --git a/core/modules/system/src/Tests/Form/ConfirmFormTest.php b/core/modules/system/src/Tests/Form/ConfirmFormTest.php
index ffcc44a..9521176 100644
--- a/core/modules/system/src/Tests/Form/ConfirmFormTest.php
+++ b/core/modules/system/src/Tests/Form/ConfirmFormTest.php
@@ -7,6 +7,8 @@
namespace Drupal\system\Tests\Form;
+use Drupal\Component\Utility\String;
+use Drupal\Core\Url;
use Drupal\simpletest\WebTestBase;
/**
@@ -50,4 +52,35 @@ class ConfirmFormTest extends WebTestBase {
$this->assertUrl('form-test/confirm-form', array('query' => array('destination' => 'admin/config')), "The form's complex cancel link was followed.");
}
+ /**
+ * Tests that the confirm form does not use external destinations.
+ */
+ public function testConfirmFormWithExternalDestination() {
+ $this->drupalGet('form-test/confirm-form');
+ $this->assertCancelLinkUrl(Url::fromRoute('form_test.route8'));
+ $this->drupalGet('form-test/confirm-form', array('query' => array('destination' => 'node')));
+ $this->assertCancelLinkUrl(Url::fromUri('internal:/node'));
+ $this->drupalGet('form-test/confirm-form', array('query' => array('destination' => 'http://example.com')));
+ $this->assertCancelLinkUrl(Url::fromRoute('form_test.route8'));
+ }
+
+ /**
+ * Asserts that a cancel link is present pointing to the provided URL.
+ *
+ * @param \Drupal\Core\Url $url
+ * The url to check for.
+ * @param string $message
+ * The assert message.
+ * @param string $group
+ * The assertion group.
+ *
+ * @return bool
+ * Result of the assertion.
+ */
+ public function assertCancelLinkUrl(Url $url, $message = '', $group = 'Other') {
+ $links = $this->xpath('//a[@href=:url]', [':url' => $url->toString()]);
+ $message = ($message ? $message : String::format('Cancel link with url %url found.', ['%url' => $url->toString()]));
+ return $this->assertTrue(isset($links[0]), $message, $group);
+ }
+
}