ControllerTest.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  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.
  14. *
  15. * @category Zend
  16. * @package Zend_Rest
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /** Test helper */
  23. require_once dirname(__FILE__) . '/../../TestHelper.php';
  24. require_once "PHPUnit/Framework/TestCase.php";
  25. require_once "PHPUnit/Framework/TestSuite.php";
  26. /** Zend_Rest_Controller */
  27. require_once 'Zend/Rest/Controller.php';
  28. /** Zend_Controller_Request_HttpTestCase */
  29. require_once 'Zend/Controller/Request/HttpTestCase.php';
  30. /** Zend_Controller_Response_HttpTestCase */
  31. require_once 'Zend/Controller/Response/HttpTestCase.php';
  32. // Call Zend_Rest_ControllerTest::main() if this source file is executed directly.
  33. if (!defined("PHPUnit_MAIN_METHOD")) {
  34. define("PHPUnit_MAIN_METHOD", "Zend_Rest_ControllerTest::main");
  35. }
  36. /**
  37. * @category Zend
  38. * @package Zend_Rest
  39. * @subpackage UnitTests
  40. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  41. * @license http://framework.zend.com/license/new-bsd New BSD License
  42. */
  43. class Zend_Rest_TestController extends Zend_Rest_Controller
  44. {
  45. public $testValue = '';
  46. public function __construct(Zend_Controller_Request_Abstract $request,
  47. Zend_Controller_Response_Abstract $response,
  48. array $invokeArgs = array())
  49. {
  50. $this->testValue = '';
  51. }
  52. public function indexAction()
  53. {
  54. $this->testValue = 'indexAction';
  55. }
  56. public function getAction()
  57. {
  58. $this->testValue = 'getAction';
  59. }
  60. public function headAction()
  61. {
  62. $this->testValue = 'headAction';
  63. }
  64. public function postAction()
  65. {
  66. $this->testValue = 'postAction';
  67. }
  68. public function putAction()
  69. {
  70. $this->testValue = 'putAction';
  71. }
  72. public function deleteAction()
  73. {
  74. $this->testValue = 'deleteAction';
  75. }
  76. }
  77. /**
  78. * @category Zend
  79. * @package Zend_Rest
  80. * @subpackage UnitTests
  81. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  82. * @license http://framework.zend.com/license/new-bsd New BSD License
  83. * @group Zend_Rest
  84. */
  85. class Zend_Rest_ControllerTest extends PHPUnit_Framework_TestCase
  86. {
  87. protected $_testController;
  88. /**
  89. * Runs the test methods of this class.
  90. *
  91. * @access public
  92. * @static
  93. */
  94. public static function main()
  95. {
  96. require_once "PHPUnit/TextUI/TestRunner.php";
  97. $suite = new PHPUnit_Framework_TestSuite("Zend_Rest_ControllerTest");
  98. $result = PHPUnit_TextUI_TestRunner::run($suite);
  99. }
  100. public function setUp()
  101. {
  102. $request = new Zend_Controller_Request_HttpTestCase();
  103. $response = new Zend_Controller_Response_HttpTestCase();
  104. $this->_testController = new Zend_Rest_TestController($request, $response);
  105. }
  106. public function test_action_methods()
  107. {
  108. $this->_testController->indexAction();
  109. $this->assertEquals('indexAction', $this->_testController->testValue);
  110. $this->_testController->getAction();
  111. $this->assertEquals('getAction', $this->_testController->testValue);
  112. $this->_testController->headAction();
  113. $this->assertEquals('headAction', $this->_testController->testValue);
  114. $this->_testController->postAction();
  115. $this->assertEquals('postAction', $this->_testController->testValue);
  116. $this->_testController->putAction();
  117. $this->assertEquals('putAction', $this->_testController->testValue);
  118. $this->_testController->deleteAction();
  119. $this->assertEquals('deleteAction', $this->_testController->testValue);
  120. }
  121. }
  122. // Call Zend_Rest_ControllerTest::main() if this source file is executed directly.
  123. if (PHPUnit_MAIN_METHOD == "Zend_Rest_ControllerTest::main") {
  124. Zend_Rest_ControllerTest::main();
  125. }