LayoutsListenerTest::testHostLayout()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
/*
4
* This file is part of the OrbitaleCmsBundle package.
5
*
6
* (c) Alexandre Rock Ancelet <[email protected]>
7
*
8
* For the full copyright and license information, please view the LICENSE
9
* file that was distributed with this source code.
10
*/
11
12
namespace Orbitale\Bundle\CmsBundle\Tests\EventListener;
13
14
use Doctrine\ORM\EntityManager;
15
use Orbitale\Bundle\CmsBundle\Tests\Fixtures\AbstractTestCase;
16
use Orbitale\Bundle\CmsBundle\Tests\Fixtures\TestBundle\Entity\Page;
17
18
class LayoutsListenerTest extends AbstractTestCase
19
{
20
    public function testDifferentLayout()
21
    {
22
        $client = static::createClient(['environment' => 'layout']);
23
24
        /** @var \Twig_Environment $twig */
25
        $twig = $client->getContainer()->get('twig');
26
        $twig->resolveTemplate('test_layout.html.twig');
27
28
        $crawler = $client->request('GET', '/page/');
29
30
        static::assertEquals(1, $crawler->filter('#test_layout_wrapper')->count());
31
        static::assertRegExp('~^One change of the layout is this special hardcoded title\. ~', $crawler->filter('title')->html());
32
    }
33
34
    public function testHostLayout()
35
    {
36
        $client = static::createClient(['environment' => 'layout'], ['HTTP_HOST' => 'local.host']);
37
38
        $crawler = $client->request('GET', '/page/');
39
40
        static::assertRegExp('~^This layout is only for local\.host\. ~', $crawler->filter('title')->html());
41
    }
42
43
    /**
44
     * @expectedException \Twig_Error_Loader
45
     * @expectedExceptionMessage Unable to find template this_layout_does_not_exist.html.twig for layout front. The "layout" parameter must be a valid twig view to be used as a layout.
46
     */
47
    public function testLayoutWrong()
48
    {
49
        static::createClient(['environment' => 'layout_wrong'])->request('GET', '/page/');
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55
    protected static function createClient(array $options = [], array $server = [])
56
    {
57
        $client = parent::createClient($options, $server);
58
59
        $homepage = new Page();
60
        $homepage
61
            ->setHomepage(true)
62
            ->setEnabled(true)
63
            ->setSlug('home')
64
            ->setTitle('My homepage')
65
            ->setContent('Hello world!')
66
        ;
67
68
        /** @var EntityManager $em */
69
        $em = $client->getKernel()->getContainer()->get('doctrine')->getManager();
70
        $em->persist($homepage);
71
        $em->flush();
72
73
        return $client;
74
    }
75
}
76