testInjectLayoutViewModelCreatesParentForExistingViewModel()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 8
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
/**
3
 * MtMail - e-mail module for Zend Framework
4
 *
5
 * @link      http://github.com/mtymek/MtMail
6
 * @copyright Copyright (c) 2013-2017 Mateusz Tymek
7
 * @license   BSD 2-Clause
8
 */
9
10
namespace MtMailTest\Plugin;
11
12
use MtMail\Event\ComposerEvent;
13
use MtMail\ComposerPlugin\Layout;
14
use MtMail\Service\Composer;
15
use MtMailTest\Test\LayoutProviderTemplate;
16
use Zend\View\Model\ViewModel;
17
18
class LayoutTest extends \PHPUnit\Framework\TestCase
19
{
20
    /**
21
     * @var Layout
22
     */
23
    protected $plugin;
24
25
    public function setUp()
26
    {
27
        $this->plugin = new Layout();
28
    }
29
30
    public function testLayoutTemplateIsMutable()
31
    {
32
        $this->plugin->setLayoutTemplate('layout.phtml');
33
        $this->assertEquals('layout.phtml', $this->plugin->getLayoutTemplate());
34
    }
35
36
    public function testInjectLayoutViewModelCreatesParentForExistingViewModel()
37
    {
38
        $viewModel = new ViewModel();
39
        $event = new ComposerEvent();
40
        $event->setViewModel($viewModel);
41
        $this->plugin->injectLayoutViewModel($event);
42
        $this->assertEquals([$viewModel], $event->getViewModel()->getChildren());
43
    }
44
45
    public function testInjectLayoutViewModelDoesNotCreateParentIfModelTerminates()
46
    {
47
        $viewModel = new ViewModel();
48
        $viewModel->setTerminal(true);
49
        $event = new ComposerEvent();
50
        $event->setViewModel($viewModel);
51
        $this->plugin->injectLayoutViewModel($event);
52
        $this->assertEquals([], $event->getViewModel()->getChildren());
53
        $this->assertEquals($viewModel, $event->getViewModel());
54
    }
55
56
    public function testPluginCanInjectTemplateSpecyficLayout()
57
    {
58
        $template = new LayoutProviderTemplate;
59
        $viewModel = new ViewModel();
60
61
        $event = new ComposerEvent();
62
        $event->setTemplate($template);
63
        $event->setViewModel($viewModel);
64
65
        $this->plugin->injectLayoutViewModel($event);
66
        $this->assertEquals($template->getLayout(), $event->getViewModel()->getTemplate());
67
    }
68
}
69