Skip to content

Commit 6c93de1

Browse files
Merge branch '6.4' into 7.0
* 6.4: (31 commits) [HttpKernel] Strip exception file paths from log messages [Validator] Add ability to validate time without seconds [Process] Fix test case [Process] Support finding executables independently of open_basedir [Mime] Update mimetypes Add some PHPDoc [Workflow] Add a profiler [Form] Removing self-closing slash from `<input>` [FrameworkBundle][Serializer] Add TranslatableNormalizer [Uid] Fix example [HttpKernel] Add `reset()` implementation in DataCollector [Uid] Add more PHP doc to "export" functions [HttpKernel] RequestPayloadValueResolver Add support for custom http status code [Serializer] Add support for seld/jsonlint in order to enhance error messages [Workflow] fix MermaidDumper when place contains special char [Translation] Phrase translation provider [Workflow] Add support for storing the marking in a property [Crawler] Fix regression where cdata nodes will return empty string [Scheduler] make `ScheduledStamp` "send-able" [Serializer] Groups annotation/attribute on class ...
2 parents 82a079f + 3f5752f commit 6c93de1

File tree

3 files changed

+56
-6
lines changed

3 files changed

+56
-6
lines changed

AbstractBrowser.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -251,26 +251,33 @@ public function getRequest(): object
251251

252252
/**
253253
* Clicks on a given link.
254+
*
255+
* @param array $serverParameters An array of server parameters
254256
*/
255-
public function click(Link $link): Crawler
257+
public function click(Link $link/* , array $serverParameters = [] */): Crawler
256258
{
259+
$serverParameters = 1 < \func_num_args() ? func_get_arg(1) : [];
260+
257261
if ($link instanceof Form) {
258-
return $this->submit($link);
262+
return $this->submit($link, [], $serverParameters);
259263
}
260264

261-
return $this->request($link->getMethod(), $link->getUri());
265+
return $this->request($link->getMethod(), $link->getUri(), [], [], $serverParameters);
262266
}
263267

264268
/**
265269
* Clicks the first link (or clickable image) that contains the given text.
266270
*
267-
* @param string $linkText The text of the link or the alt attribute of the clickable image
271+
* @param string $linkText The text of the link or the alt attribute of the clickable image
272+
* @param array $serverParameters An array of server parameters
268273
*/
269-
public function clickLink(string $linkText): Crawler
274+
public function clickLink(string $linkText/* , array $serverParameters = [] */): Crawler
270275
{
276+
$serverParameters = 1 < \func_num_args() ? func_get_arg(1) : [];
277+
271278
$crawler = $this->crawler ?? throw new BadMethodCallException(sprintf('The "request()" method must be called before "%s()".', __METHOD__));
272279

273-
return $this->click($crawler->selectLink($linkText)->link());
280+
return $this->click($crawler->selectLink($linkText)->link(), $serverParameters);
274281
}
275282

276283
/**

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
6.4
5+
---
6+
7+
* Add argument `$serverParameters` to `AbstractBrowser::click()` and `AbstractBrowser::clickLink()`
8+
49
6.3
510
---
611

Tests/AbstractBrowserTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,19 @@ public function testClick()
279279
$this->assertSame('http://www.example.com/foo', $client->getRequest()->getUri(), '->click() clicks on links');
280280
}
281281

282+
public function testClickPreserveHeaders()
283+
{
284+
$client = $this->getBrowser();
285+
$client->setNextResponse(new Response('<html><a href="/foo">foo</a></html>'));
286+
$crawler = $client->request('GET', 'http://www.example.com/foo/foobar');
287+
288+
$client->click($crawler->filter('a')->link(), ['X-Special-Header' => 'Special Header Value']);
289+
290+
$server = $client->getRequest()->getServer();
291+
$this->assertArrayHasKey('X-Special-Header', $server);
292+
$this->assertSame('Special Header Value', $server['X-Special-Header']);
293+
}
294+
282295
public function testClickLink()
283296
{
284297
$client = $this->getBrowser();
@@ -299,6 +312,18 @@ public function testClickLinkNotFound()
299312
$client->clickLink('foo');
300313
}
301314

315+
public function testClickLinkPreserveHeaders()
316+
{
317+
$client = $this->getBrowser();
318+
$client->setNextResponse(new Response('<html><a href="/foo">foo</a></html>'));
319+
$client->request('GET', 'http://www.example.com/foo/foobar');
320+
$client->clickLink('foo', ['X-Special-Header' => 'Special Header Value']);
321+
322+
$server = $client->getRequest()->getServer();
323+
$this->assertArrayHasKey('X-Special-Header', $server);
324+
$this->assertSame('Special Header Value', $server['X-Special-Header']);
325+
}
326+
302327
public function testClickForm()
303328
{
304329
$client = $this->getBrowser();
@@ -310,6 +335,19 @@ public function testClickForm()
310335
$this->assertSame('http://www.example.com/foo', $client->getRequest()->getUri(), '->click() Form submit forms');
311336
}
312337

338+
public function testClickFormPreserveHeaders()
339+
{
340+
$client = $this->getBrowser();
341+
$client->setNextResponse(new Response('<html><form action="/foo"><input type="submit" /></form></html>'));
342+
$crawler = $client->request('GET', 'http://www.example.com/foo/foobar');
343+
344+
$client->click($crawler->filter('input')->form(), ['X-Special-Header' => 'Special Header Value']);
345+
346+
$server = $client->getRequest()->getServer();
347+
$this->assertArrayHasKey('X-Special-Header', $server);
348+
$this->assertSame('Special Header Value', $server['X-Special-Header']);
349+
}
350+
313351
public function testSubmit()
314352
{
315353
$client = $this->getBrowser();

0 commit comments

Comments
 (0)