3
/** PHPUnit_Framework_TestCase */
4
require_once 'PHPUnit/Framework/TestCase.php';
6
/** PHPUnit_Runner_Version */
7
require_once 'PHPUnit/Runner/Version.php';
9
/** Zend_Controller_Front */
10
require_once 'Zend/Controller/Front.php';
12
/** Zend_Controller_Action_HelperBroker */
13
require_once 'Zend/Controller/Action/HelperBroker.php';
16
require_once 'Zend/Layout.php';
19
require_once 'Zend/Session.php';
22
require_once 'Zend/Registry.php';
25
* Functional testing scaffold for MVC applications
27
* @uses PHPUnit_Framework_TestCase
30
* @copyright Copyright (C) 2008 - Present, Zend Technologies, Inc.
31
* @license New BSD {@link http://framework.zend.com/license/new-bsd}
33
abstract class Zend_Test_PHPUnit_ControllerTestCase extends PHPUnit_Framework_TestCase
36
* @var mixed Bootstrap file path or callback
41
* @var Zend_Controller_Front
43
protected $_frontController;
51
* @var Zend_Controller_Request_Abstract
56
* @var Zend_Controller_Response_Abstract
61
* Overlaoding: prevent overloading to special properties
67
public function __set($name, $value)
69
if (in_array($name, array('request', 'response', 'frontController'))) {
70
throw new Zend_Exception(sprintf('Setting %s object manually is not allowed', $name));
72
$this->$name = $value;
76
* Overloading for common properties
78
* Provides overloading for request, response, and frontController objects.
83
public function __get($name)
87
return $this->getRequest();
89
return $this->getResponse();
90
case 'frontController':
91
return $this->getFrontController();
100
* Calls {@link bootstrap()} by default
104
protected function setUp()
110
* Bootstrap the front controller
112
* Resets the front controller, and then bootstraps it.
114
* If {@link $bootstrap} is a callback, executes it; if it is a file, it include's
115
* it. When done, sets the test case request and response objects into the
120
final public function bootstrap()
123
if (null !== $this->bootstrap) {
124
if (is_callable($this->bootstrap)) {
125
call_user_func($this->bootstrap);
126
} elseif (is_string($this->bootstrap)) {
127
require_once 'Zend/Loader.php';
128
if (Zend_Loader::isReadable($this->bootstrap)) {
129
include $this->bootstrap;
133
$this->frontController
134
->setRequest($this->getRequest())
135
->setResponse($this->getResponse());
141
* If a URL is provided, sets it as the request URI in the request object.
142
* Then sets test case request and response objects in front controller,
143
* disables throwing exceptions, and disables returning the response.
144
* Finally, dispatches the front controller.
146
* @param string|null $url
149
public function dispatch($url = null)
151
// redirector should not exit
152
$redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector');
153
$redirector->setExit(false);
155
// json helper should not exit
156
$json = Zend_Controller_Action_HelperBroker::getStaticHelper('json');
157
$json->suppressExit = true;
159
$request = $this->getRequest();
161
$request->setRequestUri($url);
163
$request->setPathInfo(null);
164
$controller = $this->getFrontController();
165
$this->frontController
166
->setRequest($request)
167
->setResponse($this->getResponse())
168
->throwExceptions(false)
169
->returnResponse(false);
170
$this->frontController->dispatch();
176
* Creates new request/response objects, resets the front controller
177
* instance, and resets the action helper broker.
179
* @todo Need to update Zend_Layout to add a resetInstance() method
182
public function reset()
188
$this->resetRequest();
189
$this->resetResponse();
190
Zend_Layout::resetMvcInstance();
191
Zend_Controller_Action_HelperBroker::resetHelpers();
192
$this->frontController->resetInstance();
193
Zend_Session::$_unitTestEnabled = true;
197
* Rest all view placeholders
201
protected function _resetPlaceholders()
203
$registry = Zend_Registry::getInstance();
205
foreach ($registry as $key => $value) {
206
if (strstr($key, '_View_')) {
211
foreach ($remove as $key) {
212
unset($registry[$key]);
217
* Reset the request object
219
* Useful for test cases that need to test multiple trips to the server.
221
* @return Zend_Test_PHPUnit_ControllerTestCase
223
public function resetRequest()
225
$this->_request = null;
230
* Reset the response object
232
* Useful for test cases that need to test multiple trips to the server.
234
* @return Zend_Test_PHPUnit_ControllerTestCase
236
public function resetResponse()
238
$this->_response = null;
239
$this->_resetPlaceholders();
244
* Assert against DOM selection
246
* @param string $path CSS selector path
247
* @param string $message
250
public function assertQuery($path, $message = '')
252
$this->_incrementAssertionCount();
253
require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php';
254
$constraint = new Zend_Test_PHPUnit_Constraint_DomQuery($path);
255
$content = $this->response->outputBody();
256
if (!$constraint->evaluate($content, __FUNCTION__)) {
257
$constraint->fail($path, $message);
262
* Assert against DOM selection
264
* @param string $path CSS selector path
265
* @param string $message
268
public function assertNotQuery($path, $message = '')
270
$this->_incrementAssertionCount();
271
require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php';
272
$constraint = new Zend_Test_PHPUnit_Constraint_DomQuery($path);
273
$content = $this->response->outputBody();
274
if (!$constraint->evaluate($content, __FUNCTION__)) {
275
$constraint->fail($path, $message);
280
* Assert against DOM selection; node should contain content
282
* @param string $path CSS selector path
283
* @param string $match content that should be contained in matched nodes
284
* @param string $message
287
public function assertQueryContentContains($path, $match, $message = '')
289
$this->_incrementAssertionCount();
290
require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php';
291
$constraint = new Zend_Test_PHPUnit_Constraint_DomQuery($path);
292
$content = $this->response->outputBody();
293
if (!$constraint->evaluate($content, __FUNCTION__, $match)) {
294
$constraint->fail($path, $message);
299
* Assert against DOM selection; node should NOT contain content
301
* @param string $path CSS selector path
302
* @param string $match content that should NOT be contained in matched nodes
303
* @param string $message
306
public function assertNotQueryContentContains($path, $match, $message = '')
308
$this->_incrementAssertionCount();
309
require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php';
310
$constraint = new Zend_Test_PHPUnit_Constraint_DomQuery($path);
311
$content = $this->response->outputBody();
312
if (!$constraint->evaluate($content, __FUNCTION__, $match)) {
313
$constraint->fail($path, $message);
318
* Assert against DOM selection; node should match content
320
* @param string $path CSS selector path
321
* @param string $pattern Pattern that should be contained in matched nodes
322
* @param string $message
325
public function assertQueryContentRegex($path, $pattern, $message = '')
327
$this->_incrementAssertionCount();
328
require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php';
329
$constraint = new Zend_Test_PHPUnit_Constraint_DomQuery($path);
330
$content = $this->response->outputBody();
331
if (!$constraint->evaluate($content, __FUNCTION__, $pattern)) {
332
$constraint->fail($path, $message);
337
* Assert against DOM selection; node should NOT match content
339
* @param string $path CSS selector path
340
* @param string $pattern pattern that should NOT be contained in matched nodes
341
* @param string $message
344
public function assertNotQueryContentRegex($path, $pattern, $message = '')
346
$this->_incrementAssertionCount();
347
require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php';
348
$constraint = new Zend_Test_PHPUnit_Constraint_DomQuery($path);
349
$content = $this->response->outputBody();
350
if (!$constraint->evaluate($content, __FUNCTION__, $pattern)) {
351
$constraint->fail($path, $message);
356
* Assert against DOM selection; should contain exact number of nodes
358
* @param string $path CSS selector path
359
* @param string $count Number of nodes that should match
360
* @param string $message
363
public function assertQueryCount($path, $count, $message = '')
365
$this->_incrementAssertionCount();
366
require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php';
367
$constraint = new Zend_Test_PHPUnit_Constraint_DomQuery($path);
368
$content = $this->response->outputBody();
369
if (!$constraint->evaluate($content, __FUNCTION__, $count)) {
370
$constraint->fail($path, $message);
375
* Assert against DOM selection; should NOT contain exact number of nodes
377
* @param string $path CSS selector path
378
* @param string $count Number of nodes that should NOT match
379
* @param string $message
382
public function assertNotQueryCount($path, $count, $message = '')
384
$this->_incrementAssertionCount();
385
require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php';
386
$constraint = new Zend_Test_PHPUnit_Constraint_DomQuery($path);
387
$content = $this->response->outputBody();
388
if (!$constraint->evaluate($content, __FUNCTION__, $count)) {
389
$constraint->fail($path, $message);
394
* Assert against DOM selection; should contain at least this number of nodes
396
* @param string $path CSS selector path
397
* @param string $count Minimum number of nodes that should match
398
* @param string $message
401
public function assertQueryCountMin($path, $count, $message = '')
403
$this->_incrementAssertionCount();
404
require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php';
405
$constraint = new Zend_Test_PHPUnit_Constraint_DomQuery($path);
406
$content = $this->response->outputBody();
407
if (!$constraint->evaluate($content, __FUNCTION__, $count)) {
408
$constraint->fail($path, $message);
413
* Assert against DOM selection; should contain no more than this number of nodes
415
* @param string $path CSS selector path
416
* @param string $count Maximum number of nodes that should match
417
* @param string $message
420
public function assertQueryCountMax($path, $count, $message = '')
422
$this->_incrementAssertionCount();
423
require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php';
424
$constraint = new Zend_Test_PHPUnit_Constraint_DomQuery($path);
425
$content = $this->response->outputBody();
426
if (!$constraint->evaluate($content, __FUNCTION__, $count)) {
427
$constraint->fail($path, $message);
432
* Assert against XPath selection
434
* @param string $path XPath path
435
* @param string $message
438
public function assertXpath($path, $message = '')
440
$this->_incrementAssertionCount();
441
require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php';
442
$constraint = new Zend_Test_PHPUnit_Constraint_DomQuery($path);
443
$content = $this->response->outputBody();
444
if (!$constraint->evaluate($content, __FUNCTION__)) {
445
$constraint->fail($path, $message);
450
* Assert against XPath selection
452
* @param string $path XPath path
453
* @param string $message
456
public function assertNotXpath($path, $message = '')
458
$this->_incrementAssertionCount();
459
require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php';
460
$constraint = new Zend_Test_PHPUnit_Constraint_DomQuery($path);
461
$content = $this->response->outputBody();
462
if (!$constraint->evaluate($content, __FUNCTION__)) {
463
$constraint->fail($path, $message);
468
* Assert against XPath selection; node should contain content
470
* @param string $path XPath path
471
* @param string $match content that should be contained in matched nodes
472
* @param string $message
475
public function assertXpathContentContains($path, $match, $message = '')
477
$this->_incrementAssertionCount();
478
require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php';
479
$constraint = new Zend_Test_PHPUnit_Constraint_DomQuery($path);
480
$content = $this->response->outputBody();
481
if (!$constraint->evaluate($content, __FUNCTION__, $match)) {
482
$constraint->fail($path, $message);
487
* Assert against XPath selection; node should NOT contain content
489
* @param string $path XPath path
490
* @param string $match content that should NOT be contained in matched nodes
491
* @param string $message
494
public function assertNotXpathContentContains($path, $match, $message = '')
496
$this->_incrementAssertionCount();
497
require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php';
498
$constraint = new Zend_Test_PHPUnit_Constraint_DomQuery($path);
499
$content = $this->response->outputBody();
500
if (!$constraint->evaluate($content, __FUNCTION__, $match)) {
501
$constraint->fail($path, $message);
506
* Assert against XPath selection; node should match content
508
* @param string $path XPath path
509
* @param string $pattern Pattern that should be contained in matched nodes
510
* @param string $message
513
public function assertXpathContentRegex($path, $pattern, $message = '')
515
$this->_incrementAssertionCount();
516
require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php';
517
$constraint = new Zend_Test_PHPUnit_Constraint_DomQuery($path);
518
$content = $this->response->outputBody();
519
if (!$constraint->evaluate($content, __FUNCTION__, $pattern)) {
520
$constraint->fail($path, $message);
525
* Assert against XPath selection; node should NOT match content
527
* @param string $path XPath path
528
* @param string $pattern pattern that should NOT be contained in matched nodes
529
* @param string $message
532
public function assertNotXpathContentRegex($path, $pattern, $message = '')
534
$this->_incrementAssertionCount();
535
require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php';
536
$constraint = new Zend_Test_PHPUnit_Constraint_DomQuery($path);
537
$content = $this->response->outputBody();
538
if (!$constraint->evaluate($content, __FUNCTION__, $pattern)) {
539
$constraint->fail($path, $message);
544
* Assert against XPath selection; should contain exact number of nodes
546
* @param string $path XPath path
547
* @param string $count Number of nodes that should match
548
* @param string $message
551
public function assertXpathCount($path, $count, $message = '')
553
$this->_incrementAssertionCount();
554
require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php';
555
$constraint = new Zend_Test_PHPUnit_Constraint_DomQuery($path);
556
$content = $this->response->outputBody();
557
if (!$constraint->evaluate($content, __FUNCTION__, $count)) {
558
$constraint->fail($path, $message);
563
* Assert against XPath selection; should NOT contain exact number of nodes
565
* @param string $path XPath path
566
* @param string $count Number of nodes that should NOT match
567
* @param string $message
570
public function assertNotXpathCount($path, $count, $message = '')
572
$this->_incrementAssertionCount();
573
require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php';
574
$constraint = new Zend_Test_PHPUnit_Constraint_DomQuery($path);
575
$content = $this->response->outputBody();
576
if (!$constraint->evaluate($content, __FUNCTION__, $count)) {
577
$constraint->fail($path, $message);
582
* Assert against XPath selection; should contain at least this number of nodes
584
* @param string $path XPath path
585
* @param string $count Minimum number of nodes that should match
586
* @param string $message
589
public function assertXpathCountMin($path, $count, $message = '')
591
$this->_incrementAssertionCount();
592
require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php';
593
$constraint = new Zend_Test_PHPUnit_Constraint_DomQuery($path);
594
$content = $this->response->outputBody();
595
if (!$constraint->evaluate($content, __FUNCTION__, $count)) {
596
$constraint->fail($path, $message);
601
* Assert against XPath selection; should contain no more than this number of nodes
603
* @param string $path XPath path
604
* @param string $count Maximum number of nodes that should match
605
* @param string $message
608
public function assertXpathCountMax($path, $count, $message = '')
610
$this->_incrementAssertionCount();
611
require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php';
612
$constraint = new Zend_Test_PHPUnit_Constraint_DomQuery($path);
613
$content = $this->response->outputBody();
614
if (!$constraint->evaluate($content, __FUNCTION__, $count)) {
615
$constraint->fail($path, $message);
620
* Assert that response is a redirect
622
* @param string $message
625
public function assertRedirect($message = '')
627
$this->_incrementAssertionCount();
628
require_once 'Zend/Test/PHPUnit/Constraint/Redirect.php';
629
$constraint = new Zend_Test_PHPUnit_Constraint_Redirect();
630
$response = $this->response;
631
if (!$constraint->evaluate($response, __FUNCTION__)) {
632
$constraint->fail($response, $message);
637
* Assert that response is NOT a redirect
639
* @param string $message
642
public function assertNotRedirect($message = '')
644
$this->_incrementAssertionCount();
645
require_once 'Zend/Test/PHPUnit/Constraint/Redirect.php';
646
$constraint = new Zend_Test_PHPUnit_Constraint_Redirect();
647
$response = $this->response;
648
if (!$constraint->evaluate($response, __FUNCTION__)) {
649
$constraint->fail($response, $message);
654
* Assert that response redirects to given URL
657
* @param string $message
660
public function assertRedirectTo($url, $message = '')
662
$this->_incrementAssertionCount();
663
require_once 'Zend/Test/PHPUnit/Constraint/Redirect.php';
664
$constraint = new Zend_Test_PHPUnit_Constraint_Redirect();
665
$response = $this->response;
666
if (!$constraint->evaluate($response, __FUNCTION__, $url)) {
667
$constraint->fail($response, $message);
672
* Assert that response does not redirect to given URL
675
* @param string $message
678
public function assertNotRedirectTo($url, $message = '')
680
$this->_incrementAssertionCount();
681
require_once 'Zend/Test/PHPUnit/Constraint/Redirect.php';
682
$constraint = new Zend_Test_PHPUnit_Constraint_Redirect();
683
$response = $this->response;
684
if (!$constraint->evaluate($response, __FUNCTION__, $url)) {
685
$constraint->fail($response, $message);
690
* Assert that redirect location matches pattern
692
* @param string $pattern
693
* @param string $message
696
public function assertRedirectRegex($pattern, $message = '')
698
$this->_incrementAssertionCount();
699
require_once 'Zend/Test/PHPUnit/Constraint/Redirect.php';
700
$constraint = new Zend_Test_PHPUnit_Constraint_Redirect();
701
$response = $this->response;
702
if (!$constraint->evaluate($response, __FUNCTION__, $pattern)) {
703
$constraint->fail($response, $message);
708
* Assert that redirect location does not match pattern
710
* @param string $pattern
711
* @param string $message
714
public function assertNotRedirectRegex($pattern, $message = '')
716
$this->_incrementAssertionCount();
717
require_once 'Zend/Test/PHPUnit/Constraint/Redirect.php';
718
$constraint = new Zend_Test_PHPUnit_Constraint_Redirect();
719
$response = $this->response;
720
if (!$constraint->evaluate($response, __FUNCTION__, $pattern)) {
721
$constraint->fail($response, $message);
726
* Assert response code
729
* @param string $message
732
public function assertResponseCode($code, $message = '')
734
$this->_incrementAssertionCount();
735
require_once 'Zend/Test/PHPUnit/Constraint/ResponseHeader.php';
736
$constraint = new Zend_Test_PHPUnit_Constraint_ResponseHeader();
737
$response = $this->response;
738
if (!$constraint->evaluate($response, __FUNCTION__, $code)) {
739
$constraint->fail($response, $message);
744
* Assert response code
747
* @param string $message
750
public function assertNotResponseCode($code, $message = '')
752
$this->_incrementAssertionCount();
753
require_once 'Zend/Test/PHPUnit/Constraint/ResponseHeader.php';
754
$constraint = new Zend_Test_PHPUnit_Constraint_ResponseHeader();
755
$constraint->setNegate(true);
756
$response = $this->response;
757
if (!$constraint->evaluate($response, __FUNCTION__, $code)) {
758
$constraint->fail($response, $message);
763
* Assert response header exists
765
* @param string $header
766
* @param string $message
769
public function assertHeader($header, $message = '')
771
$this->_incrementAssertionCount();
772
require_once 'Zend/Test/PHPUnit/Constraint/ResponseHeader.php';
773
$constraint = new Zend_Test_PHPUnit_Constraint_ResponseHeader();
774
$response = $this->response;
775
if (!$constraint->evaluate($response, __FUNCTION__, $header)) {
776
$constraint->fail($response, $message);
781
* Assert response header does not exist
783
* @param string $header
784
* @param string $message
787
public function assertNotHeader($header, $message = '')
789
$this->_incrementAssertionCount();
790
require_once 'Zend/Test/PHPUnit/Constraint/ResponseHeader.php';
791
$constraint = new Zend_Test_PHPUnit_Constraint_ResponseHeader();
792
$constraint->setNegate(true);
793
$response = $this->response;
794
if (!$constraint->evaluate($response, __FUNCTION__, $header)) {
795
$constraint->fail($response, $message);
800
* Assert response header exists and contains the given string
802
* @param string $header
803
* @param string $match
804
* @param string $message
807
public function assertHeaderContains($header, $match, $message = '')
809
$this->_incrementAssertionCount();
810
require_once 'Zend/Test/PHPUnit/Constraint/ResponseHeader.php';
811
$constraint = new Zend_Test_PHPUnit_Constraint_ResponseHeader();
812
$response = $this->response;
813
if (!$constraint->evaluate($response, __FUNCTION__, $header, $match)) {
814
$constraint->fail($response, $message);
819
* Assert response header does not exist and/or does not contain the given string
821
* @param string $header
822
* @param string $match
823
* @param string $message
826
public function assertNotHeaderContains($header, $match, $message = '')
828
$this->_incrementAssertionCount();
829
require_once 'Zend/Test/PHPUnit/Constraint/ResponseHeader.php';
830
$constraint = new Zend_Test_PHPUnit_Constraint_ResponseHeader();
831
$constraint->setNegate(true);
832
$response = $this->response;
833
if (!$constraint->evaluate($response, __FUNCTION__, $header, $match)) {
834
$constraint->fail($response, $message);
839
* Assert response header exists and matches the given pattern
841
* @param string $header
842
* @param string $pattern
843
* @param string $message
846
public function assertHeaderRegex($header, $pattern, $message = '')
848
$this->_incrementAssertionCount();
849
require_once 'Zend/Test/PHPUnit/Constraint/ResponseHeader.php';
850
$constraint = new Zend_Test_PHPUnit_Constraint_ResponseHeader();
851
$response = $this->response;
852
if (!$constraint->evaluate($response, __FUNCTION__, $header, $pattern)) {
853
$constraint->fail($response, $message);
858
* Assert response header does not exist and/or does not match the given regex
860
* @param string $header
861
* @param string $pattern
862
* @param string $message
865
public function assertNotHeaderRegex($header, $pattern, $message = '')
867
$this->_incrementAssertionCount();
868
require_once 'Zend/Test/PHPUnit/Constraint/ResponseHeader.php';
869
$constraint = new Zend_Test_PHPUnit_Constraint_ResponseHeader();
870
$constraint->setNegate(true);
871
$response = $this->response;
872
if (!$constraint->evaluate($response, __FUNCTION__, $header, $pattern)) {
873
$constraint->fail($response, $message);
878
* Assert that the last handled request used the given module
880
* @param string $module
881
* @param string $message
884
public function assertModule($module, $message = '')
886
$this->_incrementAssertionCount();
887
if ($module != $this->request->getModuleName()) {
888
$msg = sprintf('Failed asserting last module used was "%s"', $module);
889
if (!empty($message)) {
890
$msg = $message . "\n" . $msg;
897
* Assert that the last handled request did NOT use the given module
899
* @param string $module
900
* @param string $message
903
public function assertNotModule($module, $message = '')
905
$this->_incrementAssertionCount();
906
if ($module == $this->request->getModuleName()) {
907
$msg = sprintf('Failed asserting last module used was NOT "%s"', $module);
908
if (!empty($message)) {
909
$msg = $message . "\n" . $msg;
916
* Assert that the last handled request used the given controller
918
* @param string $controller
919
* @param string $message
922
public function assertController($controller, $message = '')
924
$this->_incrementAssertionCount();
925
if ($controller != $this->request->getControllerName()) {
926
$msg = sprintf('Failed asserting last controller used was "%s"', $controller);
927
if (!empty($message)) {
928
$msg = $message . "\n" . $msg;
935
* Assert that the last handled request did NOT use the given controller
937
* @param string $controller
938
* @param string $message
941
public function assertNotController($controller, $message = '')
943
$this->_incrementAssertionCount();
944
if ($controller == $this->request->getControllerName()) {
945
$msg = sprintf('Failed asserting last controller used was NOT "%s"', $controller);
946
if (!empty($message)) {
947
$msg = $message . "\n" . $msg;
954
* Assert that the last handled request used the given action
956
* @param string $action
957
* @param string $message
960
public function assertAction($action, $message = '')
962
$this->_incrementAssertionCount();
963
if ($action != $this->request->getActionName()) {
964
$msg = sprintf('Failed asserting last action used was "%s"', $action);
965
if (!empty($message)) {
966
$msg = $message . "\n" . $msg;
973
* Assert that the last handled request did NOT use the given action
975
* @param string $action
976
* @param string $message
979
public function assertNotAction($action, $message = '')
981
$this->_incrementAssertionCount();
982
if ($action == $this->request->getActionName()) {
983
$msg = sprintf('Failed asserting last action used was NOT "%s"', $action);
984
if (!empty($message)) {
985
$msg = $message . "\n" . $msg;
992
* Assert that the specified route was used
994
* @param string $route
995
* @param string $message
998
public function assertRoute($route, $message = '')
1000
$this->_incrementAssertionCount();
1001
$router = $this->frontController->getRouter();
1002
if ($route != $router->getCurrentRouteName()) {
1003
$msg = sprintf('Failed asserting route matched was "%s"', $route);
1004
if (!empty($message)) {
1005
$msg = $message . "\n" . $msg;
1012
* Assert that the route matched is NOT as specified
1014
* @param string $route
1015
* @param string $message
1018
public function assertNotRoute($route, $message = '')
1020
$this->_incrementAssertionCount();
1021
$router = $this->frontController->getRouter();
1022
if ($route == $router->getCurrentRouteName()) {
1023
$msg = sprintf('Failed asserting route matched was NOT "%s"', $route);
1024
if (!empty($message)) {
1025
$msg = $message . "\n" . $msg;
1032
* Retrieve front controller instance
1034
* @return Zend_Controller_Front
1036
public function getFrontController()
1038
if (null === $this->_frontController) {
1039
$this->_frontController = Zend_Controller_Front::getInstance();
1041
return $this->_frontController;
1045
* Retrieve test case request object
1047
* @return Zend_Controller_Request_Abstract
1049
public function getRequest()
1051
if (null === $this->_request) {
1052
require_once 'Zend/Controller/Request/HttpTestCase.php';
1053
$this->_request = new Zend_Controller_Request_HttpTestCase;
1055
return $this->_request;
1059
* Retrieve test case response object
1061
* @return Zend_Controller_Response_Abstract
1063
public function getResponse()
1065
if (null === $this->_response) {
1066
require_once 'Zend/Controller/Response/HttpTestCase.php';
1067
$this->_response = new Zend_Controller_Response_HttpTestCase;
1069
return $this->_response;
1073
* Retrieve DOM query object
1075
* @return Zend_Dom_Query
1077
public function getQuery()
1079
if (null === $this->_query) {
1080
require_once 'Zend/Dom/Query.php';
1081
$this->_query = new Zend_Dom_Query;
1083
return $this->_query;
1087
* Increment assertion count
1091
protected function _incrementAssertionCount()
1093
$stack = debug_backtrace();
1094
foreach (debug_backtrace() as $step) {
1095
if (isset($step['object'])
1096
&& $step['object'] instanceof PHPUnit_Framework_TestCase
1098
if (version_compare(PHPUnit_Runner_Version::id(), '3.3.3', 'lt')) {
1099
$step['object']->incrementAssertionCounter();
1101
$step['object']->addToAssertionCount(1);