Issue #2719701 by jhedstrom: BrowserTestBase::drupalGet() incompatible with WebTestBase::drupalGet()

8.2.x
Alex Pott 2016-05-08 11:04:52 -05:00
parent ffcbce2ccc
commit 8f138ab1a6
2 changed files with 17 additions and 2 deletions

View File

@ -2,6 +2,7 @@
namespace Drupal\Tests\simpletest\Functional;
use Drupal\Core\Url;
use Drupal\Tests\BrowserTestBase;
/**
@ -31,6 +32,14 @@ class BrowserTestBaseTest extends BrowserTestBase {
// 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');
}
/**

View File

@ -549,7 +549,7 @@ abstract class BrowserTestBase extends \PHPUnit_Framework_TestCase {
/**
* 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 @@ abstract class BrowserTestBase extends \PHPUnit_Framework_TestCase {
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();
}