Dispatcher->dispatchメソッドの引数をアクション名(文字列)からActionInfoに変更
@@ -1,5 +1,6 @@ | ||
1 | 1 | <?php |
2 | 2 | |
3 | +require_once('Kaede/Core/ActionInfo.php'); | |
3 | 4 | require_once('Kaede/Util/PseudoAnnotation.php'); |
4 | 5 | require_once('Kaede/Core/Session.php'); |
5 | 6 | require_once('Kaede/Core/Response.php'); |
@@ -31,9 +32,14 @@ | ||
31 | 32 | $this->d->response =& new Kaede_Core_Response(); |
32 | 33 | } |
33 | 34 | |
35 | + function createInfo($actionName) | |
36 | + { | |
37 | + return new Kaede_Core_ActionInfo($actionName); | |
38 | + } | |
39 | + | |
34 | 40 | function testStartNewContext_ActionIsNotEntryAction() |
35 | 41 | { |
36 | - $action = 'foo_bar'; | |
42 | + $action = $this->createInfo('foo_bar'); | |
37 | 43 | $method = 'get'; |
38 | 44 | |
39 | 45 | //Mocks as Actors |
@@ -48,11 +54,13 @@ | ||
48 | 54 | |
49 | 55 | function testStartNewContext_DefaultFlowName_DefaultFlowActions() |
50 | 56 | { |
51 | - $action = 'foo_bar'; | |
57 | + $action = $this->createInfo('foo_bar'); | |
58 | + $actionName = $action->getName(); | |
59 | + | |
52 | 60 | $method = 'get'; |
53 | 61 | |
54 | - $flowName = $action; | |
55 | - $actions = array($action); | |
62 | + $flowName = $actionName; | |
63 | + $actions = array($actionName); | |
56 | 64 | |
57 | 65 | //Mocks as Actors |
58 | 66 | $this->util->setReturnValue('readClassAnnotations', |
@@ -72,11 +80,12 @@ | ||
72 | 80 | |
73 | 81 | function testStartNewContext_FlowName_FlowActions() |
74 | 82 | { |
75 | - $action = 'foo_bar'; | |
83 | + $actionName = 'foo_bar'; | |
84 | + $action = $this->createInfo($actionName); | |
76 | 85 | $method = 'get'; |
77 | 86 | |
78 | 87 | $flowName = 'foo_bar_flow_name'; |
79 | - $actions = array($action, 'page2', 'page3'); | |
88 | + $actions = array($actionName, 'page2', 'page3'); | |
80 | 89 | |
81 | 90 | //Mocks as Actors |
82 | 91 | $this->util->setReturnValue('readClassAnnotations', |
@@ -98,11 +107,12 @@ | ||
98 | 107 | function testDispatch_NoContextWasPassed() |
99 | 108 | { |
100 | 109 | //startNewContext must be called |
101 | - $action = 'foo_bar'; | |
110 | + $actionName = 'foo_bar'; | |
111 | + $action = $this->createInfo($actionName); | |
102 | 112 | $method = 'get'; |
103 | 113 | |
104 | 114 | $flowName = 'foo_bar_flow_name'; |
105 | - $actions = array($action, 'page2', 'page3'); | |
115 | + $actions = array($actionName, 'page2', 'page3'); | |
106 | 116 | |
107 | 117 | //Mocks as Actors |
108 | 118 | $this->util->setReturnValue('readClassAnnotations', |
@@ -125,7 +135,8 @@ | ||
125 | 135 | |
126 | 136 | function testDispatch_ContextNotFound() |
127 | 137 | { |
128 | - $action = 'foo_bar'; | |
138 | + $actionName = 'foo_bar'; | |
139 | + $action = $this->createInfo($actionName); | |
129 | 140 | $method = 'get'; |
130 | 141 | $contextKey = 'dummy'; |
131 | 142 |
@@ -144,7 +155,8 @@ | ||
144 | 155 | function testDispatch_ContextIsFinished() |
145 | 156 | { |
146 | 157 | $initialAction = 'initial_action'; |
147 | - $action = 'foo_bar'; | |
158 | + $actionName = 'foo_bar'; | |
159 | + $action = $this->createInfo($actionName); | |
148 | 160 | $method = 'get'; |
149 | 161 | $contextKey = 'dummy'; |
150 | 162 |
@@ -167,7 +179,8 @@ | ||
167 | 179 | function testDispatch_ActionMismatch_OutOfFlowActions() |
168 | 180 | { |
169 | 181 | $currentAction = 'current_action'; |
170 | - $action = 'foo_bar'; | |
182 | + $actionName = 'foo_bar'; | |
183 | + $action = $this->createInfo($actionName); | |
171 | 184 | $method = 'get'; |
172 | 185 | $contextKey = 'dummy'; |
173 | 186 |
@@ -175,13 +188,13 @@ | ||
175 | 188 | $this->sess->setReturnReference('getContext', $this->ctx, array($contextKey)); |
176 | 189 | $this->ctx->setReturnValue('isFinished', false); |
177 | 190 | $this->ctx->setReturnValue('getCurrentAction', $currentAction); |
178 | - $this->ctx->setReturnValue('hasAction', false, array($action)); | |
191 | + $this->ctx->setReturnValue('hasAction', false, array($actionName)); | |
179 | 192 | |
180 | 193 | //Mocks as Critics |
181 | 194 | $this->sess->expectOnce('getContext', array($contextKey)); |
182 | 195 | $this->ctx->expectOnce('isFinished'); |
183 | 196 | $this->ctx->expectOnce('getCurrentAction'); |
184 | - $this->ctx->expectOnce('hasAction', array($action)); | |
197 | + $this->ctx->expectOnce('hasAction', array($actionName)); | |
185 | 198 | $this->ctx->expectNever('invoke'); |
186 | 199 | |
187 | 200 | $this->assertFalse($this->d->dispatch($action, $method, $contextKey)); |
@@ -191,7 +204,8 @@ | ||
191 | 204 | function testDispatch_ActionMismatch_MoveInFlowActions() |
192 | 205 | { |
193 | 206 | $currentAction = 'current_action'; |
194 | - $action = 'foo_bar'; | |
207 | + $actionName = 'foo_bar'; | |
208 | + $action = $this->createInfo($actionName); | |
195 | 209 | $method = 'get'; |
196 | 210 | $contextKey = 'dummy'; |
197 | 211 |
@@ -199,7 +213,7 @@ | ||
199 | 213 | $this->sess->setReturnReference('getContext', $this->ctx, array($contextKey)); |
200 | 214 | $this->ctx->setReturnValue('isFinished', false); |
201 | 215 | $this->ctx->setReturnValue('getCurrentAction', $currentAction); |
202 | - $this->ctx->setReturnValue('hasAction', true, array($action)); | |
216 | + $this->ctx->setReturnValue('hasAction', true, array($actionName)); | |
203 | 217 | $this->ctx->setReturnValue('invoke', true); |
204 | 218 | |
205 | 219 | //Mocks as Critics |
@@ -206,8 +220,8 @@ | ||
206 | 220 | $this->sess->expectOnce('getContext', array($contextKey)); |
207 | 221 | $this->ctx->expectOnce('isFinished'); |
208 | 222 | $this->ctx->expectOnce('getCurrentAction'); |
209 | - $this->ctx->expectOnce('hasAction', array($action)); | |
210 | - $this->ctx->expectOnce('invoke', array('move', array('requestedAction' => $action))); | |
223 | + $this->ctx->expectOnce('hasAction', array($actionName)); | |
224 | + $this->ctx->expectOnce('invoke', array('move', array('requestedAction' => $actionName))); | |
211 | 225 | |
212 | 226 | $this->assertTrue($this->d->dispatch($action, $method, $contextKey)); |
213 | 227 | } |
@@ -215,7 +229,8 @@ | ||
215 | 229 | function testDispatch_Start() |
216 | 230 | { |
217 | 231 | $currentAction = 'current_action'; |
218 | - $action = $currentAction; | |
232 | + $actionName = $currentAction; | |
233 | + $action = $this->createInfo($actionName); | |
219 | 234 | $method = 'get'; |
220 | 235 | $contextKey = 'dummy'; |
221 | 236 |
@@ -1,5 +1,6 @@ | ||
1 | 1 | <?php |
2 | 2 | |
3 | +require_once('Kaede/Core/ActionInfo.php'); | |
3 | 4 | require_once('Kaede/Core/Session.php'); |
4 | 5 | require_once('Kaede/Core/Response.php'); |
5 | 6 | require_once('Kaede/Core/Dispatcher/Event.php'); |
@@ -25,21 +26,26 @@ | ||
25 | 26 | $this->d->response =& new Kaede_Core_Response(); |
26 | 27 | } |
27 | 28 | |
29 | + function createInfo($actionName) | |
30 | + { | |
31 | + return new Kaede_Core_ActionInfo($actionName); | |
32 | + } | |
33 | + | |
28 | 34 | function testDispatch_ContextNotPassed() |
29 | 35 | { |
30 | - $action = 'foo_bar'; | |
36 | + $actionInfo = $this->createInfo('foo_bar'); | |
31 | 37 | $method = 'post'; |
32 | 38 | |
33 | 39 | //Mocks as Critics |
34 | 40 | $this->sess->expectNever('getContext'); |
35 | 41 | |
36 | - $this->assertFalse($this->d->dispatch($action, $method, '')); | |
42 | + $this->assertFalse($this->d->dispatch($actionInfo, $method, '')); | |
37 | 43 | $this->assertEqual(403, $this->d->response->getStatus()); |
38 | 44 | } |
39 | 45 | |
40 | 46 | function testDispatch_ContextNotFound() |
41 | 47 | { |
42 | - $action = 'foo_bar'; | |
48 | + $actionInfo = $this->createInfo('foo_bar'); | |
43 | 49 | $method = 'post'; |
44 | 50 | $contextKey = 'dummy'; |
45 | 51 |
@@ -51,7 +57,7 @@ | ||
51 | 57 | //Mocks as Critics |
52 | 58 | $this->sess->expectOnce('getContext', array($contextKey)); |
53 | 59 | |
54 | - $this->assertFalse($this->d->dispatch($action, $method, $contextKey)); | |
60 | + $this->assertFalse($this->d->dispatch($actionInfo, $method, $contextKey)); | |
55 | 61 | $this->assertEqual(403, $this->d->response->getStatus()); |
56 | 62 | } |
57 | 63 |
@@ -58,7 +64,7 @@ | ||
58 | 64 | function testDispatch_ContextIsFinished() |
59 | 65 | { |
60 | 66 | $initialAction = 'initial_action'; |
61 | - $action = 'foo_bar'; | |
67 | + $actionInfo = $this->createInfo('foo_bar'); | |
62 | 68 | $method = 'post'; |
63 | 69 | $contextKey = 'dummy'; |
64 | 70 |
@@ -75,13 +81,13 @@ | ||
75 | 81 | $this->ctx->expectOnce('redirect', array($initialAction, false)); |
76 | 82 | $this->ctx->expectOnce('destroy'); |
77 | 83 | |
78 | - $this->assertTrue($this->d->dispatch($action, $method, $contextKey)); | |
84 | + $this->assertTrue($this->d->dispatch($actionInfo, $method, $contextKey)); | |
79 | 85 | } |
80 | 86 | |
81 | 87 | function testDispatch_ActionMismatch() |
82 | 88 | { |
83 | 89 | $currentAction = 'current_action'; |
84 | - $action = 'foo_bar'; | |
90 | + $actionInfo = $this->createInfo('foo_bar'); | |
85 | 91 | $method = 'post'; |
86 | 92 | $contextKey = 'dummy'; |
87 | 93 |
@@ -96,7 +102,7 @@ | ||
96 | 102 | $this->ctx->expectOnce('getCurrentAction'); |
97 | 103 | $this->ctx->expectNever('invoke'); |
98 | 104 | |
99 | - $this->assertFalse($this->d->dispatch($action, $method, $contextKey)); | |
105 | + $this->assertFalse($this->d->dispatch($actionInfo, $method, $contextKey)); | |
100 | 106 | $this->assertEqual(403, $this->d->response->getStatus()); |
101 | 107 | } |
102 | 108 |
@@ -103,7 +109,7 @@ | ||
103 | 109 | function testDispatch() |
104 | 110 | { |
105 | 111 | $currentAction = 'current_action'; |
106 | - $action = $currentAction; | |
112 | + $actionInfo = $this->createInfo($currentAction); | |
107 | 113 | $method = 'post'; |
108 | 114 | $contextKey = 'dummy'; |
109 | 115 |
@@ -126,10 +132,10 @@ | ||
126 | 132 | 'invoke', |
127 | 133 | array("after_post", |
128 | 134 | array('method' => $actionMethod, |
129 | - 'httpMethod' => $method, | |
135 | + 'actionMethod' => $method, | |
130 | 136 | 'result' => true))); |
131 | 137 | |
132 | - $this->assertTrue($this->d->dispatch($action, $method, $contextKey)); | |
138 | + $this->assertTrue($this->d->dispatch($actionInfo, $method, $contextKey)); | |
133 | 139 | } |
134 | 140 | |
135 | 141 | } |
@@ -45,12 +45,12 @@ | ||
45 | 45 | /** |
46 | 46 | * |
47 | 47 | * @access public |
48 | - * @param string $actionName | |
48 | + * @param Kaede_Core_ActionInfo $actionInfo | |
49 | 49 | * @return boolean |
50 | 50 | */ |
51 | - function startNewContext($actionName, $httpMethod) | |
51 | + function startNewContext($actionInfo, $actionMethod) | |
52 | 52 | { |
53 | - $actionInfo =& new Kaede_Core_ActionInfo($actionName); | |
53 | + $actionName = $actionInfo->getName(); | |
54 | 54 | $annos = $this->annotationUtil->readClassAnnotations( |
55 | 55 | $actionInfo->getClassName()); |
56 | 56 |
@@ -75,15 +75,17 @@ | ||
75 | 75 | /** |
76 | 76 | * |
77 | 77 | * @access public |
78 | - * @param string $actionName | |
79 | - * @param string $httpMethod | |
78 | + * @param Kaede_Core_ActionInfo $actionInfo | |
79 | + * @param string $actionMethod | |
80 | 80 | * @param string $contextKey |
81 | 81 | * @return boolean |
82 | 82 | */ |
83 | - function dispatch($actionName, $httpMethod, $contextKey) | |
83 | + function dispatch($actionInfo, $actionMethod, $contextKey) | |
84 | 84 | { |
85 | + $actionName = $actionInfo->getName(); | |
86 | + | |
85 | 87 | if(!$contextKey) { |
86 | - return $this->startNewContext($actionName, $httpMethod); | |
88 | + return $this->startNewContext($actionInfo, $actionMethod); | |
87 | 89 | } |
88 | 90 | |
89 | 91 | if(is_null($context =& $this->session->getContext($contextKey))) { |
@@ -29,12 +29,12 @@ | ||
29 | 29 | /** |
30 | 30 | * |
31 | 31 | * @access public |
32 | - * @param string $actionName | |
33 | - * @param string $httpMethod | |
32 | + * @param string $actionInfo | |
33 | + * @param string $actionMethod | |
34 | 34 | * @param string $contextKey |
35 | 35 | * @return boolean |
36 | 36 | */ |
37 | - function dispatch($actionName, $httpMethod, $contextKey) | |
37 | + function dispatch($actionInfo, $actionMethod, $contextKey) | |
38 | 38 | { |
39 | 39 | if(!$contextKey || is_null($context =& $this->session->getContext($contextKey))) { |
40 | 40 | $this->accessForbidden(); |
@@ -46,7 +46,7 @@ | ||
46 | 46 | return true; |
47 | 47 | } |
48 | 48 | |
49 | - if($actionName != $context->getCurrentAction()) { | |
49 | + if($actionInfo->getName() != $context->getCurrentAction()) { | |
50 | 50 | $this->accessForbidden(); |
51 | 51 | return false; |
52 | 52 | } |
@@ -54,7 +54,7 @@ | ||
54 | 54 | $method = "exec_post"; |
55 | 55 | $result = $context->invoke($method); |
56 | 56 | $context->invoke("after_post", array('method' => $method, |
57 | - 'httpMethod' => $httpMethod, | |
57 | + 'actionMethod' => $actionMethod, | |
58 | 58 | 'result' => $result)); |
59 | 59 | return $result; |
60 | 60 | } |
@@ -83,7 +83,7 @@ | ||
83 | 83 | $this->session->start(); |
84 | 84 | |
85 | 85 | $dispatcher =& $this->getDispatcher($actionInfo, $httpMethod, $contextKey); |
86 | - $dispatcher->dispatch($actionInfo->getName(), $actionMethod, $contextKey); | |
86 | + $dispatcher->dispatch($actionInfo, $actionMethod, $contextKey); | |
87 | 87 | |
88 | 88 | $this->response->send(); |
89 | 89 | $this->session->endRequest(); |
@@ -40,12 +40,12 @@ | ||
40 | 40 | /** |
41 | 41 | * |
42 | 42 | * @access public |
43 | - * @param string $actionName | |
44 | - * @param string $httpMethod | |
43 | + * @param Kaede_Core_ActionInfo $actionInfo | |
44 | + * @param string $actionMethod | |
45 | 45 | * @param string $contextKey |
46 | 46 | * @return boolean |
47 | 47 | */ |
48 | - function dispatch($actionName, $httpMethod, $contextKey) | |
48 | + function dispatch($actionInfo, $actionMethod, $contextKey) | |
49 | 49 | { |
50 | 50 | } |
51 | 51 |