Skip to content

Commit d43715a

Browse files
committed
merged with origin/master
1 parent 0f44ba6 commit d43715a

File tree

7 files changed

+42
-17
lines changed

7 files changed

+42
-17
lines changed

src/Codeception/Lib/Connector/Guzzle.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,15 @@ protected function createResponse(Response $response)
117117
$matches = [];
118118

119119
$matchesMeta = preg_match(
120-
'/\<meta[^\>]+http-equiv="refresh" content="(\d*)\s*;?\s*url=(.*?)"/i',
120+
'/\<meta[^\>]+http-equiv="refresh" content="\s*(\d*)\s*;\s*url=(.*?)"/i',
121121
$response->getBody(true),
122122
$matches
123123
);
124124

125125
if (!$matchesMeta) {
126126
// match by header
127127
preg_match(
128-
'~(\d*);?url=(.*)~',
128+
'/^\s*(\d*)\s*;\s*url=(.*)/i',
129129
(string)$response->getHeader('Refresh'),
130130
$matches
131131
);

src/Codeception/Module/PhpBrowser.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<?php
22
namespace Codeception\Module;
33

4+
use Codeception\Exception\ModuleConfigException;
45
use Codeception\Exception\ModuleException;
6+
use Codeception\Lib\Connector\Guzzle6;
57
use Codeception\Lib\InnerBrowser;
68
use Codeception\Lib\Interfaces\MultiSession;
79
use Codeception\Lib\Interfaces\Remote;
@@ -29,6 +31,8 @@
2931
* ## Configuration
3032
*
3133
* * url *required* - start url of your app
34+
* * handler (default: curl) - Guzzle handler to use. By default curl is used, also possible to pass `stream`, or any valid class name as [Handler](http://docs.guzzlephp.org/en/latest/handlers-and-middleware.html#handlers).
35+
* * middleware - Guzzle middlewares to add. An array of valid callables is required.
3236
* * curl - curl options
3337
* * headers - ...
3438
* * cookies - ...
@@ -85,11 +89,13 @@ class PhpBrowser extends InnerBrowser implements Remote, MultiSession
8589
'timeout' => 30,
8690
'curl' => [],
8791
'refresh_max_interval' => 10,
92+
'handler' => 'curl',
93+
'middleware' => null,
8894

8995
// required defaults (not recommended to change)
9096
'allow_redirects' => false,
9197
'http_errors' => false,
92-
'cookies' => true
98+
'cookies' => true,
9399
];
94100

95101
protected $guzzleConfigFields = [
@@ -233,6 +239,13 @@ public function _initializeSession()
233239
if ($this->isGuzzlePsr7) {
234240
$defaults['base_uri'] = $this->config['url'];
235241
$defaults['curl'] = $curlOptions;
242+
$handler = Guzzle6::createHandler($this->config['handler']);
243+
if ($handler && is_array($this->config['middleware'])) {
244+
foreach ($this->config['middleware'] as $middleware) {
245+
$handler->push($middleware);
246+
}
247+
}
248+
$defaults['handler'] = $handler;
236249
$this->guzzle = new GuzzleClient($defaults);
237250
} else {
238251
$defaults['config']['curl'] = $curlOptions;

tests/data/app/controllers.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ function GET() {
6666
}
6767
}
6868

69-
class redirect_self {
69+
class redirect_meta_refresh {
7070
function GET() {
71-
include __DIR__.'/view/redirect_self.php';
71+
include __DIR__.'/view/redirect_meta_refresh.php';
7272
}
7373
}
7474

tests/data/app/index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
'/redirect_params' => 'redirect_params',
2727
'/redirect_interval' => 'redirect_interval',
2828
'/redirect_header_interval' => 'redirect_header_interval',
29-
'/redirect_self' => 'redirect_self',
29+
'/redirect_meta_refresh' => 'redirect_meta_refresh',
3030
'/relative_redirect' => 'redirect_relative',
3131
'/relative/redirect' => 'redirect_relative',
3232
'/redirect_twice' => 'redirect_twice',
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<html>
2+
<head>
3+
<meta http-equiv="refresh" content="9; url=/info" />
4+
</head>
5+
<body>
6+
<h1>Meta redirect</h1>
7+
</body>
8+
</html>

tests/data/app/view/redirect_self.php

Lines changed: 0 additions & 8 deletions
This file was deleted.

tests/unit/Codeception/Module/PhpBrowserTest.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,23 @@ public function testHtmlRedirectWithParams()
120120
$this->module->seeResponseCodeIs(200);
121121
$this->module->seeCurrentUrlEquals('/search?one=1&two=2');
122122
}
123-
123+
124124
public function testMetaRefresh()
125125
{
126-
$this->module->amOnPage('/redirect_self');
127-
$this->module->see('Redirecting to myself');
126+
$this->module->amOnPage('/redirect_meta_refresh');
127+
$this->module->seeResponseCodeIs(200);
128+
$this->module->seeCurrentUrlEquals('/info');
129+
}
130+
131+
public function testMetaRefreshIsIgnoredIfIntervalIsLongerThanMaxInterval()
132+
{
133+
// prepare config
134+
$config = $this->module->_getConfig();
135+
$config['refresh_max_interval'] = 3; // less than 9
136+
$this->module->_reconfigure($config);
137+
$this->module->amOnPage('/redirect_meta_refresh');
138+
$this->module->seeResponseCodeIs(200);
139+
$this->module->seeCurrentUrlEquals('/redirect_meta_refresh');
128140
}
129141

130142
public function testRefreshRedirect()

0 commit comments

Comments
 (0)