Skip to content

Commit

Permalink
Merge branch '6.4' into 7.0
Browse files Browse the repository at this point in the history
* 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
  ...
  • Loading branch information
nicolas-grekas committed Aug 1, 2023
2 parents 82a079f + 3f5752f commit 6c93de1
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 6 deletions.
19 changes: 13 additions & 6 deletions AbstractBrowser.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,26 +251,33 @@ public function getRequest(): object

/**
* Clicks on a given link.
*
* @param array $serverParameters An array of server parameters
*/
public function click(Link $link): Crawler
public function click(Link $link/* , array $serverParameters = [] */): Crawler
{
$serverParameters = 1 < \func_num_args() ? func_get_arg(1) : [];

if ($link instanceof Form) {
return $this->submit($link);
return $this->submit($link, [], $serverParameters);
}

return $this->request($link->getMethod(), $link->getUri());
return $this->request($link->getMethod(), $link->getUri(), [], [], $serverParameters);
}

/**
* Clicks the first link (or clickable image) that contains the given text.
*
* @param string $linkText The text of the link or the alt attribute of the clickable image
* @param string $linkText The text of the link or the alt attribute of the clickable image
* @param array $serverParameters An array of server parameters
*/
public function clickLink(string $linkText): Crawler
public function clickLink(string $linkText/* , array $serverParameters = [] */): Crawler
{
$serverParameters = 1 < \func_num_args() ? func_get_arg(1) : [];

$crawler = $this->crawler ?? throw new BadMethodCallException(sprintf('The "request()" method must be called before "%s()".', __METHOD__));

return $this->click($crawler->selectLink($linkText)->link());
return $this->click($crawler->selectLink($linkText)->link(), $serverParameters);
}

/**
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

6.4
---

* Add argument `$serverParameters` to `AbstractBrowser::click()` and `AbstractBrowser::clickLink()`

6.3
---

Expand Down
38 changes: 38 additions & 0 deletions Tests/AbstractBrowserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,19 @@ public function testClick()
$this->assertSame('http://www.example.com/foo', $client->getRequest()->getUri(), '->click() clicks on links');
}

public function testClickPreserveHeaders()
{
$client = $this->getBrowser();
$client->setNextResponse(new Response('<html><a href="/foo">foo</a></html>'));
$crawler = $client->request('GET', 'http://www.example.com/foo/foobar');

$client->click($crawler->filter('a')->link(), ['X-Special-Header' => 'Special Header Value']);

$server = $client->getRequest()->getServer();
$this->assertArrayHasKey('X-Special-Header', $server);
$this->assertSame('Special Header Value', $server['X-Special-Header']);
}

public function testClickLink()
{
$client = $this->getBrowser();
Expand All @@ -299,6 +312,18 @@ public function testClickLinkNotFound()
$client->clickLink('foo');
}

public function testClickLinkPreserveHeaders()
{
$client = $this->getBrowser();
$client->setNextResponse(new Response('<html><a href="/foo">foo</a></html>'));
$client->request('GET', 'http://www.example.com/foo/foobar');
$client->clickLink('foo', ['X-Special-Header' => 'Special Header Value']);

$server = $client->getRequest()->getServer();
$this->assertArrayHasKey('X-Special-Header', $server);
$this->assertSame('Special Header Value', $server['X-Special-Header']);
}

public function testClickForm()
{
$client = $this->getBrowser();
Expand All @@ -310,6 +335,19 @@ public function testClickForm()
$this->assertSame('http://www.example.com/foo', $client->getRequest()->getUri(), '->click() Form submit forms');
}

public function testClickFormPreserveHeaders()
{
$client = $this->getBrowser();
$client->setNextResponse(new Response('<html><form action="/foo"><input type="submit" /></form></html>'));
$crawler = $client->request('GET', 'http://www.example.com/foo/foobar');

$client->click($crawler->filter('input')->form(), ['X-Special-Header' => 'Special Header Value']);

$server = $client->getRequest()->getServer();
$this->assertArrayHasKey('X-Special-Header', $server);
$this->assertSame('Special Header Value', $server['X-Special-Header']);
}

public function testSubmit()
{
$client = $this->getBrowser();
Expand Down

0 comments on commit 6c93de1

Please sign in to comment.