Symfony2 Functional Testing - Click on elements with jQuery interaction
functional-testing, jquery, phpunit, symfony, web-crawler
Solution
Symfony functional tests exercise your code by directly calling the Symfony kernel. They're not run through a web browser and therefore don't support javascript (which is simply not executed).
If it's not possible to run your application without javascript, than you have to use another tool for functional testing. One of the options is to use Mink with one of the drivers supporting javascript (like Selenium2).
Problem
I'm doing some functional tests for an application done with Symfony2 (2.1) and I'm stuck with a problem. I have some parts of the website that load when the user clicks a link or other element, but these actions are performed using jQuery and $.post calls. How can I get the Symfony2 crawler to do these calls? When I do something like this: ``` $link = $crawler->filter('ul.line_menu a')->eq(1)->link(); $crawler = $client->click($link); ``` The crawler gets the "href" of the "a" element and launches it, but the "href" is empty, and a "click()" function is associated with this element, preventing the click action with "preventDefault()". Thank you everyone!! :)