Skip to content
Newer
Older
100644 98 lines (86 sloc) 2.75 KB
8bfcfe4 @gwoo updating test suite handling. Re-Adding `\test\Controller` for browse…
gwoo authored Mar 22, 2010
1 <?php
2 /**
3 * Lithium: the most rad php framework
4 *
f99a12f @mehlah Happy 2013!
mehlah authored Jan 1, 2013
5 * @copyright Copyright 2013, Union of RAD (http://union-of-rad.org)
8bfcfe4 @gwoo updating test suite handling. Re-Adding `\test\Controller` for browse…
gwoo authored Mar 22, 2010
6 * @license http://opensource.org/licenses/bsd-license.php The BSD License
7 */
8
9 namespace lithium\test;
10
11 use lithium\test\Dispatcher;
12 use lithium\core\Libraries;
13 use lithium\test\Group;
e65d211 @gwoo Simiplfying test menu generation.
gwoo authored Dec 1, 2012
14 use lithium\util\Set;
d071691 @jails Tests isolation, tests shouldn't need to take care about the launcher…
jails authored Apr 19, 2013
15 use lithium\net\http\Router;
8bfcfe4 @gwoo updating test suite handling. Re-Adding `\test\Controller` for browse…
gwoo authored Mar 22, 2010
16
17 /**
18 * The Test Controller for running the html version of the test suite
19 *
20 */
21 class Controller extends \lithium\core\Object {
22
23 /**
d071691 @jails Tests isolation, tests shouldn't need to take care about the launcher…
jails authored Apr 19, 2013
24 * Saved context.
25 *
26 * @var array
27 */
28 protected $_context = array();
29
30 /**
8bfcfe4 @gwoo updating test suite handling. Re-Adding `\test\Controller` for browse…
gwoo authored Mar 22, 2010
31 * Magic method to make Controller callable.
32 *
11018ba @nateabele Fixing coding standards issues with `@see` tags.
nateabele authored May 7, 2010
33 * @see lithium\action\Dispatcher::_callable()
8bfcfe4 @gwoo updating test suite handling. Re-Adding `\test\Controller` for browse…
gwoo authored Mar 22, 2010
34 * @param object $request A \lithium\action\Request object.
35 * @param array $dispatchParams Array of params after being parsed by router.
36 * @param array $options Some basic options for this controller.
37 * @return string
59cb735 @nateabele Ensuring `@filter` tags are present in docblocks that support filteri…
nateabele authored May 24, 2011
38 * @filter
8bfcfe4 @gwoo updating test suite handling. Re-Adding `\test\Controller` for browse…
gwoo authored Mar 22, 2010
39 */
40 public function __invoke($request, $dispatchParams, array $options = array()) {
41 $dispatchParamsDefaults = array('args' => array());
42 $dispatchParams += $dispatchParamsDefaults;
65e0e81 @davidpersson Dropping usage of reporter in test controller.
davidpersson authored May 19, 2012
43 $defaults = array('format' => 'html', 'timeout' => 0);
8bfcfe4 @gwoo updating test suite handling. Re-Adding `\test\Controller` for browse…
gwoo authored Mar 22, 2010
44 $options += (array) $request->query + $defaults;
45 $params = compact('request', 'dispatchParams', 'options');
46
47 return $this->_filter(__METHOD__, $params, function($self, $params) {
48 $request = $params['request'];
49 $options = $params['options'];
50 $params = $params['dispatchParams'];
0a74653 @gwoo allowing \test\Controller timeout to be set via params.
gwoo authored Feb 7, 2011
51 set_time_limit((integer) $options['timeout']);
6c0a90e @nateabele Modifying test suite results display to remove leading backslash, and…
nateabele authored Jul 6, 2010
52 $group = join('\\', (array) $params['args']);
8bfcfe4 @gwoo updating test suite handling. Re-Adding `\test\Controller` for browse…
gwoo authored Mar 22, 2010
53
6c0a90e @nateabele Modifying test suite results display to remove leading backslash, and…
nateabele authored Jul 6, 2010
54 if ($group === "all") {
8bfcfe4 @gwoo updating test suite handling. Re-Adding `\test\Controller` for browse…
gwoo authored Mar 22, 2010
55 $group = Group::all();
56 $options['title'] = 'All Tests';
57 }
d071691 @jails Tests isolation, tests shouldn't need to take care about the launcher…
jails authored Apr 19, 2013
58
58aa566 @mikegreiling fix for browser-based tests in php 5.3
mikegreiling authored May 6, 2013
59 $self->invokeMethod('_saveCtrlContext');
0a74653 @gwoo allowing \test\Controller timeout to be set via params.
gwoo authored Feb 7, 2011
60 $report = Dispatcher::run($group, $options);
58aa566 @mikegreiling fix for browser-based tests in php 5.3
mikegreiling authored May 6, 2013
61 $self->invokeMethod('_restoreCtrlContext');
d071691 @jails Tests isolation, tests shouldn't need to take care about the launcher…
jails authored Apr 19, 2013
62
8bfcfe4 @gwoo updating test suite handling. Re-Adding `\test\Controller` for browse…
gwoo authored Mar 22, 2010
63 $filters = Libraries::locate('test.filter');
64 $menu = Libraries::locate('tests', null, array(
65 'filter' => '/cases|integration|functional/',
66 'exclude' => '/mocks/'
67 ));
68 sort($menu);
e65d211 @gwoo Simiplfying test menu generation.
gwoo authored Dec 2, 2012
69 $menu = Set::expand(array_combine($menu, $menu), array('separator' => "\\"));
8bfcfe4 @gwoo updating test suite handling. Re-Adding `\test\Controller` for browse…
gwoo authored Mar 22, 2010
70 $result = compact('request', 'report', 'filters', 'menu');
71 return $report->render('layout', $result);
72 });
73 }
d071691 @jails Tests isolation, tests shouldn't need to take care about the launcher…
jails authored Apr 19, 2013
74
75 protected function _saveCtrlContext() {
76 $this->_context['scope'] = Router::scope(false);
77 $this->_context['routes'] = Router::get();
78 $this->_context['scopes'] = Router::attached();
79 Router::reset();
80 }
81
82 protected function _restoreCtrlContext() {
83 Router::reset();
84 foreach ($this->_context['routes'] as $scope => $routes) {
85 Router::scope($scope, function() use ($routes) {
86 foreach ($routes as $route) {
87 Router::connect($route);
88 }
89 });
90 }
91 foreach ($this->_context['scopes'] as $scope => $attachment) {
92 Router::attach($scope, $attachment);
93 }
94 Router::scope($this->_context['scope']);
95 }
8bfcfe4 @gwoo updating test suite handling. Re-Adding `\test\Controller` for browse…
gwoo authored Mar 22, 2010
96 }
97
98 ?>
Something went wrong with that request. Please try again.