2
0

ControllerTest.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 postAction()
  61. {
  62. $this->testValue = 'postAction';
  63. }
  64. public function putAction()
  65. {
  66. $this->testValue = 'putAction';
  67. }
  68. public function deleteAction()
  69. {
  70. $this->testValue = 'deleteAction';
  71. }
  72. }
  73. /**
  74. * @category Zend
  75. * @package Zend_Rest
  76. * @subpackage UnitTests
  77. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  78. * @license http://framework.zend.com/license/new-bsd New BSD License
  79. * @group Zend_Rest
  80. */
  81. class Zend_Rest_ControllerTest extends PHPUnit_Framework_TestCase
  82. {
  83. protected $_testController;
  84. /**
  85. * Runs the test methods of this class.
  86. *
  87. * @access public
  88. * @static
  89. */
  90. public static function main()
  91. {
  92. require_once "PHPUnit/TextUI/TestRunner.php";
  93. $suite = new PHPUnit_Framework_TestSuite("Zend_Rest_ControllerTest");
  94. $result = PHPUnit_TextUI_TestRunner::run($suite);
  95. }
  96. public function setUp()
  97. {
  98. $request = new Zend_Controller_Request_HttpTestCase();
  99. $response = new Zend_Controller_Response_HttpTestCase();
  100. $this->_testController = new Zend_Rest_TestController($request, $response);
  101. }
  102. public function test_action_methods()
  103. {
  104. $this->_testController->indexAction();
  105. $this->assertEquals('indexAction', $this->_testController->testValue);
  106. $this->_testController->getAction();
  107. $this->assertEquals('getAction', $this->_testController->testValue);
  108. $this->_testController->postAction();
  109. $this->assertEquals('postAction', $this->_testController->testValue);
  110. $this->_testController->putAction();
  111. $this->assertEquals('putAction', $this->_testController->testValue);
  112. $this->_testController->deleteAction();
  113. $this->assertEquals('deleteAction', $this->_testController->testValue);
  114. }
  115. }
  116. // Call Zend_Rest_ControllerTest::main() if this source file is executed directly.
  117. if (PHPUnit_MAIN_METHOD == "Zend_Rest_ControllerTest::main") {
  118. Zend_Rest_ControllerTest::main();
  119. }