ControllerTest.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. * @package Zend_Rest
  16. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  17. * @license http://framework.zend.com/license/new-bsd New BSD License
  18. * @version $Id$
  19. */
  20. /** Test helper */
  21. require_once dirname(__FILE__) . '/../../TestHelper.php';
  22. require_once "PHPUnit/Framework/TestCase.php";
  23. require_once "PHPUnit/Framework/TestSuite.php";
  24. /**
  25. * @category Zend
  26. * @package Zend_Rest
  27. * @subpackage UnitTests
  28. */
  29. /** Zend_Rest_Controller */
  30. require_once 'Zend/Rest/Controller.php';
  31. /** Zend_Controller_Request_HttpTestCase */
  32. require_once 'Zend/Controller/Request/HttpTestCase.php';
  33. /** Zend_Controller_Response_HttpTestCase */
  34. require_once 'Zend/Controller/Response/HttpTestCase.php';
  35. // Call Zend_Rest_ControllerTest::main() if this source file is executed directly.
  36. if (!defined("PHPUnit_MAIN_METHOD")) {
  37. define("PHPUnit_MAIN_METHOD", "Zend_Rest_ControllerTest::main");
  38. }
  39. class Zend_Rest_TestController extends Zend_Rest_Controller
  40. {
  41. public $testValue = '';
  42. public function __construct(Zend_Controller_Request_Abstract $request,
  43. Zend_Controller_Response_Abstract $response,
  44. array $invokeArgs = array())
  45. {
  46. $this->testValue = '';
  47. }
  48. public function indexAction()
  49. {
  50. $this->testValue = 'indexAction';
  51. }
  52. public function getAction()
  53. {
  54. $this->testValue = 'getAction';
  55. }
  56. public function postAction()
  57. {
  58. $this->testValue = 'postAction';
  59. }
  60. public function putAction()
  61. {
  62. $this->testValue = 'putAction';
  63. }
  64. public function deleteAction()
  65. {
  66. $this->testValue = 'deleteAction';
  67. }
  68. }
  69. /**
  70. * @category Zend
  71. * @package Zend_Rest
  72. * @subpackage UnitTests
  73. */
  74. class Zend_Rest_ControllerTest extends PHPUnit_Framework_TestCase
  75. {
  76. protected $_testController;
  77. /**
  78. * Runs the test methods of this class.
  79. *
  80. * @access public
  81. * @static
  82. */
  83. public static function main()
  84. {
  85. require_once "PHPUnit/TextUI/TestRunner.php";
  86. $suite = new PHPUnit_Framework_TestSuite("Zend_Rest_ControllerTest");
  87. $result = PHPUnit_TextUI_TestRunner::run($suite);
  88. }
  89. public function setUp()
  90. {
  91. $request = new Zend_Controller_Request_HttpTestCase();
  92. $response = new Zend_Controller_Response_HttpTestCase();
  93. $this->_testController = new Zend_Rest_TestController($request, $response);
  94. }
  95. public function test_action_methods()
  96. {
  97. $this->_testController->indexAction();
  98. $this->assertEquals('indexAction', $this->_testController->testValue);
  99. $this->_testController->getAction();
  100. $this->assertEquals('getAction', $this->_testController->testValue);
  101. $this->_testController->postAction();
  102. $this->assertEquals('postAction', $this->_testController->testValue);
  103. $this->_testController->putAction();
  104. $this->assertEquals('putAction', $this->_testController->testValue);
  105. $this->_testController->deleteAction();
  106. $this->assertEquals('deleteAction', $this->_testController->testValue);
  107. }
  108. }
  109. // Call Zend_Rest_ControllerTest::main() if this source file is executed directly.
  110. if (PHPUnit_MAIN_METHOD == "Zend_Rest_ControllerTest::main") {
  111. Zend_Rest_ControllerTest::main();
  112. }