Hoa central
Content.php
Go to the documentation of this file.
1 <?php
2 
38 
39 use Hoa\Test;
40 use Mock\Hoa\Mail\Content as SUT;
41 
50 class Content extends Test\Unit\Suite
51 {
52  public function case_content_disposition()
53  {
54  $this
55  ->given($content = new SUT())
56  ->when($result = $content['content-disposition'])
57  ->then
58  ->string($result)
59  ->isEqualTo('inline');
60  }
61 
63  {
64  $this
65  ->given($content = new SUT())
66  ->when($result = $content['content-transfer-encoding'])
67  ->then
68  ->string($result)
69  ->isEqualTo('base64');
70  }
71 
72  public function case_array_access()
73  {
74  $this
75  ->when($content = new SUT())
76  ->then
77  ->object($content)
78  ->isInstanceOf('ArrayAccess');
79  }
80 
81  public function case_headers()
82  {
83  $this
84  ->given(
85  $name = 'FoO',
86  $value = 'Bar'
87  )
88  ->when($result = new SUT())
89  ->then
90  ->boolean(isset($result[$name]))
91  ->isFalse()
92 
93  ->when($result[$name] = $value)
94  ->then
95  ->boolean(isset($result[$name]))
96  ->isTrue()
97  ->string($result[$name])
98  ->isEqualTo($value)
99 
100  ->let($_name = strtolower($name))
101  ->boolean(isset($result[$_name]))
102  ->isTrue()
103  ->string($result[$_name])
104  ->isEqualTo($value)
105 
106  ->when(function () use ($result, $name) {
107  unset($result[$name]);
108  })
109  ->then
110  ->boolean(isset($result[$name]))
111  ->isFalse();
112  }
113 
114  public function case_illegal_headers()
115  {
116  $this
117  ->given(
118  $value = $this->realdom->regex('#.*(\n|\r)+.*#'),
119  $content = new SUT()
120  )
121  ->when(function () use ($value, $content) {
122  foreach ($this->sampleMany($value, 512) as $badValue) {
123  $this
124  ->exception(function () use ($badValue, $content) {
125  $content['foo' ] = $badValue;
126  })
127  ->isInstanceOf('Hoa\Mail\Exception\Security');
128  }
129  });
130  }
131 
132  public function case_get_headers()
133  {
134  $this
135  ->given($content = new SUT())
136  ->when($result = $content->getHeaders())
137  ->then
138  ->array($result)
139  ->isEqualTo([
140  'content-transfer-encoding' => 'base64',
141  'content-disposition' => 'inline'
142  ]);
143  }
144 
146  {
147  $this
148  ->given(
149  $content = new SUT(),
150  $this->calling($content)->_getContent = 'foobar'
151  )
152  ->when($result = $content->getFormattedContent())
153  ->then
154  ->string($result)
155  ->isEqualTo(
156  'content-transfer-encoding: base64' . CRLF .
157  'content-disposition: inline' . CRLF .
158  CRLF .
159  'foobar'
160  );
161  }
162 
164  {
165  $this
166  ->given(
167  $content = new SUT(),
168  $this->calling($content)->_getContent = 'foobar'
169  )
170  ->when($result = $content->getFormattedContent(false))
171  ->then
172  ->string($result)
173  ->isEqualTo('foobar');
174  }
175 
176  public function case_get_id_auto_generated()
177  {
178  $this
179  ->given(
180  $this->function->md5 = 'foo',
181  $content = new SUT()
182  )
183  ->when($result = $content->getId())
184  ->then
185  ->string($result)
186  ->isEqualTo('foo*mail@hoa-project.net')
187  ->string($content['content-id'])
188  ->isEqualTo('<foo*mail@hoa-project.net>');
189  }
190 
191  public function case_get_id_forced()
192  {
193  $this
194  ->given(
195  $id = '<foo@bar.baz>',
196  $content = new SUT(),
197  $content['content-id'] = $id
198  )
199  ->when($result = $content->getId())
200  ->then
201  ->string($result)
202  ->isEqualTo(trim($id, '<>'));
203  }
204 
205  public function case_get_id_url()
206  {
207  $this
208  ->given(
209  $content = new SUT(),
210  $id = $content->getId()
211  )
212  ->when($result = $content->getIdUrl())
213  ->then
214  ->string($result)
215  ->isEqualTo('cid:' . $id);
216  }
217 
218  public function case_format_no_header()
219  {
220  $this
221  ->given($headers = [])
222  ->when($result = SUT::formatHeaders($headers))
223  ->then
224  ->variable($result)
225  ->isNull();
226  }
227 
228  public function case_format_headers()
229  {
230  $this
231  ->given($headers = ['a' => 'b', 'c' => 'd'])
232  ->when($result = SUT::formatHeaders($headers))
233  ->then
234  ->string($result)
235  ->isEqualTo(
236  'a: b' . CRLF .
237  'c: d' . CRLF
238  );
239  }
240 
241  public function case_get_address()
242  {
243  $this
244  ->given($_contact = $this->realdom->regex('#([^<]*<)?.+#'))
245  ->when(function () use ($_contact) {
246  foreach ($this->sampleMany($_contact, 1000) as $contact) {
247  if (false !== $pos = strpos($contact, '<')) {
248  $address = substr($contact, $pos + 1);
249  } else {
250  $address = trim($contact);
251  }
252 
253  $this
254  ->string(SUT::getAddress($contact))
255  ->isEqualTo($address);
256  }
257  });
258  }
259 
260  public function case_get_domain()
261  {
262  $this
263  ->given($_contact = $this->realdom->regex('#(.+@)?.+#'))
264  ->when(function () use ($_contact) {
265  foreach ($this->sampleMany($_contact, 1000) as $contact) {
266  if (false !== $pos = strpos($contact, '@')) {
267  $domain = substr($contact, $pos + 1);
268  } else {
269  $domain = $contact;
270  }
271 
272  $this
273  ->string(SUT::getDomain($contact))
274  ->isEqualTo($domain);
275  }
276  });
277  }
278 
279  public function case_to_string()
280  {
281  $this
282  ->given(
283  $content = new SUT(),
284  $this->calling($content)->_getContent = 'foobar'
285  )
286  ->when($result = $content->__toString())
287  ->then
288  ->string($result)
289  ->isEqualTo($content->getFormattedContent());
290  }
291 }
$content
Definition: Hoa.php:119