MyControllerTestCase.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. App::uses('ControllerTestCase', 'TestSuite');
  3. App::uses('Router', 'Routing');
  4. /**
  5. * MyControllerTestCase Test Case
  6. *
  7. */
  8. class MyControllerTestCase extends ControllerTestCase {
  9. /**
  10. * Overwrite to fix issue that it always defaults to POST.
  11. * That should be GET - which it now is.
  12. *
  13. * ### Options:
  14. *
  15. * - `data` Will be used as the request data. If the `method` is GET,
  16. * data will be used a GET params. If the `method` is POST, it will be used
  17. * as POST data. By setting `$options['data']` to a string, you can simulate XML or JSON
  18. * payloads to your controllers allowing you to test REST webservices.
  19. * - `method` POST or GET. Defaults to GET.
  20. * - `return` Specify the return type you want. Choose from:
  21. * - `vars` Get the set view variables.
  22. * - `view` Get the rendered view, without a layout.
  23. * - `contents` Get the rendered view including the layout.
  24. * - `result` Get the return value of the controller action. Useful
  25. * for testing requestAction methods.
  26. *
  27. * @param string $url The url to test
  28. * @param array $options See options
  29. * @return mixed
  30. */
  31. protected function _testAction($url = '', $options = array()) {
  32. $options += array(
  33. 'method' => 'GET',
  34. );
  35. if (is_array($url)) {
  36. $url = Router::url($url);
  37. }
  38. return parent::_testAction($url, $options);
  39. }
  40. }