DrupalMinkClient.php in Drupal 8
File
core/tests/Drupal/BuildTests/Framework/DrupalMinkClient.php
View source
<?php
namespace Drupal\BuildTests\Framework;
use Behat\Mink\Driver\Goutte\Client;
use Symfony\Component\BrowserKit\Client as SymfonyClient;
class DrupalMinkClient extends Client {
protected $followMetaRefresh;
public function followMetaRefresh(bool $followMetaRefresh = TRUE) {
$this->followMetaRefresh = $followMetaRefresh;
}
private function getMetaRefreshUrl() {
$metaRefresh = $this
->getCrawler()
->filter('meta[http-equiv="Refresh"], meta[http-equiv="refresh"]');
foreach ($metaRefresh
->extract([
'content',
]) as $content) {
if (preg_match('/^\\s*0\\s*;\\s*URL\\s*=\\s*(?|\'([^\']++)|"([^"]++)|([^\'"].*))/i', $content, $m)) {
return str_replace("\t\r\n", '', rtrim($m[1]));
}
}
return NULL;
}
public function request($method, $uri, array $parameters = [], array $files = [], array $server = [], $content = NULL, $changeHistory = TRUE) {
$this->crawler = parent::request($method, $uri, $parameters, $files, $server, $content, $changeHistory);
if ($this->followMetaRefresh && NULL !== ($redirect = $this
->getMetaRefreshUrl())) {
$this->redirect = $redirect;
$ref_redirects = new \ReflectionProperty(SymfonyClient::class, 'redirects');
$ref_redirects
->setAccessible(TRUE);
$redirects = $ref_redirects
->getValue($this);
$redirects[serialize($this->history
->current())] = TRUE;
$ref_redirects
->setValue($this, $redirects);
$this->crawler = $this
->followRedirect();
}
return $this->crawler;
}
}