1<?php
2
3/*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
13use Symfony\Component\DomCrawler\Crawler;
14
15class TemplateAnnotationTest extends WebTestCase
16{
17    /**
18     * @dataProvider urlProvider
19     */
20    public function testController($url, $checkHtml)
21    {
22        $client = self::createClient();
23        $crawler = $client->request('GET', $url);
24
25        $this->assertEquals($checkHtml, $crawler->filterXPath('//body')->html());
26    }
27
28    public static function urlProvider()
29    {
30        return array(
31            array('/multi/one-template/1/', 'bar'),
32            array('/multi/one-template/2/', 'bar'),
33            array('/multi/one-template/3/', 'bar'),
34            array('/multi/one-template/4/', 'foo bar baz'),
35            array('/invokable/predefined/service/', 'bar'),
36            array('/invokable/class-level/service/', 'bar'),
37            array('/simple/multiple/', 'a, b, c'),
38            array('/simple/multiple/henk/bar/', 'henk, bar, c'),
39            array('/simple/multiple-with-vars/', 'a, b'),
40            array('/invokable/predefined/container/', 'bar'),
41            array('/invokable/variable/container/the-var/', 'the-var'),
42            array('/invokable/another-variable/container/another-var/', 'another-var'),
43            array('/invokable/variable/container/the-var/another-var/', 'the-var,another-var'),
44            array('/no-listener/', 'I did not get rendered via twig'),
45        );
46    }
47
48    public function testStreamedControllerResponse()
49    {
50        $uri = '/streamed/';
51
52        ob_start();
53        $client = self::createClient();
54        $client->request('GET', $uri);
55
56        $crawler = new Crawler(null, $uri);
57        $crawler->addContent(ob_get_clean());
58
59        $this->assertEquals('foo, bar', $crawler->filterXPath('//body')->html());
60    }
61}
62