|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Yiisoft\Mailer\Tests; |
|
4
|
|
|
|
|
5
|
|
|
use Psr\EventDispatcher\EventDispatcherInterface; |
|
6
|
|
|
use Psr\Log\LoggerInterface; |
|
7
|
|
|
use Yiisoft\Mailer\Composer; |
|
8
|
|
|
use Yiisoft\View\Theme; |
|
9
|
|
|
use Yiisoft\View\View; |
|
10
|
|
|
use Yiisoft\Mailer\Template; |
|
11
|
|
|
|
|
12
|
|
|
class ComposerTest extends TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @return Composer $composer instance. |
|
16
|
|
|
*/ |
|
17
|
|
|
private function getComposer(): Composer |
|
18
|
|
|
{ |
|
19
|
|
|
return $this->get(Composer::class); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @dataProvider setUpData |
|
24
|
|
|
*/ |
|
25
|
|
|
public function testSetup(string $viewPath, string $htmlLayout, string $textLayout): void |
|
26
|
|
|
{ |
|
27
|
|
|
$composer = new Composer($this->get(View::class), $viewPath); |
|
28
|
|
|
$composer->setHtmlLayout($htmlLayout); |
|
29
|
|
|
$composer->setTextayout($textLayout); |
|
30
|
|
|
$this->assertEquals($composer->getView(), $this->get(View::class)); |
|
31
|
|
|
$this->assertSame($viewPath, $composer->getViewPath()); |
|
32
|
|
|
$this->assertSame($htmlLayout, $this->getObjectPropertyValue($composer, 'htmlLayout')); |
|
33
|
|
|
$this->assertSame($textLayout, $this->getObjectPropertyValue($composer, 'textLayout')); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function setUpData(): array |
|
37
|
|
|
{ |
|
38
|
|
|
return [ |
|
39
|
|
|
['/tmp/views', '', ''], |
|
40
|
|
|
['/tmp/views', 'layouts/html', 'layouts/text'], |
|
41
|
|
|
]; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function testSetView(): void |
|
45
|
|
|
{ |
|
46
|
|
|
$view = new View('/tmp/views', new Theme(), $this->get(EventDispatcherInterface::class), $this->get(LoggerInterface::class)); |
|
47
|
|
|
$composer = $this->getComposer(); |
|
48
|
|
|
$composer->setView($view); |
|
49
|
|
|
|
|
50
|
|
|
$this->assertEquals($composer->getView(), $view); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function testSetViewPath(): void |
|
54
|
|
|
{ |
|
55
|
|
|
$path = '/tmp/views'; |
|
56
|
|
|
$composer = $this->getComposer(); |
|
57
|
|
|
$composer->setViewPath($path); |
|
58
|
|
|
$this->assertEquals($composer->getViewPath(), $path); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function testCreateTemplate(): void |
|
62
|
|
|
{ |
|
63
|
|
|
$composer = $this->getComposer(); |
|
64
|
|
|
$method = new \ReflectionMethod(Composer::class, 'createTemplate'); |
|
65
|
|
|
$method->setAccessible(true); |
|
66
|
|
|
|
|
67
|
|
|
$viewName = 'test-view'; |
|
68
|
|
|
/* @var $template Template */ |
|
69
|
|
|
$template = $method->invoke($composer, $viewName); |
|
70
|
|
|
|
|
71
|
|
|
$this->assertSame($composer->getView(), $this->getObjectPropertyValue($template, 'view')); |
|
72
|
|
|
$this->assertEquals($viewName, $this->getObjectPropertyValue($template, 'viewName')); |
|
73
|
|
|
$this->assertEquals($this->getObjectPropertyValue($composer, 'viewPath'), $template->getViewPath()); |
|
74
|
|
|
$this->assertEquals($this->getObjectPropertyValue($composer, 'htmlLayout'), $this->getObjectPropertyValue($template, 'htmlLayout')); |
|
75
|
|
|
$this->assertEquals($this->getObjectPropertyValue($composer, 'textLayout'), $this->getObjectPropertyValue($template, 'textLayout')); |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|