From 8f138ab1a6568091fe045f6de5db8ce2992d52b2 Mon Sep 17 00:00:00 2001
From: Alex Pott <alex.a.pott@googlemail.com>
Date: Sun, 8 May 2016 11:04:52 -0500
Subject: [PATCH] Issue #2719701 by jhedstrom: BrowserTestBase::drupalGet()
 incompatible with WebTestBase::drupalGet()

---
 .../tests/src/Functional/BrowserTestBaseTest.php       |  9 +++++++++
 core/tests/Drupal/Tests/BrowserTestBase.php            | 10 ++++++++--
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/core/modules/simpletest/tests/src/Functional/BrowserTestBaseTest.php b/core/modules/simpletest/tests/src/Functional/BrowserTestBaseTest.php
index 1ec4604a91a4..d321a4b5b287 100644
--- a/core/modules/simpletest/tests/src/Functional/BrowserTestBaseTest.php
+++ b/core/modules/simpletest/tests/src/Functional/BrowserTestBaseTest.php
@@ -2,6 +2,7 @@
 
 namespace Drupal\Tests\simpletest\Functional;
 
+use Drupal\Core\Url;
 use Drupal\Tests\BrowserTestBase;
 
 /**
@@ -31,6 +32,14 @@ public function testGoTo() {
 
     // Test page contains some text.
     $this->assertSession()->pageTextContains('Test page text.');
+
+    // Test drupalGet with a url object.
+    $url = Url::fromRoute('test_page_test.render_title');
+    $this->drupalGet($url);
+    $this->assertSession()->statusCodeEquals(200);
+
+    // Test page contains some text.
+    $this->assertSession()->pageTextContains('Hello Drupal');
   }
 
   /**
diff --git a/core/tests/Drupal/Tests/BrowserTestBase.php b/core/tests/Drupal/Tests/BrowserTestBase.php
index 19fc9132244c..cefb7538f6c8 100644
--- a/core/tests/Drupal/Tests/BrowserTestBase.php
+++ b/core/tests/Drupal/Tests/BrowserTestBase.php
@@ -549,7 +549,7 @@ protected function prepareRequest() {
   /**
    * Retrieves a Drupal path or an absolute path.
    *
-   * @param string $path
+   * @param string|\Drupal\Core\Url $path
    *   Drupal path or URL to load into Mink controlled browser.
    * @param array $options
    *   (optional) Options to be forwarded to the url generator.
@@ -560,9 +560,15 @@ protected function prepareRequest() {
   protected function drupalGet($path, array $options = array()) {
     $options['absolute'] = TRUE;
 
+    if ($path instanceof Url) {
+      $url_options = $path->getOptions();
+      $options = $url_options + $options;
+      $path->setOptions($options);
+      $url = $path->setAbsolute()->toString();
+    }
     // The URL generator service is not necessarily available yet; e.g., in
     // interactive installer tests.
-    if ($this->container->has('url_generator')) {
+    elseif ($this->container->has('url_generator')) {
       if (UrlHelper::isExternal($path)) {
         $url = Url::fromUri($path, $options)->toString();
       }
-- 
GitLab