equal
deleted
inserted
replaced
12 * obtain it through the world-wide-web, please send an email |
12 * obtain it through the world-wide-web, please send an email |
13 * to license@zend.com so we can send you a copy immediately. |
13 * to license@zend.com so we can send you a copy immediately. |
14 * |
14 * |
15 * @category Zend |
15 * @category Zend |
16 * @package Zend_Test |
16 * @package Zend_Test |
17 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
17 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) |
18 * @license http://framework.zend.com/license/new-bsd New BSD License |
18 * @license http://framework.zend.com/license/new-bsd New BSD License |
19 * @version $Id: ControllerTestCase.php 24593 2012-01-05 20:35:02Z matthew $ |
19 * @version $Id$ |
20 */ |
20 */ |
21 |
|
22 /** @see PHPUnit_Runner_Version */ |
|
23 require_once 'PHPUnit/Runner/Version.php'; |
|
24 |
|
25 /** |
|
26 * Depending on version, include the proper PHPUnit support |
|
27 * @see PHPUnit_Autoload |
|
28 */ |
|
29 require_once (version_compare(PHPUnit_Runner_Version::id(), '3.5.0', '>=')) ? 'PHPUnit/Autoload.php' : 'PHPUnit/Framework.php'; |
|
30 |
21 |
31 /** @see Zend_Controller_Front */ |
22 /** @see Zend_Controller_Front */ |
32 require_once 'Zend/Controller/Front.php'; |
23 require_once 'Zend/Controller/Front.php'; |
33 |
24 |
34 /** @see Zend_Controller_Action_HelperBroker */ |
25 /** @see Zend_Controller_Action_HelperBroker */ |
48 * |
39 * |
49 * @uses PHPUnit_Framework_TestCase |
40 * @uses PHPUnit_Framework_TestCase |
50 * @category Zend |
41 * @category Zend |
51 * @package Zend_Test |
42 * @package Zend_Test |
52 * @subpackage PHPUnit |
43 * @subpackage PHPUnit |
53 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
44 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) |
54 * @license http://framework.zend.com/license/new-bsd New BSD License |
45 * @license http://framework.zend.com/license/new-bsd New BSD License |
55 */ |
46 */ |
56 abstract class Zend_Test_PHPUnit_ControllerTestCase extends PHPUnit_Framework_TestCase |
47 abstract class Zend_Test_PHPUnit_ControllerTestCase extends PHPUnit_Framework_TestCase |
57 { |
48 { |
58 /** |
49 /** |
88 |
79 |
89 /** |
80 /** |
90 * Overloading: prevent overloading to special properties |
81 * Overloading: prevent overloading to special properties |
91 * |
82 * |
92 * @param string $name |
83 * @param string $name |
93 * @param mixed $value |
84 * @param mixed $value |
94 * @return void |
85 * @throws Zend_Exception |
95 */ |
86 */ |
96 public function __set($name, $value) |
87 public function __set($name, $value) |
97 { |
88 { |
98 if (in_array($name, array('request', 'response', 'frontController'))) { |
89 if (in_array($name, array('request', 'response', 'frontController'))) { |
99 require_once 'Zend/Exception.php'; |
90 require_once 'Zend/Exception.php'; |
105 /** |
96 /** |
106 * Overloading for common properties |
97 * Overloading for common properties |
107 * |
98 * |
108 * Provides overloading for request, response, and frontController objects. |
99 * Provides overloading for request, response, and frontController objects. |
109 * |
100 * |
110 * @param mixed $name |
101 * @param mixed $name |
111 * @return void |
102 * @return null|Zend_Controller_Front|Zend_Controller_Request_HttpTestCase|Zend_Controller_Response_HttpTestCase |
112 */ |
103 */ |
113 public function __get($name) |
104 public function __get($name) |
114 { |
105 { |
115 switch ($name) { |
106 switch ($name) { |
116 case 'request': |
107 case 'request': |
126 |
117 |
127 /** |
118 /** |
128 * Set up MVC app |
119 * Set up MVC app |
129 * |
120 * |
130 * Calls {@link bootstrap()} by default |
121 * Calls {@link bootstrap()} by default |
131 * |
|
132 * @return void |
|
133 */ |
122 */ |
134 protected function setUp() |
123 protected function setUp() |
135 { |
124 { |
136 $this->bootstrap(); |
125 $this->bootstrap(); |
137 } |
126 } |
142 * Resets the front controller, and then bootstraps it. |
131 * Resets the front controller, and then bootstraps it. |
143 * |
132 * |
144 * If {@link $bootstrap} is a callback, executes it; if it is a file, it include's |
133 * If {@link $bootstrap} is a callback, executes it; if it is a file, it include's |
145 * it. When done, sets the test case request and response objects into the |
134 * it. When done, sets the test case request and response objects into the |
146 * front controller. |
135 * front controller. |
147 * |
|
148 * @return void |
|
149 */ |
136 */ |
150 final public function bootstrap() |
137 final public function bootstrap() |
151 { |
138 { |
152 $this->reset(); |
139 $this->reset(); |
153 if (null !== $this->bootstrap) { |
140 if (null !== $this->bootstrap) { |
174 * If a URL is provided, sets it as the request URI in the request object. |
161 * If a URL is provided, sets it as the request URI in the request object. |
175 * Then sets test case request and response objects in front controller, |
162 * Then sets test case request and response objects in front controller, |
176 * disables throwing exceptions, and disables returning the response. |
163 * disables throwing exceptions, and disables returning the response. |
177 * Finally, dispatches the front controller. |
164 * Finally, dispatches the front controller. |
178 * |
165 * |
179 * @param string|null $url |
166 * @param string|null $url |
180 * @return void |
|
181 */ |
167 */ |
182 public function dispatch($url = null) |
168 public function dispatch($url = null) |
183 { |
169 { |
184 // redirector should not exit |
170 // redirector should not exit |
185 $redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector'); |
171 $redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector'); |
214 * |
200 * |
215 * Creates new request/response objects, resets the front controller |
201 * Creates new request/response objects, resets the front controller |
216 * instance, and resets the action helper broker. |
202 * instance, and resets the action helper broker. |
217 * |
203 * |
218 * @todo Need to update Zend_Layout to add a resetInstance() method |
204 * @todo Need to update Zend_Layout to add a resetInstance() method |
219 * @return void |
|
220 */ |
205 */ |
221 public function reset() |
206 public function reset() |
222 { |
207 { |
223 $_SESSION = array(); |
208 $_SESSION = array(); |
224 $_GET = array(); |
209 $_GET = array(); |
232 Zend_Session::$_unitTestEnabled = true; |
217 Zend_Session::$_unitTestEnabled = true; |
233 } |
218 } |
234 |
219 |
235 /** |
220 /** |
236 * Rest all view placeholders |
221 * Rest all view placeholders |
237 * |
|
238 * @return void |
|
239 */ |
222 */ |
240 protected function _resetPlaceholders() |
223 protected function _resetPlaceholders() |
241 { |
224 { |
242 $registry = Zend_Registry::getInstance(); |
225 $registry = Zend_Registry::getInstance(); |
243 $remove = array(); |
226 $remove = array(); |
284 } |
267 } |
285 |
268 |
286 /** |
269 /** |
287 * Assert against DOM selection |
270 * Assert against DOM selection |
288 * |
271 * |
289 * @param string $path CSS selector path |
272 * @param string $path CSS selector path |
290 * @param string $message |
273 * @param string $message |
291 * @return void |
|
292 */ |
274 */ |
293 public function assertQuery($path, $message = '') |
275 public function assertQuery($path, $message = '') |
294 { |
276 { |
295 $this->_incrementAssertionCount(); |
277 $this->_incrementAssertionCount(); |
296 require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php'; |
278 require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php'; |
302 } |
284 } |
303 |
285 |
304 /** |
286 /** |
305 * Assert against DOM selection |
287 * Assert against DOM selection |
306 * |
288 * |
307 * @param string $path CSS selector path |
289 * @param string $path CSS selector path |
308 * @param string $message |
290 * @param string $message |
309 * @return void |
|
310 */ |
291 */ |
311 public function assertNotQuery($path, $message = '') |
292 public function assertNotQuery($path, $message = '') |
312 { |
293 { |
313 $this->_incrementAssertionCount(); |
294 $this->_incrementAssertionCount(); |
314 require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php'; |
295 require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php'; |
320 } |
301 } |
321 |
302 |
322 /** |
303 /** |
323 * Assert against DOM selection; node should contain content |
304 * Assert against DOM selection; node should contain content |
324 * |
305 * |
325 * @param string $path CSS selector path |
306 * @param string $path CSS selector path |
326 * @param string $match content that should be contained in matched nodes |
307 * @param string $match content that should be contained in matched nodes |
327 * @param string $message |
308 * @param string $message |
328 * @return void |
|
329 */ |
309 */ |
330 public function assertQueryContentContains($path, $match, $message = '') |
310 public function assertQueryContentContains($path, $match, $message = '') |
331 { |
311 { |
332 $this->_incrementAssertionCount(); |
312 $this->_incrementAssertionCount(); |
333 require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php'; |
313 require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php'; |
339 } |
319 } |
340 |
320 |
341 /** |
321 /** |
342 * Assert against DOM selection; node should NOT contain content |
322 * Assert against DOM selection; node should NOT contain content |
343 * |
323 * |
344 * @param string $path CSS selector path |
324 * @param string $path CSS selector path |
345 * @param string $match content that should NOT be contained in matched nodes |
325 * @param string $match content that should NOT be contained in matched nodes |
346 * @param string $message |
326 * @param string $message |
347 * @return void |
|
348 */ |
327 */ |
349 public function assertNotQueryContentContains($path, $match, $message = '') |
328 public function assertNotQueryContentContains($path, $match, $message = '') |
350 { |
329 { |
351 $this->_incrementAssertionCount(); |
330 $this->_incrementAssertionCount(); |
352 require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php'; |
331 require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php'; |
358 } |
337 } |
359 |
338 |
360 /** |
339 /** |
361 * Assert against DOM selection; node should match content |
340 * Assert against DOM selection; node should match content |
362 * |
341 * |
363 * @param string $path CSS selector path |
342 * @param string $path CSS selector path |
364 * @param string $pattern Pattern that should be contained in matched nodes |
343 * @param string $pattern Pattern that should be contained in matched nodes |
365 * @param string $message |
344 * @param string $message |
366 * @return void |
|
367 */ |
345 */ |
368 public function assertQueryContentRegex($path, $pattern, $message = '') |
346 public function assertQueryContentRegex($path, $pattern, $message = '') |
369 { |
347 { |
370 $this->_incrementAssertionCount(); |
348 $this->_incrementAssertionCount(); |
371 require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php'; |
349 require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php'; |
377 } |
355 } |
378 |
356 |
379 /** |
357 /** |
380 * Assert against DOM selection; node should NOT match content |
358 * Assert against DOM selection; node should NOT match content |
381 * |
359 * |
382 * @param string $path CSS selector path |
360 * @param string $path CSS selector path |
383 * @param string $pattern pattern that should NOT be contained in matched nodes |
361 * @param string $pattern pattern that should NOT be contained in matched nodes |
384 * @param string $message |
362 * @param string $message |
385 * @return void |
|
386 */ |
363 */ |
387 public function assertNotQueryContentRegex($path, $pattern, $message = '') |
364 public function assertNotQueryContentRegex($path, $pattern, $message = '') |
388 { |
365 { |
389 $this->_incrementAssertionCount(); |
366 $this->_incrementAssertionCount(); |
390 require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php'; |
367 require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php'; |
396 } |
373 } |
397 |
374 |
398 /** |
375 /** |
399 * Assert against DOM selection; should contain exact number of nodes |
376 * Assert against DOM selection; should contain exact number of nodes |
400 * |
377 * |
401 * @param string $path CSS selector path |
378 * @param string $path CSS selector path |
402 * @param string $count Number of nodes that should match |
379 * @param string $count Number of nodes that should match |
403 * @param string $message |
380 * @param string $message |
404 * @return void |
|
405 */ |
381 */ |
406 public function assertQueryCount($path, $count, $message = '') |
382 public function assertQueryCount($path, $count, $message = '') |
407 { |
383 { |
408 $this->_incrementAssertionCount(); |
384 $this->_incrementAssertionCount(); |
409 require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php'; |
385 require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php'; |
415 } |
391 } |
416 |
392 |
417 /** |
393 /** |
418 * Assert against DOM selection; should NOT contain exact number of nodes |
394 * Assert against DOM selection; should NOT contain exact number of nodes |
419 * |
395 * |
420 * @param string $path CSS selector path |
396 * @param string $path CSS selector path |
421 * @param string $count Number of nodes that should NOT match |
397 * @param string $count Number of nodes that should NOT match |
422 * @param string $message |
398 * @param string $message |
423 * @return void |
|
424 */ |
399 */ |
425 public function assertNotQueryCount($path, $count, $message = '') |
400 public function assertNotQueryCount($path, $count, $message = '') |
426 { |
401 { |
427 $this->_incrementAssertionCount(); |
402 $this->_incrementAssertionCount(); |
428 require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php'; |
403 require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php'; |
434 } |
409 } |
435 |
410 |
436 /** |
411 /** |
437 * Assert against DOM selection; should contain at least this number of nodes |
412 * Assert against DOM selection; should contain at least this number of nodes |
438 * |
413 * |
439 * @param string $path CSS selector path |
414 * @param string $path CSS selector path |
440 * @param string $count Minimum number of nodes that should match |
415 * @param string $count Minimum number of nodes that should match |
441 * @param string $message |
416 * @param string $message |
442 * @return void |
|
443 */ |
417 */ |
444 public function assertQueryCountMin($path, $count, $message = '') |
418 public function assertQueryCountMin($path, $count, $message = '') |
445 { |
419 { |
446 $this->_incrementAssertionCount(); |
420 $this->_incrementAssertionCount(); |
447 require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php'; |
421 require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php'; |
453 } |
427 } |
454 |
428 |
455 /** |
429 /** |
456 * Assert against DOM selection; should contain no more than this number of nodes |
430 * Assert against DOM selection; should contain no more than this number of nodes |
457 * |
431 * |
458 * @param string $path CSS selector path |
432 * @param string $path CSS selector path |
459 * @param string $count Maximum number of nodes that should match |
433 * @param string $count Maximum number of nodes that should match |
460 * @param string $message |
434 * @param string $message |
461 * @return void |
|
462 */ |
435 */ |
463 public function assertQueryCountMax($path, $count, $message = '') |
436 public function assertQueryCountMax($path, $count, $message = '') |
464 { |
437 { |
465 $this->_incrementAssertionCount(); |
438 $this->_incrementAssertionCount(); |
466 require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php'; |
439 require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php'; |
472 } |
445 } |
473 |
446 |
474 /** |
447 /** |
475 * Register XPath namespaces |
448 * Register XPath namespaces |
476 * |
449 * |
477 * @param array $xpathNamespaces |
450 * @param array $xpathNamespaces |
478 * @return void |
|
479 */ |
451 */ |
480 public function registerXpathNamespaces($xpathNamespaces) |
452 public function registerXpathNamespaces($xpathNamespaces) |
481 { |
453 { |
482 $this->_xpathNamespaces = $xpathNamespaces; |
454 $this->_xpathNamespaces = $xpathNamespaces; |
483 } |
455 } |
484 |
456 |
485 /** |
457 /** |
486 * Assert against XPath selection |
458 * Assert against XPath selection |
487 * |
459 * |
488 * @param string $path XPath path |
460 * @param string $path XPath path |
489 * @param string $message |
461 * @param string $message |
490 * @return void |
|
491 */ |
462 */ |
492 public function assertXpath($path, $message = '') |
463 public function assertXpath($path, $message = '') |
493 { |
464 { |
494 $this->_incrementAssertionCount(); |
465 $this->_incrementAssertionCount(); |
495 require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php'; |
466 require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php'; |
502 } |
473 } |
503 |
474 |
504 /** |
475 /** |
505 * Assert against XPath selection |
476 * Assert against XPath selection |
506 * |
477 * |
507 * @param string $path XPath path |
478 * @param string $path XPath path |
508 * @param string $message |
479 * @param string $message |
509 * @return void |
|
510 */ |
480 */ |
511 public function assertNotXpath($path, $message = '') |
481 public function assertNotXpath($path, $message = '') |
512 { |
482 { |
513 $this->_incrementAssertionCount(); |
483 $this->_incrementAssertionCount(); |
514 require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php'; |
484 require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php'; |
521 } |
491 } |
522 |
492 |
523 /** |
493 /** |
524 * Assert against XPath selection; node should contain content |
494 * Assert against XPath selection; node should contain content |
525 * |
495 * |
526 * @param string $path XPath path |
496 * @param string $path XPath path |
527 * @param string $match content that should be contained in matched nodes |
497 * @param string $match content that should be contained in matched nodes |
528 * @param string $message |
498 * @param string $message |
529 * @return void |
|
530 */ |
499 */ |
531 public function assertXpathContentContains($path, $match, $message = '') |
500 public function assertXpathContentContains($path, $match, $message = '') |
532 { |
501 { |
533 $this->_incrementAssertionCount(); |
502 $this->_incrementAssertionCount(); |
534 require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php'; |
503 require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php'; |
541 } |
510 } |
542 |
511 |
543 /** |
512 /** |
544 * Assert against XPath selection; node should NOT contain content |
513 * Assert against XPath selection; node should NOT contain content |
545 * |
514 * |
546 * @param string $path XPath path |
515 * @param string $path XPath path |
547 * @param string $match content that should NOT be contained in matched nodes |
516 * @param string $match content that should NOT be contained in matched nodes |
548 * @param string $message |
517 * @param string $message |
549 * @return void |
|
550 */ |
518 */ |
551 public function assertNotXpathContentContains($path, $match, $message = '') |
519 public function assertNotXpathContentContains($path, $match, $message = '') |
552 { |
520 { |
553 $this->_incrementAssertionCount(); |
521 $this->_incrementAssertionCount(); |
554 require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php'; |
522 require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php'; |
561 } |
529 } |
562 |
530 |
563 /** |
531 /** |
564 * Assert against XPath selection; node should match content |
532 * Assert against XPath selection; node should match content |
565 * |
533 * |
566 * @param string $path XPath path |
534 * @param string $path XPath path |
567 * @param string $pattern Pattern that should be contained in matched nodes |
535 * @param string $pattern Pattern that should be contained in matched nodes |
568 * @param string $message |
536 * @param string $message |
569 * @return void |
|
570 */ |
537 */ |
571 public function assertXpathContentRegex($path, $pattern, $message = '') |
538 public function assertXpathContentRegex($path, $pattern, $message = '') |
572 { |
539 { |
573 $this->_incrementAssertionCount(); |
540 $this->_incrementAssertionCount(); |
574 require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php'; |
541 require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php'; |
581 } |
548 } |
582 |
549 |
583 /** |
550 /** |
584 * Assert against XPath selection; node should NOT match content |
551 * Assert against XPath selection; node should NOT match content |
585 * |
552 * |
586 * @param string $path XPath path |
553 * @param string $path XPath path |
587 * @param string $pattern pattern that should NOT be contained in matched nodes |
554 * @param string $pattern pattern that should NOT be contained in matched nodes |
588 * @param string $message |
555 * @param string $message |
589 * @return void |
|
590 */ |
556 */ |
591 public function assertNotXpathContentRegex($path, $pattern, $message = '') |
557 public function assertNotXpathContentRegex($path, $pattern, $message = '') |
592 { |
558 { |
593 $this->_incrementAssertionCount(); |
559 $this->_incrementAssertionCount(); |
594 require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php'; |
560 require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php'; |
601 } |
567 } |
602 |
568 |
603 /** |
569 /** |
604 * Assert against XPath selection; should contain exact number of nodes |
570 * Assert against XPath selection; should contain exact number of nodes |
605 * |
571 * |
606 * @param string $path XPath path |
572 * @param string $path XPath path |
607 * @param string $count Number of nodes that should match |
573 * @param string $count Number of nodes that should match |
608 * @param string $message |
574 * @param string $message |
609 * @return void |
|
610 */ |
575 */ |
611 public function assertXpathCount($path, $count, $message = '') |
576 public function assertXpathCount($path, $count, $message = '') |
612 { |
577 { |
613 $this->_incrementAssertionCount(); |
578 $this->_incrementAssertionCount(); |
614 require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php'; |
579 require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php'; |
621 } |
586 } |
622 |
587 |
623 /** |
588 /** |
624 * Assert against XPath selection; should NOT contain exact number of nodes |
589 * Assert against XPath selection; should NOT contain exact number of nodes |
625 * |
590 * |
626 * @param string $path XPath path |
591 * @param string $path XPath path |
627 * @param string $count Number of nodes that should NOT match |
592 * @param string $count Number of nodes that should NOT match |
628 * @param string $message |
593 * @param string $message |
629 * @return void |
|
630 */ |
594 */ |
631 public function assertNotXpathCount($path, $count, $message = '') |
595 public function assertNotXpathCount($path, $count, $message = '') |
632 { |
596 { |
633 $this->_incrementAssertionCount(); |
597 $this->_incrementAssertionCount(); |
634 require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php'; |
598 require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php'; |
641 } |
605 } |
642 |
606 |
643 /** |
607 /** |
644 * Assert against XPath selection; should contain at least this number of nodes |
608 * Assert against XPath selection; should contain at least this number of nodes |
645 * |
609 * |
646 * @param string $path XPath path |
610 * @param string $path XPath path |
647 * @param string $count Minimum number of nodes that should match |
611 * @param string $count Minimum number of nodes that should match |
648 * @param string $message |
612 * @param string $message |
649 * @return void |
|
650 */ |
613 */ |
651 public function assertXpathCountMin($path, $count, $message = '') |
614 public function assertXpathCountMin($path, $count, $message = '') |
652 { |
615 { |
653 $this->_incrementAssertionCount(); |
616 $this->_incrementAssertionCount(); |
654 require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php'; |
617 require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php'; |
661 } |
624 } |
662 |
625 |
663 /** |
626 /** |
664 * Assert against XPath selection; should contain no more than this number of nodes |
627 * Assert against XPath selection; should contain no more than this number of nodes |
665 * |
628 * |
666 * @param string $path XPath path |
629 * @param string $path XPath path |
667 * @param string $count Maximum number of nodes that should match |
630 * @param string $count Maximum number of nodes that should match |
668 * @param string $message |
631 * @param string $message |
669 * @return void |
|
670 */ |
632 */ |
671 public function assertXpathCountMax($path, $count, $message = '') |
633 public function assertXpathCountMax($path, $count, $message = '') |
672 { |
634 { |
673 $this->_incrementAssertionCount(); |
635 $this->_incrementAssertionCount(); |
674 require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php'; |
636 require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php'; |
681 } |
643 } |
682 |
644 |
683 /** |
645 /** |
684 * Assert that response is a redirect |
646 * Assert that response is a redirect |
685 * |
647 * |
686 * @param string $message |
648 * @param string $message |
687 * @return void |
|
688 */ |
649 */ |
689 public function assertRedirect($message = '') |
650 public function assertRedirect($message = '') |
690 { |
651 { |
691 $this->_incrementAssertionCount(); |
652 $this->_incrementAssertionCount(); |
692 require_once 'Zend/Test/PHPUnit/Constraint/Redirect.php'; |
653 require_once 'Zend/Test/PHPUnit/Constraint/Redirect.php'; |
698 } |
659 } |
699 |
660 |
700 /** |
661 /** |
701 * Assert that response is NOT a redirect |
662 * Assert that response is NOT a redirect |
702 * |
663 * |
703 * @param string $message |
664 * @param string $message |
704 * @return void |
|
705 */ |
665 */ |
706 public function assertNotRedirect($message = '') |
666 public function assertNotRedirect($message = '') |
707 { |
667 { |
708 $this->_incrementAssertionCount(); |
668 $this->_incrementAssertionCount(); |
709 require_once 'Zend/Test/PHPUnit/Constraint/Redirect.php'; |
669 require_once 'Zend/Test/PHPUnit/Constraint/Redirect.php'; |
715 } |
675 } |
716 |
676 |
717 /** |
677 /** |
718 * Assert that response redirects to given URL |
678 * Assert that response redirects to given URL |
719 * |
679 * |
720 * @param string $url |
680 * @param string $url |
721 * @param string $message |
681 * @param string $message |
722 * @return void |
|
723 */ |
682 */ |
724 public function assertRedirectTo($url, $message = '') |
683 public function assertRedirectTo($url, $message = '') |
725 { |
684 { |
726 $this->_incrementAssertionCount(); |
685 $this->_incrementAssertionCount(); |
727 require_once 'Zend/Test/PHPUnit/Constraint/Redirect.php'; |
686 require_once 'Zend/Test/PHPUnit/Constraint/Redirect.php'; |
733 } |
692 } |
734 |
693 |
735 /** |
694 /** |
736 * Assert that response does not redirect to given URL |
695 * Assert that response does not redirect to given URL |
737 * |
696 * |
738 * @param string $url |
697 * @param string $url |
739 * @param string $message |
698 * @param string $message |
740 * @return void |
|
741 */ |
699 */ |
742 public function assertNotRedirectTo($url, $message = '') |
700 public function assertNotRedirectTo($url, $message = '') |
743 { |
701 { |
744 $this->_incrementAssertionCount(); |
702 $this->_incrementAssertionCount(); |
745 require_once 'Zend/Test/PHPUnit/Constraint/Redirect.php'; |
703 require_once 'Zend/Test/PHPUnit/Constraint/Redirect.php'; |
751 } |
709 } |
752 |
710 |
753 /** |
711 /** |
754 * Assert that redirect location matches pattern |
712 * Assert that redirect location matches pattern |
755 * |
713 * |
756 * @param string $pattern |
714 * @param string $pattern |
757 * @param string $message |
715 * @param string $message |
758 * @return void |
|
759 */ |
716 */ |
760 public function assertRedirectRegex($pattern, $message = '') |
717 public function assertRedirectRegex($pattern, $message = '') |
761 { |
718 { |
762 $this->_incrementAssertionCount(); |
719 $this->_incrementAssertionCount(); |
763 require_once 'Zend/Test/PHPUnit/Constraint/Redirect.php'; |
720 require_once 'Zend/Test/PHPUnit/Constraint/Redirect.php'; |
769 } |
726 } |
770 |
727 |
771 /** |
728 /** |
772 * Assert that redirect location does not match pattern |
729 * Assert that redirect location does not match pattern |
773 * |
730 * |
774 * @param string $pattern |
731 * @param string $pattern |
775 * @param string $message |
732 * @param string $message |
776 * @return void |
|
777 */ |
733 */ |
778 public function assertNotRedirectRegex($pattern, $message = '') |
734 public function assertNotRedirectRegex($pattern, $message = '') |
779 { |
735 { |
780 $this->_incrementAssertionCount(); |
736 $this->_incrementAssertionCount(); |
781 require_once 'Zend/Test/PHPUnit/Constraint/Redirect.php'; |
737 require_once 'Zend/Test/PHPUnit/Constraint/Redirect.php'; |
787 } |
743 } |
788 |
744 |
789 /** |
745 /** |
790 * Assert response code |
746 * Assert response code |
791 * |
747 * |
792 * @param int $code |
748 * @param int $code |
793 * @param string $message |
749 * @param string $message |
794 * @return void |
|
795 */ |
750 */ |
796 public function assertResponseCode($code, $message = '') |
751 public function assertResponseCode($code, $message = '') |
797 { |
752 { |
798 $this->_incrementAssertionCount(); |
753 $this->_incrementAssertionCount(); |
799 require_once 'Zend/Test/PHPUnit/Constraint/ResponseHeader.php'; |
754 require_once 'Zend/Test/PHPUnit/Constraint/ResponseHeader.php'; |
805 } |
760 } |
806 |
761 |
807 /** |
762 /** |
808 * Assert response code |
763 * Assert response code |
809 * |
764 * |
810 * @param int $code |
765 * @param int $code |
811 * @param string $message |
766 * @param string $message |
812 * @return void |
|
813 */ |
767 */ |
814 public function assertNotResponseCode($code, $message = '') |
768 public function assertNotResponseCode($code, $message = '') |
815 { |
769 { |
816 $this->_incrementAssertionCount(); |
770 $this->_incrementAssertionCount(); |
817 require_once 'Zend/Test/PHPUnit/Constraint/ResponseHeader.php'; |
771 require_once 'Zend/Test/PHPUnit/Constraint/ResponseHeader.php'; |
824 } |
778 } |
825 |
779 |
826 /** |
780 /** |
827 * Assert response header exists |
781 * Assert response header exists |
828 * |
782 * |
829 * @param string $header |
783 * @param string $header |
830 * @param string $message |
784 * @param string $message |
831 * @return void |
|
832 */ |
785 */ |
833 public function assertHeader($header, $message = '') |
786 public function assertHeader($header, $message = '') |
834 { |
787 { |
835 $this->_incrementAssertionCount(); |
788 $this->_incrementAssertionCount(); |
836 require_once 'Zend/Test/PHPUnit/Constraint/ResponseHeader.php'; |
789 require_once 'Zend/Test/PHPUnit/Constraint/ResponseHeader.php'; |
842 } |
795 } |
843 |
796 |
844 /** |
797 /** |
845 * Assert response header does not exist |
798 * Assert response header does not exist |
846 * |
799 * |
847 * @param string $header |
800 * @param string $header |
848 * @param string $message |
801 * @param string $message |
849 * @return void |
|
850 */ |
802 */ |
851 public function assertNotHeader($header, $message = '') |
803 public function assertNotHeader($header, $message = '') |
852 { |
804 { |
853 $this->_incrementAssertionCount(); |
805 $this->_incrementAssertionCount(); |
854 require_once 'Zend/Test/PHPUnit/Constraint/ResponseHeader.php'; |
806 require_once 'Zend/Test/PHPUnit/Constraint/ResponseHeader.php'; |
861 } |
813 } |
862 |
814 |
863 /** |
815 /** |
864 * Assert response header exists and contains the given string |
816 * Assert response header exists and contains the given string |
865 * |
817 * |
866 * @param string $header |
818 * @param string $header |
867 * @param string $match |
819 * @param string $match |
868 * @param string $message |
820 * @param string $message |
869 * @return void |
|
870 */ |
821 */ |
871 public function assertHeaderContains($header, $match, $message = '') |
822 public function assertHeaderContains($header, $match, $message = '') |
872 { |
823 { |
873 $this->_incrementAssertionCount(); |
824 $this->_incrementAssertionCount(); |
874 require_once 'Zend/Test/PHPUnit/Constraint/ResponseHeader.php'; |
825 require_once 'Zend/Test/PHPUnit/Constraint/ResponseHeader.php'; |
880 } |
831 } |
881 |
832 |
882 /** |
833 /** |
883 * Assert response header does not exist and/or does not contain the given string |
834 * Assert response header does not exist and/or does not contain the given string |
884 * |
835 * |
885 * @param string $header |
836 * @param string $header |
886 * @param string $match |
837 * @param string $match |
887 * @param string $message |
838 * @param string $message |
888 * @return void |
|
889 */ |
839 */ |
890 public function assertNotHeaderContains($header, $match, $message = '') |
840 public function assertNotHeaderContains($header, $match, $message = '') |
891 { |
841 { |
892 $this->_incrementAssertionCount(); |
842 $this->_incrementAssertionCount(); |
893 require_once 'Zend/Test/PHPUnit/Constraint/ResponseHeader.php'; |
843 require_once 'Zend/Test/PHPUnit/Constraint/ResponseHeader.php'; |
900 } |
850 } |
901 |
851 |
902 /** |
852 /** |
903 * Assert response header exists and matches the given pattern |
853 * Assert response header exists and matches the given pattern |
904 * |
854 * |
905 * @param string $header |
855 * @param string $header |
906 * @param string $pattern |
856 * @param string $pattern |
907 * @param string $message |
857 * @param string $message |
908 * @return void |
|
909 */ |
858 */ |
910 public function assertHeaderRegex($header, $pattern, $message = '') |
859 public function assertHeaderRegex($header, $pattern, $message = '') |
911 { |
860 { |
912 $this->_incrementAssertionCount(); |
861 $this->_incrementAssertionCount(); |
913 require_once 'Zend/Test/PHPUnit/Constraint/ResponseHeader.php'; |
862 require_once 'Zend/Test/PHPUnit/Constraint/ResponseHeader.php'; |
919 } |
868 } |
920 |
869 |
921 /** |
870 /** |
922 * Assert response header does not exist and/or does not match the given regex |
871 * Assert response header does not exist and/or does not match the given regex |
923 * |
872 * |
924 * @param string $header |
873 * @param string $header |
925 * @param string $pattern |
874 * @param string $pattern |
926 * @param string $message |
875 * @param string $message |
927 * @return void |
|
928 */ |
876 */ |
929 public function assertNotHeaderRegex($header, $pattern, $message = '') |
877 public function assertNotHeaderRegex($header, $pattern, $message = '') |
930 { |
878 { |
931 $this->_incrementAssertionCount(); |
879 $this->_incrementAssertionCount(); |
932 require_once 'Zend/Test/PHPUnit/Constraint/ResponseHeader.php'; |
880 require_once 'Zend/Test/PHPUnit/Constraint/ResponseHeader.php'; |
939 } |
887 } |
940 |
888 |
941 /** |
889 /** |
942 * Assert that the last handled request used the given module |
890 * Assert that the last handled request used the given module |
943 * |
891 * |
944 * @param string $module |
892 * @param string $module |
945 * @param string $message |
893 * @param string $message |
946 * @return void |
|
947 */ |
894 */ |
948 public function assertModule($module, $message = '') |
895 public function assertModule($module, $message = '') |
949 { |
896 { |
950 $this->_incrementAssertionCount(); |
897 $this->_incrementAssertionCount(); |
951 if ($module != $this->request->getModuleName()) { |
898 if ($module != $this->request->getModuleName()) { |
961 } |
908 } |
962 |
909 |
963 /** |
910 /** |
964 * Assert that the last handled request did NOT use the given module |
911 * Assert that the last handled request did NOT use the given module |
965 * |
912 * |
966 * @param string $module |
913 * @param string $module |
967 * @param string $message |
914 * @param string $message |
968 * @return void |
|
969 */ |
915 */ |
970 public function assertNotModule($module, $message = '') |
916 public function assertNotModule($module, $message = '') |
971 { |
917 { |
972 $this->_incrementAssertionCount(); |
918 $this->_incrementAssertionCount(); |
973 if ($module == $this->request->getModuleName()) { |
919 if ($module == $this->request->getModuleName()) { |
980 } |
926 } |
981 |
927 |
982 /** |
928 /** |
983 * Assert that the last handled request used the given controller |
929 * Assert that the last handled request used the given controller |
984 * |
930 * |
985 * @param string $controller |
931 * @param string $controller |
986 * @param string $message |
932 * @param string $message |
987 * @return void |
|
988 */ |
933 */ |
989 public function assertController($controller, $message = '') |
934 public function assertController($controller, $message = '') |
990 { |
935 { |
991 $this->_incrementAssertionCount(); |
936 $this->_incrementAssertionCount(); |
992 if ($controller != $this->request->getControllerName()) { |
937 if ($controller != $this->request->getControllerName()) { |
1004 /** |
949 /** |
1005 * Assert that the last handled request did NOT use the given controller |
950 * Assert that the last handled request did NOT use the given controller |
1006 * |
951 * |
1007 * @param string $controller |
952 * @param string $controller |
1008 * @param string $message |
953 * @param string $message |
1009 * @return void |
|
1010 */ |
954 */ |
1011 public function assertNotController($controller, $message = '') |
955 public function assertNotController($controller, $message = '') |
1012 { |
956 { |
1013 $this->_incrementAssertionCount(); |
957 $this->_incrementAssertionCount(); |
1014 if ($controller == $this->request->getControllerName()) { |
958 if ($controller == $this->request->getControllerName()) { |
1024 } |
968 } |
1025 |
969 |
1026 /** |
970 /** |
1027 * Assert that the last handled request used the given action |
971 * Assert that the last handled request used the given action |
1028 * |
972 * |
1029 * @param string $action |
973 * @param string $action |
1030 * @param string $message |
974 * @param string $message |
1031 * @return void |
|
1032 */ |
975 */ |
1033 public function assertAction($action, $message = '') |
976 public function assertAction($action, $message = '') |
1034 { |
977 { |
1035 $this->_incrementAssertionCount(); |
978 $this->_incrementAssertionCount(); |
1036 if ($action != $this->request->getActionName()) { |
979 if ($action != $this->request->getActionName()) { |
1043 } |
986 } |
1044 |
987 |
1045 /** |
988 /** |
1046 * Assert that the last handled request did NOT use the given action |
989 * Assert that the last handled request did NOT use the given action |
1047 * |
990 * |
1048 * @param string $action |
991 * @param string $action |
1049 * @param string $message |
992 * @param string $message |
1050 * @return void |
|
1051 */ |
993 */ |
1052 public function assertNotAction($action, $message = '') |
994 public function assertNotAction($action, $message = '') |
1053 { |
995 { |
1054 $this->_incrementAssertionCount(); |
996 $this->_incrementAssertionCount(); |
1055 if ($action == $this->request->getActionName()) { |
997 if ($action == $this->request->getActionName()) { |
1062 } |
1004 } |
1063 |
1005 |
1064 /** |
1006 /** |
1065 * Assert that the specified route was used |
1007 * Assert that the specified route was used |
1066 * |
1008 * |
1067 * @param string $route |
1009 * @param string $route |
1068 * @param string $message |
1010 * @param string $message |
1069 * @return void |
|
1070 */ |
1011 */ |
1071 public function assertRoute($route, $message = '') |
1012 public function assertRoute($route, $message = '') |
1072 { |
1013 { |
1073 $this->_incrementAssertionCount(); |
1014 $this->_incrementAssertionCount(); |
1074 $router = $this->frontController->getRouter(); |
1015 $router = $this->frontController->getRouter(); |
1085 } |
1026 } |
1086 |
1027 |
1087 /** |
1028 /** |
1088 * Assert that the route matched is NOT as specified |
1029 * Assert that the route matched is NOT as specified |
1089 * |
1030 * |
1090 * @param string $route |
1031 * @param string $route |
1091 * @param string $message |
1032 * @param string $message |
1092 * @return void |
|
1093 */ |
1033 */ |
1094 public function assertNotRoute($route, $message = '') |
1034 public function assertNotRoute($route, $message = '') |
1095 { |
1035 { |
1096 $this->_incrementAssertionCount(); |
1036 $this->_incrementAssertionCount(); |
1097 $router = $this->frontController->getRouter(); |
1037 $router = $this->frontController->getRouter(); |
1156 require_once 'Zend/Dom/Query.php'; |
1096 require_once 'Zend/Dom/Query.php'; |
1157 $this->_query = new Zend_Dom_Query; |
1097 $this->_query = new Zend_Dom_Query; |
1158 } |
1098 } |
1159 return $this->_query; |
1099 return $this->_query; |
1160 } |
1100 } |
1161 |
1101 |
1162 /** |
1102 /** |
1163 * URL Helper |
1103 * URL Helper |
1164 * |
1104 * |
1165 * @param array $urlOptions |
1105 * @param array $urlOptions |
1166 * @param string $name |
1106 * @param string $name |
1167 * @param bool $reset |
1107 * @param bool $reset |
1168 * @param bool $encode |
1108 * @param bool $encode |
|
1109 * @throws Exception |
|
1110 * @throws Zend_Controller_Router_Exception |
|
1111 * @return string |
1169 */ |
1112 */ |
1170 public function url($urlOptions = array(), $name = null, $reset = false, $encode = true) |
1113 public function url($urlOptions = array(), $name = null, $reset = false, $encode = true) |
1171 { |
1114 { |
1172 $frontController = $this->getFrontController(); |
1115 $frontController = $this->getFrontController(); |
1173 $router = $frontController->getRouter(); |
1116 $router = $frontController->getRouter(); |
1177 if (count($router->getRoutes()) == 0) { |
1120 if (count($router->getRoutes()) == 0) { |
1178 $router->addDefaultRoutes(); |
1121 $router->addDefaultRoutes(); |
1179 } |
1122 } |
1180 return $router->assemble($urlOptions, $name, $reset, $encode); |
1123 return $router->assemble($urlOptions, $name, $reset, $encode); |
1181 } |
1124 } |
1182 |
1125 |
|
1126 /** |
|
1127 * Urlize options |
|
1128 * |
|
1129 * @param array $urlOptions |
|
1130 * @param bool $actionControllerModuleOnly |
|
1131 * @return mixed |
|
1132 */ |
1183 public function urlizeOptions($urlOptions, $actionControllerModuleOnly = true) |
1133 public function urlizeOptions($urlOptions, $actionControllerModuleOnly = true) |
1184 { |
1134 { |
1185 $ccToDash = new Zend_Filter_Word_CamelCaseToDash(); |
1135 $ccToDash = new Zend_Filter_Word_CamelCaseToDash(); |
1186 foreach ($urlOptions as $n => $v) { |
1136 foreach ($urlOptions as $n => $v) { |
1187 if (in_array($n, array('action', 'controller', 'module'))) { |
1137 if (in_array($n, array('action', 'controller', 'module'))) { |
1191 return $urlOptions; |
1141 return $urlOptions; |
1192 } |
1142 } |
1193 |
1143 |
1194 /** |
1144 /** |
1195 * Increment assertion count |
1145 * Increment assertion count |
1196 * |
|
1197 * @return void |
|
1198 */ |
1146 */ |
1199 protected function _incrementAssertionCount() |
1147 protected function _incrementAssertionCount() |
1200 { |
1148 { |
1201 $stack = debug_backtrace(); |
1149 $stack = debug_backtrace(); |
1202 foreach (debug_backtrace() as $step) { |
1150 foreach ($stack as $step) { |
1203 if (isset($step['object']) |
1151 if (isset($step['object']) |
1204 && $step['object'] instanceof PHPUnit_Framework_TestCase |
1152 && $step['object'] instanceof PHPUnit_Framework_TestCase |
1205 ) { |
1153 ) { |
1206 if (version_compare(PHPUnit_Runner_Version::id(), '3.3.0', 'lt')) { |
1154 if (version_compare(PHPUnit_Runner_Version::id(), '3.3.0', 'lt')) { |
1207 break; |
1155 break; |