Skip to content

Commit 44149f5

Browse files
committed
Merge branch '2.2'
2 parents ad9a61a + d3120ca commit 44149f5

File tree

7 files changed

+117
-4
lines changed

7 files changed

+117
-4
lines changed

src/Codeception/Module/PhpBrowser.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,8 @@ public function _backupSession()
269269
return [
270270
'client' => $this->client,
271271
'guzzle' => $this->guzzle,
272-
'crawler' => $this->crawler
272+
'crawler' => $this->crawler,
273+
'headers' => $this->headers,
273274
];
274275
}
275276

tests/data/app/controllers.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,4 +258,15 @@ class jserroronload {
258258
function GET() {
259259
include __DIR__.'/view/jserroronload.php';
260260
}
261-
}
261+
}
262+
263+
class userAgent {
264+
function GET() {
265+
echo $_SERVER['HTTP_USER_AGENT'];
266+
}
267+
}
268+
class minimal {
269+
function GET() {
270+
include __DIR__.'/view/minimal.php';
271+
}
272+
}

tests/data/app/index.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
'/somepath/info' => 'info',
3838
'/facebook\??.*' => 'facebookController',
3939
'/form/(.*?)(#|\?.*?)?' => 'form',
40+
'/user-agent' => 'userAgent',
4041
'/articles\??.*' => 'articles',
4142
'/auth' => 'httpAuth',
4243
'/register' => 'register',
@@ -46,7 +47,8 @@
4647
'/external_url' => 'external_url',
4748
'/iframe' => 'iframe',
4849
'/basehref' => 'basehref',
49-
'/jserroronload' => 'jserroronload'
50+
'/jserroronload' => 'jserroronload',
51+
'/minimal' => 'minimal',
5052
);
5153

5254
glue::stick($urls);

tests/data/app/view/minimal.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>
5+
Minimal page
6+
</title>
7+
</head>
8+
<body>
9+
<h1>
10+
Minimal page
11+
</h1>
12+
</body>
13+
</html>

tests/unit/Codeception/Module/PhpBrowserRestTest.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<?php
22

3+
use Codeception\Test\Unit;
34
use Codeception\Util\Stub as Stub;
45

5-
class PhpBrowserRestTest extends \PHPUnit_Framework_TestCase
6+
class PhpBrowserRestTest extends Unit
67
{
78
/**
89
* @var \Codeception\Module\REST
@@ -272,6 +273,31 @@ public function testHostHeader()
272273
$this->module->seeResponseContains('host: "www.example.com"');
273274
}
274275

276+
/**
277+
* @Issue 4203 https://github.com/Codeception/Codeception/issues/4203
278+
* @depends testHostHeader
279+
*/
280+
public function testSessionHeaderBackup()
281+
{
282+
if (getenv('dependencies') === 'lowest') {
283+
$this->markTestSkipped('This test can\'t pass with the lowest versions of dependencies');
284+
}
285+
286+
$this->module->haveHttpHeader('Host', 'www.example.com');
287+
$this->module->sendGET('/rest/http-host/');
288+
$this->module->seeResponseContains('host: "www.example.com"');
289+
290+
$session = $this->phpBrowser->_backupSession();
291+
292+
$this->module->haveHttpHeader('Host', 'www.localhost.com');
293+
$this->module->sendGET('/rest/http-host/');
294+
$this->module->seeResponseContains('host: "www.localhost.com"');
295+
296+
$this->phpBrowser->_loadSession($session);
297+
$this->module->sendGET('/rest/http-host/');
298+
$this->module->seeResponseContains('host: "www.example.com"');
299+
}
300+
275301
protected function shouldFail()
276302
{
277303
$this->setExpectedException('PHPUnit_Framework_AssertionFailedError');

tests/unit/Codeception/Module/PhpBrowserTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,4 +641,38 @@ public function testFillFieldInGetFormWithoutId()
641641
$this->assertEquals('two', $params['select_name']);
642642
$this->assertEquals('searchterm', $params['search_name']);
643643
}
644+
645+
public function testGrabPageSourceWhenNotOnPage()
646+
{
647+
$this->setExpectedException(
648+
'\Codeception\Exception\ModuleException',
649+
'Page not loaded. Use `$I->amOnPage` (or hidden API methods `_request` and `_loadPage`) to open it'
650+
);
651+
$this->module->grabPageSource();
652+
}
653+
654+
public function testGrabPageSourceWhenOnPage()
655+
{
656+
$this->module->amOnPage('/minimal');
657+
$sourceExpected =
658+
<<<HTML
659+
<!DOCTYPE html>
660+
<html>
661+
<head>
662+
<title>
663+
Minimal page
664+
</title>
665+
</head>
666+
<body>
667+
<h1>
668+
Minimal page
669+
</h1>
670+
</body>
671+
</html>
672+
673+
HTML
674+
;
675+
$sourceActual = $this->module->grabPageSource();
676+
$this->assertXmlStringEqualsXmlString($sourceExpected, $sourceActual);
677+
}
644678
}

tests/unit/Codeception/Module/TestsForWeb.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,22 @@ public function testDontSeeLinkFailsIfTextAndUrlMatches()
166166
$this->module->dontSeeLink('Next', 'http://codeception.com/');
167167
}
168168

169+
public function testSeeLinkMatchesRelativeLink()
170+
{
171+
$this->module->amOnPage('/info');
172+
$this->module->seeLink('Sign in!', '/login');
173+
}
174+
175+
public function testDontSeeLinkMatchesRelativeLink()
176+
{
177+
$this->setExpectedException(
178+
'PHPUnit_Framework_AssertionFailedError',
179+
"Link containing text 'Sign in!' and URL '/login' was found in page /info"
180+
);
181+
$this->module->amOnPage('/info');
182+
$this->module->dontSeeLink('Sign in!', '/login');
183+
}
184+
169185
public function testClick()
170186
{
171187
$this->module->amOnPage('/');
@@ -1623,4 +1639,14 @@ public function testSubmittingRelativeFormHonoursBaseHref()
16231639
$this->module->click('Relative Form');
16241640
$this->module->seeCurrentUrlEquals('/form/example5');
16251641
}
1642+
1643+
public function testAttachFileThrowsCorrectMessageWhenFileDoesNotExist()
1644+
{
1645+
$filename = 'does-not-exist.jpg';
1646+
$expectedMessage = 'File does not exist: ' . codecept_data_dir($filename);
1647+
$this->setExpectedException('InvalidArgumentException', $expectedMessage);
1648+
1649+
$this->module->amOnPage('/form/file');
1650+
$this->module->attachFile('Avatar', $filename);
1651+
}
16261652
}

0 commit comments

Comments
 (0)