$this->
assertEquals([],
$this->
createTestCrawler()->
filterXPath('//ol'
)->
links(), '->links() returns an empty array if the node selection is empty'
);
} public function testForm() { $testCrawler =
$this->
createTestCrawler('http://example.com/bar/'
);
$crawler =
$testCrawler->
selectButton('FooValue'
);
$crawler2 =
$testCrawler->
selectButton('FooBarValue'
);
$this->
assertInstanceOf(Form::
class,
$crawler->
form(), '->form() returns a Form instance'
);
$this->
assertInstanceOf(Form::
class,
$crawler2->
form(), '->form() returns a Form instance'
);
$this->
assertEquals($crawler->
form()->
getFormNode()->
getAttribute('id'
),
$crawler2->
form()->
getFormNode()->
getAttribute('id'
), '->form() works on elements with form attribute'
);
$this->
assertEquals(['FooName' => 'FooBar', 'TextName' => 'TextValue', 'FooTextName' => 'FooTextValue'
],
$crawler->
form(['FooName' => 'FooBar'
])->
getValues(), '->form() takes an array of values to submit as its first argument'
);
$this->
assertEquals(['FooName' => 'FooValue', 'TextName' => 'TextValue', 'FooTextName' => 'FooTextValue'
],
$crawler->
form()->
getValues(), '->getValues() returns correct form values'
);
$this->
assertEquals(['FooBarName' => 'FooBarValue', 'TextName' => 'TextValue', 'FooTextName' => 'FooTextValue'
],
$crawler2->
form()->
getValues(), '->getValues() returns correct form values'
);
try { $this->
createTestCrawler()->
filterXPath('//ol'
)->
form();
$this->
fail('->form() throws an \InvalidArgumentException if the node list is empty'
);
} catch (\InvalidArgumentException
$e) { $this->
assertTrue(true, '->form() throws an \InvalidArgumentException if the node list is empty'
);
} }