Bin will be removed on June 1, 2014 in favor of http://gist.github.com. Please save all your pastes before then. So long, and thanks for all the fish!×
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// cake/tests/lib/cake_test_case.php
// In CakeTestDispatcher class. Copied code from cake/dispatcher.php
// Note: looks for the <Controller Name>TestController to use the test controller class.
  function __loadController($params) {
    $pluginName = $pluginPath = $controller = null;
 
    if (!empty($params['plugin'])) {
      $this->plugin = $params['plugin'];
      $pluginName = Inflector::camelize($params['plugin']);
      $pluginPath = $pluginName . '.';
      $this->params['controller'] = $this->plugin;
      $controller = $pluginName;
    }
 
    if (!empty($params['controller'])) {
      $controller = Inflector::camelize($params['controller']);
    }
 
    if ($pluginPath . $controller) {
      if (App::import('Controller', $pluginPath . $controller)) {
        if(class_exists($controller.'TestController')) {
          return $controller.'Test'; //Added for test suite.
        } else {
          return $controller;
        }
      }
    }
    return false;
  }
 
 
// app/tests/cases/controllers/reports_controler.test.php
App::import('Controller','Reports');
 
class ReportsTestController extends ReportsController {
  function redirect($url = null, $status = null) {
    return array('url' => $url, 'status' => $status);
  }
}
 
class TestReports extends ReportsTestController {
  var $autoRender = false;
 
}
 
class ReportsControlllerTest extends CakeTestCase {
  var $Reports = null;
 
  function setUp() {
    $this->Reports = new TestReports();
  }
 
  function testReportsView() {
    $result = $this->testAction('/reports/view');
    $expect = array(
      'url' => array(
        'controller' => 'reports',
        'action' => 'index'
      ),
      'status' => 301
    );
 
    $this->assertEqual($result, $expect);
  }
 
  function tearDown() {
    unset($this->Reports);
  }
 
}
 
 
// app/controllers/reports_controller.php
class ReportsController extends AppController {
  var $name = 'Reports';
  var $helpers = array('Html', 'Form');
 
  function view() {
    return $this->redirect(
      array(
        'controller' => 'reports',
        'action' => 'index'
      ),
      301
    );
  }
 
}