Skip to content

Commit c9093a8

Browse files
committed
Implemented changes suggested by Wouter
1 parent e7056a8 commit c9093a8

File tree

1 file changed

+30
-35
lines changed

1 file changed

+30
-35
lines changed

components/browser_kit/introduction.rst

Lines changed: 30 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,9 @@ requested URL::
6262
$crawler = $client->request('GET', 'http://symfony.com');
6363

6464
The value returned by the ``request()`` method is an instance of the
65-
:class:`Symfony\\Component\\DomCrawler\\Crawler` class, which allows accessing
66-
and traversing HTML elements programmatically.
65+
:class:`Symfony\\Component\\DomCrawler\\Crawler` class, provided by the
66+
:doc:`DomCrawler component </components/dom_crawler>`_, and which allows
67+
accessing and traversing HTML elements programmatically.
6768

6869
Clicking Links
6970
~~~~~~~~~~~~~~
@@ -83,10 +84,12 @@ the needed HTTP GET request to simulate the link click::
8384
Submitting Forms
8485
~~~~~~~~~~~~~~~~
8586

86-
The ``Crawler`` object is also capable of simulating form submissions. First,
87-
select the form via any of its buttons (thanks to the ``selectButton()`` and
88-
``form()`` methods). Then, fill in the form data to send and use the ``submit()``
89-
method to make the needed HTTP POST request to submit the form::
87+
The ``Crawler`` object is also capable of selecting forms. First, select any of
88+
the form's buttons with the ``selectButton()`` method. Then, use the ``form()``
89+
method to select the form which the button belongs to.
90+
91+
After selecting the form, fill in its data and send it using the ``submit()``
92+
method (which makes the needed HTTP POST request to submit the form contents)::
9093

9194
use Acme\Client;
9295

@@ -125,17 +128,18 @@ retrieve any cookie while making requests with the client::
125128
$cookie = $cookieJar->get('name_of_the_cookie');
126129

127130
// Get cookie data
128-
$name = $cookie->getName();
129-
$value = $cookie->getValue();
130-
$raw = $cookie->getRawValue();
131-
$secure = $cookie->isSecure();
131+
$name = $cookie->getName();
132+
$value = $cookie->getValue();
133+
$raw = $cookie->getRawValue();
134+
$secure = $cookie->isSecure();
132135
$isHttpOnly = $cookie->isHttpOnly();
133-
$isExpired = $cookie->isExpired();
134-
$expires = $cookie->getExpiresTime();
135-
$path = $cookie->getPath();
136-
$domain = $cookie->getDomain();
136+
$isExpired = $cookie->isExpired();
137+
$expires = $cookie->getExpiresTime();
138+
$path = $cookie->getPath();
139+
$domain = $cookie->getDomain();
137140

138141
.. note::
142+
139143
These methods only return cookies that have not expired.
140144

141145
Looping Through Cookies
@@ -154,22 +158,19 @@ Looping Through Cookies
154158
155159
// Get array with all cookies
156160
$cookies = $cookieJar->all();
157-
foreach($cookies as $cookie)
158-
{
161+
foreach ($cookies as $cookie) {
159162
// ...
160163
}
161164
162165
// Get all values
163166
$values = $cookieJar->allValues('http://symfony.com');
164-
foreach($values as $value)
165-
{
167+
foreach ($values as $value) {
166168
// ...
167169
}
168170
169171
// Get all raw values
170172
$rawValues = $cookieJar->allRawValues('http://symfony.com');
171-
foreach($rawValues as $rawValue)
172-
{
173+
foreach ($rawValues as $rawValue) {
173174
// ...
174175
}
175176
@@ -182,13 +183,7 @@ into the client constructor::
182183
use Acme\Client;
183184

184185
// create cookies and add to cookie jar
185-
$expires = new \DateTime();
186-
$expires->add(new \DateInterval('P1D'));
187-
$cookie = new Cookie(
188-
'flavor',
189-
'chocolate chip',
190-
$now->getTimestamp()
191-
);
186+
$cookieJar = new Cookie('flavor', 'chocolate', strtotime('+1 day'));
192187

193188
// create a client and set the cookies
194189
$client = new Client(array(), array(), $cookieJar);
@@ -204,17 +199,17 @@ history::
204199

205200
// make a real request to an external site
206201
$client = new Client();
207-
$home_crawler = $client->request('GET', 'http://symfony.com');
202+
$client->request('GET', 'http://symfony.com');
208203

209204
// select and click on a link
210-
$doc_link = $crawler->selectLink('Documentation')->link();
211-
$doc_crawler = $client->click($link);
205+
$link = $crawler->selectLink('Documentation')->link();
206+
$client->click($link);
212207

213208
// go back to home page
214-
$home_crawler = $client->back();
209+
$crawler = $client->back();
215210

216211
// go forward to documentation page
217-
$doc_crawler = $client->forward();
212+
$crawler = $client->forward();
218213

219214
You can delete the client's history with the ``restart()`` method. This will
220215
also delete all the cookies::
@@ -223,10 +218,10 @@ also delete all the cookies::
223218

224219
// make a real request to an external site
225220
$client = new Client();
226-
$home_crawler = $client->request('GET', 'http://symfony.com');
221+
$client->request('GET', 'http://symfony.com');
227222

228223
// delete history
229224
$client->restart();
230225

231-
.. _Packagist: https://packagist.org/packages/symfony/browser-kit
232-
.. _Goutte: https://github.com/fabpot/Goutte
226+
.. _`Packagist`: https://packagist.org/packages/symfony/browser-kit
227+
.. _`Goutte`: https://github.com/fabpot/Goutte

0 commit comments

Comments
 (0)