0


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

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.