Issues (12)

lib/custom/tests/MW/Mail/Message/Zend2Test.php (1 issue)

Labels
Severity
1
<?php
2
3
namespace Aimeos\MW\Mail\Message;
4
5
6
/**
7
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
8
 * @copyright Aimeos (aimeos.org), 2014-2018
9
 */
10
class Zend2Test extends \PHPUnit\Framework\TestCase
0 ignored issues
show
The type PHPUnit\Framework\TestCase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
{
12
	private $object;
13
	private $mock;
14
15
16
	/**
17
	 * Sets up the fixture, for example, opens a network connection.
18
	 * This method is called before a test is executed.
19
	 *
20
	 * @access protected
21
	 */
22
	protected function setUp()
23
	{
24
		if( !class_exists( 'Zend\Mail\Message' ) ) {
25
			$this->markTestSkipped( 'Zend\Mail\Message is not available' );
26
		}
27
28
		$this->mock = $this->getMockBuilder( 'Zend\Mail\Message' )->getMock();
29
		$this->object = new \Aimeos\MW\Mail\Message\Zend2( $this->mock, 'UTF-8' );
30
	}
31
32
	/**
33
	 * Tears down the fixture, for example, closes a network connection.
34
	 * This method is called after a test is executed.
35
	 *
36
	 * @access protected
37
	 */
38
	protected function tearDown()
39
	{
40
	}
41
42
43
	public function testAddFrom()
44
	{
45
		$this->mock->expects( $this->once() )->method( 'setFrom' )
46
			->with( $this->stringContains( 'a@b' ), $this->stringContains( 'test' ) );
47
48
		$result = $this->object->addFrom( 'a@b', 'test' );
49
		$this->assertSame( $this->object, $result );
50
	}
51
52
53
	public function testAddTo()
54
	{
55
		$this->mock->expects( $this->once() )->method( 'addTo' )
56
			->with( $this->stringContains( 'a@b' ), $this->stringContains( 'test' ) );
57
58
		$result = $this->object->addTo( 'a@b', 'test' );
59
		$this->assertSame( $this->object, $result );
60
	}
61
62
63
	public function testAddCc()
64
	{
65
		$this->mock->expects( $this->once() )->method( 'addCc' )
66
			->with( $this->stringContains( 'a@b' ), $this->stringContains( 'test' ) );
67
68
		$result = $this->object->addCc( 'a@b', 'test' );
69
		$this->assertSame( $this->object, $result );
70
	}
71
72
73
	public function testAddBcc()
74
	{
75
		$this->mock->expects( $this->once() )->method( 'addBcc' )
76
			->with( $this->stringContains( 'a@b' ), $this->stringContains( 'test' ) );
77
78
		$result = $this->object->addBcc( 'a@b', 'test' );
79
		$this->assertSame( $this->object, $result );
80
	}
81
82
83
	public function testAddReplyTo()
84
	{
85
		$this->mock->expects( $this->once() )->method( 'setReplyTo' )
86
			->with( $this->stringContains( 'a@b' ), $this->stringContains( 'test' ) );
87
88
		$result = $this->object->addReplyTo( 'a@b', 'test' );
89
		$this->assertSame( $this->object, $result );
90
	}
91
92
93
	public function testAddHeader()
94
	{
95
		$mockHeader = $this->getMockBuilder( 'Zend\Mail\Headers' )->getMock();
96
97
		$mockHeader->expects( $this->once() )->method( 'addHeaderLine' )
98
			->with( $this->stringContains( 'test' ), $this->stringContains( 'value' ) );
99
100
		$this->mock->expects( $this->once() )->method( 'getHeaders' )
101
			->will( $this->returnValue( $mockHeader ) );
102
103
		$result = $this->object->addHeader( 'test', 'value' );
104
		$this->assertSame( $this->object, $result );
105
	}
106
107
108
	public function testSetSender()
109
	{
110
		$this->mock->expects( $this->once() )->method( 'setFrom' )
111
			->with( $this->stringContains( 'a@b' ), $this->stringContains( 'test' ) );
112
113
		$result = $this->object->setSender( 'a@b', 'test' );
114
		$this->assertSame( $this->object, $result );
115
	}
116
117
118
	public function testSetSubject()
119
	{
120
		$this->mock->expects( $this->once() )->method( 'setSubject' )
121
			->with( $this->stringContains( 'test' ) );
122
123
		$result = $this->object->setSubject( 'test' );
124
		$this->assertSame( $this->object, $result );
125
	}
126
127
128
	public function testSetBody()
129
	{
130
		$result = $this->object->setBody( 'test' );
131
		$this->object->getObject();
132
133
		$this->assertSame( $this->object, $result );
134
	}
135
136
137
	public function testSetBodyHtml()
138
	{
139
		$result = $this->object->setBodyHtml( 'test' );
140
		$this->object->getObject();
141
142
		$this->assertSame( $this->object, $result );
143
	}
144
145
146
	public function testAddAttachment()
147
	{
148
		$result = $this->object->addAttachment( 'test', 'text/plain', 'test.txt', 'inline' );
149
		$this->assertSame( $this->object, $result );
150
	}
151
152
153
	public function testEmbedAttachment()
154
	{
155
		$result = $this->object->embedAttachment( 'test', 'text/plain', 'test.txt' );
156
		$this->object->getObject();
157
158
		$this->assertInternalType( 'string', $result );
159
	}
160
161
162
	public function testEmbedAttachmentMultiple()
163
	{
164
		$object = new \Aimeos\MW\Mail\Message\Zend2( new \Zend\Mail\Message() );
165
166
		$object->setBody( 'text body' );
167
		$object->embedAttachment( 'test', 'text/plain', 'test.txt' );
168
		$object->embedAttachment( 'test', 'text/plain', 'test.txt' );
169
170
		$exp = '#Content-Disposition: inline; filename="test.txt".*Content-Disposition: inline; filename="1_test.txt"#smu';
171
		$this->assertRegExp( $exp, $object->getObject()->toString() );
172
	}
173
174
175
	public function testGetObject()
176
	{
177
		$this->assertInstanceOf( 'Zend\Mail\Message', $this->object->getObject() );
178
	}
179
180
181
	public function testGenerateMailAlternative()
182
	{
183
		$object = new \Aimeos\MW\Mail\Message\Zend2( new \Zend\Mail\Message() );
184
185
		$object->setBody( 'text body' );
186
		$object->setBodyHtml( 'html body' );
187
188
		$exp = '#Content-Type: multipart/alternative.*Content-Type: text/plain.*Content-Type: text/html#smu';
189
		$this->assertRegExp( $exp, $object->getObject()->toString() );
190
	}
191
192
193
	public function testGenerateMailRelated()
194
	{
195
		$object = new \Aimeos\MW\Mail\Message\Zend2( new \Zend\Mail\Message() );
196
197
		$object->embedAttachment( 'embedded-data', 'text/plain', 'embedded.txt' );
198
		$object->setBodyHtml( 'html body' );
199
200
		$exp = '#Content-Type: multipart/related.*Content-Type: text/html.*Content-Type: text/plain#smu';
201
		$this->assertRegExp( $exp, $object->getObject()->toString() );
202
	}
203
204
205
	public function testGenerateMailFull()
206
	{
207
		$object = new \Aimeos\MW\Mail\Message\Zend2( new \Zend\Mail\Message() );
208
209
		$object->addAttachment( 'attached-data', 'text/plain', 'attached.txt' );
210
		$object->embedAttachment( 'embedded-data', 'text/plain', 'embedded.txt' );
211
		$object->setBodyHtml( 'html body' );
212
		$object->setBody( 'text body' );
213
214
		$exp = '#Content-Type: multipart/mixed.*Content-Type: multipart/alternative.*Content-Type: text/plain.*Content-Type: multipart/related.*Content-Type: text/html.*Content-Type: text/plain.*Content-Type: text/plain#smu';
215
		$this->assertRegExp( $exp, $object->getObject()->toString() );
216
	}
217
218
}
219