1 | <?php |
||
19 | class CaptureRequestTest extends \PHPUnit_Framework_TestCase |
||
20 | { |
||
21 | |||
22 | /** +++++++++++++++++++++++++++++++++++ **/ |
||
23 | /** ++++++++++++++ TESTS ++++++++++++++ **/ |
||
24 | /** +++++++++++++++++++++++++++++++++++ **/ |
||
25 | |||
26 | /** |
||
27 | * Test capture type is returned by default |
||
28 | * if no type is set. |
||
29 | * |
||
30 | * @access public |
||
31 | * @return void |
||
32 | */ |
||
33 | public function testCaptureTypeIsReturnedByDefaultIfNotTypeIsSet() |
||
39 | |||
40 | /** |
||
41 | * Test custom type can be set. |
||
42 | * |
||
43 | * @access public |
||
44 | * @return void |
||
45 | */ |
||
46 | public function testCustomTypeCanBeSet() |
||
55 | |||
56 | /** |
||
57 | * Test URL can be set via constructor. |
||
58 | * |
||
59 | * @access public |
||
60 | * @return void |
||
61 | */ |
||
62 | public function testUrlCanBeSetViaConstructor() |
||
69 | |||
70 | /** |
||
71 | * Test method can be set via constructor. |
||
72 | * |
||
73 | * @access public |
||
74 | * @return void |
||
75 | */ |
||
76 | public function testMethodCanBeSetViaConstructor() |
||
83 | |||
84 | /** |
||
85 | * Test timeout can be set via constructor. |
||
86 | * |
||
87 | * @access public |
||
88 | * @return void |
||
89 | */ |
||
90 | public function testTimeoutCanBeSetViaConstructor() |
||
97 | |||
98 | /** |
||
99 | * Test invalid method is thrown if method |
||
100 | * is invalid. |
||
101 | * |
||
102 | * @access public |
||
103 | * @return void |
||
104 | */ |
||
105 | public function testInvalidMethodIsThrownIfMethodIsInvalid() |
||
112 | |||
113 | /** |
||
114 | * Test rect width can be set. |
||
115 | * |
||
116 | * @access public |
||
117 | * @return void |
||
118 | */ |
||
119 | public function testRectWidthCanBeSet() |
||
129 | |||
130 | /** |
||
131 | * Test rect height can be set. |
||
132 | * |
||
133 | * @access public |
||
134 | * @return void |
||
135 | */ |
||
136 | public function testRectHeightCanBeSet() |
||
146 | |||
147 | /** |
||
148 | * Test rect top can be set. |
||
149 | * |
||
150 | * @access public |
||
151 | * @return void |
||
152 | */ |
||
153 | public function testRectTopCanBeSet() |
||
164 | |||
165 | /** |
||
166 | * Test rect left can be set. |
||
167 | * |
||
168 | * @access public |
||
169 | * @return void |
||
170 | */ |
||
171 | public function testRectLeftCanBeSet() |
||
182 | |||
183 | /** |
||
184 | * Test invalid URL exception is thrown |
||
185 | * if URL is invalid format. |
||
186 | * |
||
187 | * @access public |
||
188 | * @return void |
||
189 | */ |
||
190 | public function testInvalidUrlExceptionIsThrownIfUrlIsInvalidFormat() |
||
197 | |||
198 | /** |
||
199 | * Test URL does not contain query params if |
||
200 | * mehtod is not HEAD or GET. |
||
201 | * |
||
202 | * @access public |
||
203 | * @return void |
||
204 | */ |
||
205 | public function testUrlDoesNotContainQueryParamsIfMethodIsNotHeadOrGet() |
||
221 | |||
222 | /** |
||
223 | * Test URL does contain query params if mehthod |
||
224 | * is GET. |
||
225 | * |
||
226 | * @access public |
||
227 | * @return void |
||
228 | */ |
||
229 | public function testUrlDoesContainQueryParamsIfMethodIsGet() |
||
247 | |||
248 | /** |
||
249 | * Test URL does contain query params if method |
||
250 | * is HEAD. |
||
251 | * |
||
252 | * @access public |
||
253 | * @return void |
||
254 | */ |
||
255 | public function testUrlDoesContainQueryParamsIfMethodIsHead() |
||
273 | |||
274 | /** |
||
275 | * Test query params are appended to URL if |
||
276 | * URL contains existng query params. |
||
277 | * |
||
278 | * @access public |
||
279 | * @return void |
||
280 | */ |
||
281 | public function testQueryParamsAreAppendedToUrlIfUrlContainsExistingQueryParams() |
||
299 | |||
300 | /** |
||
301 | * Test request contains no body if method |
||
302 | * is GET. |
||
303 | * |
||
304 | * @access public |
||
305 | * @return void |
||
306 | */ |
||
307 | public function testRequestContainsNoBodyIfMethodIsGet() |
||
320 | |||
321 | /** |
||
322 | * Test request contains no body if method |
||
323 | * is HEAD. |
||
324 | * |
||
325 | * @access public |
||
326 | * @return void |
||
327 | */ |
||
328 | public function testRequestContainsNoBodyIfMethodIsHead() |
||
341 | |||
342 | /** |
||
343 | * Test request contains a body if method is |
||
344 | * not HEAD or GET. |
||
345 | * |
||
346 | * @access public |
||
347 | * @return void |
||
348 | */ |
||
349 | public function testRequestContainsABodyIfMethodIsNotHeadOrGet() |
||
364 | |||
365 | /** |
||
366 | * Test request data can be flattened. |
||
367 | * |
||
368 | * @access public |
||
369 | * @return void |
||
370 | */ |
||
371 | public function testRequestDataCanBeFalttened() |
||
392 | |||
393 | /** |
||
394 | * Test raw request data can be accessed. |
||
395 | * |
||
396 | * @access public |
||
397 | * @return void |
||
398 | */ |
||
399 | public function testRawRequestDataCanBeAccessed() |
||
414 | |||
415 | /** |
||
416 | * Test headers can be added. |
||
417 | * |
||
418 | * @access public |
||
419 | * @return void |
||
420 | */ |
||
421 | public function testHeadersCanBeAdded() |
||
440 | |||
441 | /** |
||
442 | * Test headers can be accessed in |
||
443 | * JSON format |
||
444 | * |
||
445 | * @access public |
||
446 | * @return void |
||
447 | */ |
||
448 | public function testHeadersCanBeAccessedInJsonFormat() |
||
462 | |||
463 | /** |
||
464 | * Test raw headers can be accessed. |
||
465 | * |
||
466 | * @access public |
||
467 | * @return void |
||
468 | */ |
||
469 | public function testRawHeadersCanBeAccessed() |
||
481 | |||
482 | /** |
||
483 | * Test not writable exception is thrown if |
||
484 | * output path is not writable. |
||
485 | * |
||
486 | * @access public |
||
487 | * @return void |
||
488 | */ |
||
489 | public function testNotWritableExceptonIsThrownIfOutputPathIsNotWritable() |
||
490 | { |
||
491 | $this->setExpectedException('\JonnyW\PhantomJs\Exception\NotWritableException'); |
||
492 | |||
493 | $invalidPath = '/invalid/path'; |
||
494 | |||
495 | $captureRequest = $this->getCaptureRequest(); |
||
496 | $captureRequest->setOutputFile($invalidPath); |
||
497 | } |
||
498 | |||
499 | /** |
||
500 | * Test can set output file. |
||
501 | * |
||
502 | * @access public |
||
503 | * @return void |
||
504 | */ |
||
505 | public function testCanSetOutputFile() |
||
514 | |||
515 | /** |
||
516 | * Test can set viewport width. |
||
517 | * |
||
518 | * @access public |
||
519 | * @return void |
||
520 | */ |
||
521 | public function testCanSetViewportWidth() |
||
531 | |||
532 | /** |
||
533 | * Test can set viewport height. |
||
534 | * |
||
535 | * @access public |
||
536 | * @return void |
||
537 | */ |
||
538 | public function testCanSetViewportHeight() |
||
548 | |||
549 | /** +++++++++++++++++++++++++++++++++++ **/ |
||
550 | /** ++++++++++ TEST ENTITIES ++++++++++ **/ |
||
551 | /** +++++++++++++++++++++++++++++++++++ **/ |
||
552 | |||
553 | /** |
||
554 | * Get capture request instance. |
||
555 | * |
||
556 | * @access protected |
||
557 | * @param string $url (default: null) |
||
558 | * @param string $method (default: RequestInterface::METHOD_GET) |
||
559 | * @param int $timeout (default: 5000) |
||
560 | * @return \JonnyW\PhantomJs\Http\CaptureRequest |
||
561 | */ |
||
562 | protected function getCaptureRequest($url = null, $method = RequestInterface::METHOD_GET, $timeout = 5000) |
||
568 | } |
||
569 |