Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.


I don't find a way to add "button" or "input" fields to a form to the crawler in Symfony for testing. I'm doing this :

$crawler = $this->client->request('GET', '');
$document = new \DOMDocument();
$document->loadXml('<button type="submit" name="_submit" href="#">Create</button >');
$nodeList = $document->getElementsByTagName('button');
$node = $document->getElementsByTagName('button')->item(0);
$crawler->addNode($node, $form);
var_dump($crawler->filter('button[name="_submit"]')->text()); //Return Create Logic

But when i try to send my form i've got :

$form = $crawler->selectButton('_submit')->form(array(
                                                'login-input' => 'XXXXXX',
                                                'pass-input'  => 'XXXXX',
                                            ));

This doesn't work i've got :

LogicException: The selected node does not have a form ancestor.

I don't have any button or input fields because it's a javascript submit.
Someone have any idea ?


EDIT
I've found an another way: I send directly ajax request, and i've got the same effect @redbirdo, your solution doesn't work for me, and isn't what i want at the start of my question

share|improve this question
add comment

1 Answer

You can simulate a POST request in a test using the client like this:

$client->request(
    'POST',
    '/submit',
    array('name' => 'Fabien'),
    array('photo' => $photo)
);

There are more examples under Working with the Test Client in the Testing section of the Symfony manual.

EDIT:

The second parameter should be the relative or absolute url of the page being tested. The '/submit' here is just a symfony example.

share|improve this answer
 
I've tried this : '$this->client->request('POST', '/submit', array('login-input' => 'XXXXX', 'pass-input' => 'XxXX'));' but doesn't work, i've got an 404 error page –  Babou34090 Jun 5 '13 at 9:39
 
@babou see edit. –  redbirdo Jun 5 '13 at 13:31
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.