Skip to content
This repository was archived by the owner on Aug 16, 2021. It is now read-only.

Commit b4f9815

Browse files
author
Greg Heitz
committed
Add tests setHeaders and redirectUrl
1 parent 6e012d2 commit b4f9815

File tree

2 files changed

+61
-14
lines changed

2 files changed

+61
-14
lines changed

src/BrowserMob.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,15 @@ public function closeProxy()
135135
$this->_close();
136136
}
137137

138-
public function startHar()
138+
public function startHar($label = '')
139139
{
140-
$this->_newHar();
140+
$this->_newHar($label);
141141
return $this->response->success;
142142
}
143143

144-
public function addPage()
144+
public function addPage($label = '')
145145
{
146-
$this->_newPage();
146+
$this->_newPage($label);
147147
return $this->response->success;
148148
}
149149

tests/functional/BrowserMobProxyCest.php

Lines changed: 57 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,22 @@ public function initProxy(FunctionalTester $I)
1414
$I->assertInstanceOf('Codeception\Extension\BrowserMob', $module);
1515
}
1616

17+
/**
18+
* @env autostart
19+
* @env blacklist
20+
* @env whitelist
21+
* @env limits
22+
* @env timeouts
23+
*/
24+
public function parameters(FunctionalTester $I)
25+
{
26+
$port = $I->getProxyPort();
27+
$I->assertNotNull($port);
28+
$I->closeProxy();
29+
$port = $I->getProxyPort();
30+
//$I->assertNotNull($port); // BrowserMobProxy_Client issue
31+
}
32+
1733
/**
1834
* @covers ::openProxy
1935
* @covers ::startHar
@@ -38,18 +54,49 @@ public function captureHar(FunctionalTester $I)
3854
}
3955

4056
/**
41-
* @env autostart
42-
* @env blacklist
43-
* @env whitelist
44-
* @env limits
45-
* @env timeouts
57+
* @covers ::openProxy
58+
* @covers ::startHar
59+
* @covers ::addPage
60+
* @covers ::getHar
4661
*/
47-
public function parameters(FunctionalTester $I)
62+
public function captureHarWithPage(FunctionalTester $I)
4863
{
49-
$port = $I->getProxyPort();
50-
$I->assertNotNull($port);
64+
$port = $I->openProxy();
65+
$I->assertNotNull($port, "`${port}` is not a valid port");
66+
$I->startHar('codeception');
67+
Requests::get('http://codeception.com/', [], ['proxy' => "127.0.0.1:${port}"]);
68+
$rep = $I->addPage('github');
69+
$I->assertTrue($rep);
70+
Requests::get('http://github.com/', [], ['proxy' => "127.0.0.1:${port}"]);
71+
$har = $I->getHar();
72+
$I->assertEquals('BrowserMob Proxy', $har['log']['creator']['name']);
73+
$I->assertNotEmpty($har['log']['entries']);
74+
$I->assertEquals('github', $har['log']['entries'][1]['pageref']);
75+
$I->closeProxy();
76+
}
77+
78+
public function setHeaders(FunctionalTester $I)
79+
{
80+
$port = $I->openProxy();
81+
$I->assertNotNull($port, "`${port}` is not a valid port");
82+
$rep = $I->setHeaders(['User-Agent' => 'BrowserMob-Agent']);
83+
$I->assertTrue($rep);
84+
$I->startHar('codeception');
85+
Requests::get('http://codeception.com/', [], ['proxy' => "127.0.0.1:${port}"]);
86+
$I->getHar();
87+
$I->closeProxy();
88+
}
89+
90+
public function redirectUrl(FunctionalTester $I)
91+
{
92+
$port = $I->openProxy();
93+
$I->assertNotNull($port, "`${port}` is not a valid port");
94+
$rep = $I->redirectUrl('http://testdomain.url/', 'http://codeception.com/');
95+
$I->assertTrue($rep);
96+
$I->startHar('codeception');
97+
Requests::get('http://testdomain.url/', [], ['proxy' => "127.0.0.1:${port}"]);
98+
$har = $I->getHar();
99+
$I->assertEquals('http://codeception.com/', $har['log']['entries'][0]['request']['url']);
51100
$I->closeProxy();
52-
$port = $I->getProxyPort();
53-
//$I->assertNotNull($port); // BrowserMobProxy_Client issue
54101
}
55102
}

0 commit comments

Comments
 (0)