|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Azine\EmailBundle\Tests\Services; |
|
4
|
|
|
|
|
5
|
|
|
use Azine\EmailBundle\Services\AzineWebViewService; |
|
6
|
|
|
|
|
7
|
|
|
class AzineWebViewServiceTest extends \PHPUnit\Framework\TestCase |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject mock of the UrlGeneratorInterface |
|
11
|
|
|
*/ |
|
12
|
|
|
private function getMockRouter() |
|
13
|
|
|
{ |
|
14
|
|
|
return $this->getMockBuilder("Symfony\Component\Routing\Generator\UrlGeneratorInterface")->disableOriginalConstructor()->getMock(); |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
public function testGetTemplatesForWebView() |
|
18
|
|
|
{ |
|
19
|
|
|
$routerMock = $this->getMockRouter(); |
|
20
|
|
|
$webViewService = new AzineWebViewService($routerMock); |
|
21
|
|
|
|
|
22
|
|
|
$this->assertTrue(is_array($webViewService->getTemplatesForWebPreView())); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
public function testGetTestMailAccounts() |
|
26
|
|
|
{ |
|
27
|
|
|
$routerMock = $this->getMockRouter(); |
|
28
|
|
|
$webViewService = new AzineWebViewService($routerMock); |
|
29
|
|
|
|
|
30
|
|
|
$this->assertTrue(is_array($webViewService->getTestMailAccounts())); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function testGetDummyVarsFor() |
|
34
|
|
|
{ |
|
35
|
|
|
$routerMock = $this->getMockRouter(); |
|
36
|
|
|
$webViewService = new AzineWebViewService($routerMock); |
|
37
|
|
|
|
|
38
|
|
|
$this->assertTrue(is_array($webViewService->getDummyVarsFor('some template', 'de'))); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function testAddTestMailAccount() |
|
42
|
|
|
{ |
|
43
|
|
|
$routerMock = $this->getMockRouter(); |
|
44
|
|
|
$webViewService = new AzineWebViewService($routerMock); |
|
45
|
|
|
|
|
46
|
|
|
$description = 'Some description'; |
|
47
|
|
|
$emailAddress = '[email protected]'; |
|
48
|
|
|
$args = array(array(), $description, $emailAddress); |
|
49
|
|
|
$returnValue = self::getMethod('addTestMailAccount')->invokeArgs($webViewService, $args); |
|
50
|
|
|
|
|
51
|
|
|
$this->assertSame(array('accountDescription' => $description, 'accountEmail' => $emailAddress), $returnValue[0]); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function testAddTemplate() |
|
55
|
|
|
{ |
|
56
|
|
|
$templateId = 'someId'; |
|
57
|
|
|
$description = 'some new template'; |
|
58
|
|
|
$formats = array('txt', 'html', 'xml'); |
|
59
|
|
|
$someUrl = '/some/url/to/the/preview'; |
|
60
|
|
|
|
|
61
|
|
|
$routerMock = $this->getMockRouter(); |
|
62
|
|
|
$routerMock->expects($this->once())->method('generate')->with('azine_email_web_preview', array('template' => $templateId))->will($this->returnValue($someUrl)); |
|
63
|
|
|
|
|
64
|
|
|
$webViewService = new AzineWebViewService($routerMock); |
|
65
|
|
|
|
|
66
|
|
|
$args = array(array(), $description, $templateId, $formats); |
|
67
|
|
|
$templates = self::getMethod('addTemplate')->invokeArgs($webViewService, $args); |
|
68
|
|
|
|
|
69
|
|
|
$this->assertSame(1, sizeof($templates)); |
|
70
|
|
|
$this->assertSame(array('url' => $someUrl, |
|
71
|
|
|
'description' => $description, |
|
72
|
|
|
'formats' => $formats, |
|
73
|
|
|
'templateId' => $templateId, |
|
74
|
|
|
), $templates[0]); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @param string $name |
|
79
|
|
|
*/ |
|
80
|
|
|
private static function getMethod($name) |
|
81
|
|
|
{ |
|
82
|
|
|
$class = new \ReflectionClass("Azine\EmailBundle\Services\AzineWebViewService"); |
|
83
|
|
|
$method = $class->getMethod($name); |
|
84
|
|
|
$method->setAccessible(true); |
|
85
|
|
|
|
|
86
|
|
|
return $method; |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|