-
-
Notifications
You must be signed in to change notification settings - Fork 529
/
Copy pathmodMailTest.php
135 lines (127 loc) · 3.27 KB
/
modMailTest.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
<?php
/*
* This file is part of the MODX Revolution package.
*
* Copyright (c) MODX, LLC
*
* For complete copyright and license information, see the COPYRIGHT and LICENSE
* files found in the top-level directory of this distribution.
*
* @package modx-test
*/
/**
* Tests related to the modMail class.
*
* @package modx-test
* @subpackage modx
* @group Model
* @group Mail
* @group modMail
*/
class modMailTest extends MODxTestCase {
/**
* @var modMail|PHPUnit_Framework_MockObject_MockObject $mail
*/
public $mail;
public function setUp(): void
{
parent::setUp();
$this->modx->loadClass('mail.modMail',MODX_CORE_PATH.'model/modx/',true,true);
$this->mail = $this->getMockForAbstractClass('modMail',array(&$this->modx));
$this->mail->expects($this->any())
->method('_getMailer')
->will($this->returnValue(true));
}
/**
* @param string $k
* @param mixed $v
* @dataProvider providerSet
*/
public function testSet($k,$v) {
$this->mail->set($k,$v);
$this->assertEquals($v,$this->mail->attributes[$k]);
}
/**
* @return array
*/
public function providerSet() {
return array(
array('mail_use_smtp',true),
array('mail_use_smtp',false),
);
}
/**
* @param string $k
* @param mixed $v
* @dataProvider providerGet
* @depends testSet
*/
public function testGet($k,$v) {
$this->mail->set($k,$v);
$result = $this->mail->get($k);
$this->assertEquals($v,$result);
}
/**
* @return array
*/
public function providerGet() {
return array(
array('mail_use_smtp',true),
array('mail_use_smtp',false),
);
}
/**
* @return void
*/
public function testClearAttachments() {
$this->mail->clearAttachments();
$this->assertEmpty($this->mail->files);
}
/**
* @param mixed $file
* @dataProvider providerAttach
* @depends testClearAttachments
*/
public function testAttach($file) {
$this->mail->clearAttachments();
$this->mail->attach($file);
$this->assertNotEmpty($this->mail->files);
$this->mail->clearAttachments();
}
/**
* @return array
*/
public function providerAttach() {
return array(
array('test/file.txt'),
array(array('tmp_name' => 'test/file.txt','error' => 0,'name' => 'file.txt')),
);
}
/**
* @param string $header
* @param string $key
* @param string $value
* @dataProvider providerHeader
*/
public function testHeader($header,$key,$value) {
$this->mail->header($header);
$found = false;
foreach ($this->mail->headers as $header) {
if (isset($header[0]) && isset($header[1])) {
if ($header[0] == $key && $header[1] == $value) {
$found = true;
break;
}
}
}
$this->assertTrue($found);
}
/**
* @return array
*/
public function providerHeader() {
return array(
array('Content-type:text/html','Content-type','text/html'),
);
}
}