Hoa central
Message.php
Go to the documentation of this file.
1 <?php
2 
38 
41 use Hoa\Test;
42 
51 class Message extends Test\Unit\Suite
52 {
53  public function case_content_type()
54  {
55  $this
56  ->when($result = new SUT())
57  ->then
58  ->string($result['content-type'])
59  ->isEqualTo('multipart/mixed');
60  }
61 
62  public function case_date()
63  {
64  $this
65  ->when(
66  $this->function->date = function () use (&$date) {
67  return $date = date('r', 42);
68  },
69  $result = new SUT()
70  )
71  ->then
72  ->string($result['date'])
73  ->isEqualTo($date);
74  }
75 
76  public function case_add_content()
77  {
78  $this
79  ->given(
80  $message = new SUT(),
81  $content1 = new Text('foo'),
82  $content2 = new Text('bar'),
83  $message = new SUT()
84  )
85  ->when(
86  $result1 = $message->addContent($content1),
87  $result2 = $message->addContent($content2)
88  )
89  ->then
90  ->object($result1)
91  ->isIdenticalTo($result2)
92  ->object($result2)
93  ->isIdenticalTo($message)
94  ->integer(count($message->getContent()))
95  ->isEqualTo(2);
96  }
97 
98  public function case_get_recipients_only_to()
99  {
100  $this
101  ->given(
102  $recipient = 'gordon@hoa-project.net',
103  $message = new SUT(),
104  $message['to'] = $recipient
105  )
106  ->when($result = $message->getRecipients())
107  ->then
108  ->array($result)
109  ->isEqualTo([
110  $recipient
111  ]);
112  }
113 
115  {
116  $this
117  ->given(
118  $recipient1 = 'gordon@hoa-project.net',
119  $recipient2 = 'alix@hoa-project.net',
120  $recipient3 = 'g-man@hoa-project.net',
121  $message = new SUT(),
122  $message['to'] = $recipient1,
123  $message['cc'] = $recipient2 . ', ' . $recipient3
124  )
125  ->when($result = $message->getRecipients())
126  ->then
127  ->array($result)
128  ->isEqualTo([
129  $recipient1,
130  $recipient2,
131  $recipient3
132  ]);
133  }
134 
136  {
137  $this
138  ->given(
139  $recipient1 = 'gordon@hoa-project.net',
140  $recipient2 = 'alix@hoa-project.net',
141  $recipient3 = 'g-man@hoa-project.net',
142  $message = new SUT(),
143  $message['to'] = $recipient1,
144  $message['bcc'] = $recipient2 . ', ' . $recipient3
145  )
146  ->when($result = $message->getRecipients())
147  ->then
148  ->array($result)
149  ->isEqualTo([
150  $recipient1,
151  $recipient2,
152  $recipient3
153  ]);
154  }
155 
157  {
158  $this
159  ->given(
160  $recipient1 = 'gordon@hoa-project.net',
161  $recipient2 = 'alix@hoa-project.net',
162  $recipient3 = 'g-man@hoa-project.net',
163  $message = new SUT(),
164  $message['to'] = $recipient1,
165  $message['cc'] = $recipient2,
166  $message['bcc'] = $recipient3
167  )
168  ->when($result = $message->getRecipients())
169  ->then
170  ->array($result)
171  ->isEqualTo([
172  $recipient1,
173  $recipient2,
174  $recipient3
175  ]);
176  }
177 
179  {
180  $this
181  ->given(
182  $recipient = '"Gordon Freeman" gordon@hoa-project.net',
183  $message = new SUT(),
184  $message['to'] = $recipient
185  )
186  ->when($result = $message->getRecipients())
187  ->then
188  ->array($result)
189  ->isEqualTo([
190  'gordon@hoa-project.net'
191  ]);
192  }
193 
194  public function case_no_content()
195  {
196  $this
197  ->given($message = new SUT())
198  ->exception(function () use ($message) {
199  $message->getFormattedContent();
200  })
201  ->isInstanceOf('Hoa\Mail\Exception');
202  }
203 
204  public function case_one_content()
205  {
206  $this
207  ->given(
208  $this->function->date = function () use (&$date) {
209  return $date = date('r', 42);
210  },
211  $content = new Text('foo'),
212  $message = new SUT(),
213  $message->addContent($content)
214  )
215  ->when($result = $message->getFormattedContent())
216  ->then
217  ->string($result)
218  ->isEqualTo(
219  'date: ' . $date . CRLF .
220  'content-transfer-encoding: quoted-printable' . CRLF .
221  'content-disposition: inline' . CRLF .
222  'content-type: text/plain; charset=utf-8' . CRLF .
223  CRLF .
224  'foo'
225  );
226  }
227 
228  public function case_many_contents()
229  {
230  $this
231  ->given(
232  $this->function->date = function () use (&$date) {
233  return $date = date('r', 42);
234  },
235  $this->function->microtime = function () use (&$microtime) {
236  return $microtime = 42;
237  },
238  $content1 = new Text('foo'),
239  $content2 = new Text('bar'),
240  $content3 = new Text('baz'),
241  $content4 = new Text('qux'),
242  $message = new SUT(),
243  $message->addContent($content1),
244  $message->addContent($content2),
245  $message->addContent($content3),
246  $message->addContent($content4)
247  )
248  ->when($result = $message->getFormattedContent())
249  ->then
250  ->string($result)
251  ->isEqualTo(
252  'content-type: multipart/mixed; boundary="__bndry-889c9d2eee9fc547c03ab71ac5c93db3"' . CRLF .
253  'date: Thu, 01 Jan 1970 01:00:42 +0100' . CRLF .
254  CRLF .
255 
256  // Content 1.
257  '--__bndry-889c9d2eee9fc547c03ab71ac5c93db3' . CRLF .
258  $content1->getFormattedContent() . CRLF .
259 
260  // Content 2.
261  '--__bndry-889c9d2eee9fc547c03ab71ac5c93db3' . CRLF .
262  $content2->getFormattedContent() . CRLF .
263 
264  // Content 3.
265  '--__bndry-889c9d2eee9fc547c03ab71ac5c93db3' . CRLF .
266  $content3->getFormattedContent() . CRLF .
267 
268  // Content 4.
269  '--__bndry-889c9d2eee9fc547c03ab71ac5c93db3' . CRLF .
270  $content4->getFormattedContent() . CRLF .
271 
272  '--__bndry-889c9d2eee9fc547c03ab71ac5c93db3' .
273  '--' . CRLF
274  );
275  }
276 }
$content
Definition: Hoa.php:119