request('GET', '/en/blog/'); $this->assertCount( Post::NUM_ITEMS, $crawler->filter('article.post'), 'The homepage displays the right number of posts.' ); } public function testRss() { $client = static::createClient(); $crawler = $client->request('GET', '/en/blog/rss.xml'); $this->assertSame( 'text/xml; charset=UTF-8', $client->getResponse()->headers->get('Content-Type') ); $this->assertCount( Post::NUM_ITEMS, $crawler->filter('item'), 'The xml file displays the right number of posts.' ); } /** * This test changes the database contents by creating a new comment. However, * thanks to the DAMADoctrineTestBundle and its PHPUnit listener, all changes * to the database are rolled back when this test completes. This means that * all the application tests begin with the same database contents. */ public function testNewComment() { $client = static::createClient([], [ 'PHP_AUTH_USER' => 'john_user', 'PHP_AUTH_PW' => 'kitten', ]); $client->followRedirects(); // Find first blog post $crawler = $client->request('GET', '/en/blog/'); $postLink = $crawler->filter('article.post > h2 a')->link(); $crawler = $client->click($postLink); $form = $crawler->selectButton('Publish comment')->form([ 'comment[content]' => 'Hi, Symfony!', ]); $crawler = $client->submit($form); $newComment = $crawler->filter('.post-comment')->first()->filter('div > p')->text(); $this->assertSame('Hi, Symfony!', $newComment); } public function testAjaxSearch() { $client = static::createClient(); $client->xmlHttpRequest('GET', '/en/blog/search', ['q' => 'lorem']); $results = json_decode($client->getResponse()->getContent(), true); $this->assertSame('application/json', $client->getResponse()->headers->get('Content-Type')); $this->assertCount(1, $results); $this->assertSame('Lorem ipsum dolor sit amet consectetur adipiscing elit', $results[0]['title']); $this->assertSame('Jane Doe', $results[0]['author']); } }