/
MailPreviewControllerTest.php
163 lines (147 loc) · 4.81 KB
/
MailPreviewControllerTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<?php
/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @since 3.0.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace DebugKit\Test\TestCase\Controller;
use Cake\Core\Plugin;
use Cake\ORM\TableRegistry;
use Cake\Routing\RouteBuilder;
use Cake\Routing\Router;
use Cake\TestSuite\IntegrationTestCase;
/**
* Mail preview controller test
*/
class MailPreviewControllerTest extends IntegrationTestCase
{
/**
* Fixtures.
*
* @var array
*/
public $fixtures = [
'plugin.debug_kit.requests',
'plugin.debug_kit.panels'
];
/**
* Setup method.
*
* @return void
*/
public function setUp()
{
parent::setUp();
Plugin::load('DebugkitTestPlugin', ['path' => APP . 'Plugin' . DS . 'DebugkitTestPlugin' . DS]);
Router::scope('/', function ($routes) {
$routes->connect('/users/:action/*', ['controller' => 'Users']);
});
Router::plugin('DebugKit', function (RouteBuilder $routes) {
$routes->scope(
'/mail_preview',
['controller' => 'MailPreview'],
function ($routes) {
$routes->connect('/sent/*', ['action' => 'sent']);
$routes->connect('/preview/*', ['action' => 'email']);
}
);
});
$this->useHttpServer(true);
}
/**
* Test that plugin is passed to the view in email action
*
* @return void
*/
public function testEmailPluginPassedToView()
{
$this->get('/debug_kit/mail_preview/preview/TestMailerPreview/test_email?plugin=DebugkitTestPlugin');
$this->assertResponseOk();
$this->assertResponseContains('src="?part=text&plugin=DebugkitTestPlugin');
}
/** Test email template content
*
* @return void
*/
public function testEmailPartTextContent()
{
$this->get('/debug_kit/mail_preview/preview/TestMailerPreview/test_email?part=text&plugin=DebugkitTestPlugin');
$this->assertResponseOk();
$this->assertResponseContains('Testing email action.');
$this->assertResponseContains('/users/verify/token', 'Should contain URL from app context');
}
/**
* Test that onChange js function passes plugin to iframe
*
* @return void
*/
public function testOnChangeJsPluginPassedToview()
{
$this->get('/debug_kit/mail_preview/preview/TestMailerPreview/test_email?plugin=DebugkitTestPlugin');
$this->assertResponseContains("iframe.contentWindow.location.replace('?part=' + part_name + '&plugin=DebugkitTestPlugin');");
}
/**
* Test sent() with invalid data.
*
* @return void
*/
public function testSentInvalidData()
{
$this->get('/debug_kit/mail_preview/sent/aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa/0');
$this->assertResponseCode(404);
}
/**
* Test sent() with valid data.
*
* @return void
*/
public function testSentValidData()
{
$panels = TableRegistry::get('Panels');
$panel = $panels->newEntity(['request_id' => 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa']);
$data = [
'emails' => [
[
'headers' => ['To' => 'test@example.com'],
'message' => ['html' => '<h1>Hi</h1>', 'text' => 'Hi']
]
]
];
$panel->content = serialize($data);
$panels->save($panel);
$this->get("/debug_kit/mail_preview/sent/{$panel->id}/0");
$this->assertResponseCode(200);
$this->assertResponseContains('test@example.com');
$this->assertResponseContains('<iframe');
}
/**
* Test sent() with valid data rendering a part
*
* @return void
*/
public function testSentValidDataRenderPart()
{
$panels = TableRegistry::get('Panels');
$panel = $panels->newEntity(['request_id' => 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa']);
$data = [
'emails' => [
[
'headers' => ['To' => 'test@example.com'],
'message' => ['html' => '<h1>Hi</h1>', 'text' => 'Hi']
]
]
];
$panel->content = serialize($data);
$panels->save($panel);
$this->get("/debug_kit/mail_preview/sent/{$panel->id}/0?part=html");
$this->assertResponseCode(200);
$this->assertResponseContains('<h1>Hi</h1>');
}
}