Skip to content

Commit

Permalink
Update requestAction() test methods.
Browse files Browse the repository at this point in the history
These methods instead of returning arrays now set the reponse body
with serialized data.
  • Loading branch information
ADmad committed Mar 28, 2014
1 parent 08477e8 commit 5ad0555
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 20 deletions.
29 changes: 19 additions & 10 deletions tests/TestCase/Routing/RequestActionTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function testRequestAction() {
$this->assertEquals($expected, $result);

$result = $this->object->requestAction('/request_action/paginate_request_action');
$this->assertTrue($result);
$this->assertNull($result);

$result = $this->object->requestAction('/request_action/normal_request_action');
$expected = 'Hello World';
Expand Down Expand Up @@ -158,13 +158,13 @@ public function testRequestActionArray() {
$result = $this->object->requestAction(
array('controller' => 'request_action', 'action' => 'paginate_request_action')
);
$this->assertTrue($result);
$this->assertNull($result);

$result = $this->object->requestAction(
array('controller' => 'request_action', 'action' => 'paginate_request_action'),
array('pass' => array(5))
);
$this->assertTrue($result);
$this->assertNull($result);
}

/**
Expand All @@ -186,10 +186,11 @@ public function testRequestActionRemoveReturnParam() {
*/
public function testRequestActionParamParseAndPass() {
$result = $this->object->requestAction('/request_action/params_pass');
$this->assertEquals('request_action/params_pass', $result->url);
$this->assertEquals('request_action', $result['controller']);
$this->assertEquals('params_pass', $result['action']);
$this->assertEquals(null, $result['plugin']);
$result = unserialize($result);
$this->assertEquals('request_action/params_pass', $result['url']);
$this->assertEquals('request_action', $result['params']['controller']);
$this->assertEquals('params_pass', $result['params']['action']);
$this->assertNull($result['params']['plugin']);
}

/**
Expand All @@ -203,13 +204,14 @@ public function testRequestActionNoPostPassing() {
'item' => 'value'
);
$result = $this->object->requestAction(array('controller' => 'request_action', 'action' => 'post_pass'));
$expected = null;
$result = unserialize($result);
$this->assertEmpty($result);

$result = $this->object->requestAction(
array('controller' => 'request_action', 'action' => 'post_pass'),
array('post' => $_POST)
);
$result = unserialize($result);
$expected = $_POST;
$this->assertEquals($expected, $result);
}
Expand All @@ -228,18 +230,21 @@ public function testRequestActionWithQueryString() {
['controller' => 'request_action', 'action' => 'query_pass'],
['query' => $query]
);
$result = unserialize($result);
$this->assertEquals($query, $result);

$result = $this->object->requestAction([
'controller' => 'request_action',
'action' => 'query_pass',
'?' => $query
]);
$result = unserialize($result);
$this->assertEquals($query, $result);

$result = $this->object->requestAction(
'/request_action/query_pass?page=3&sort=body'
);
$result = unserialize($result);
$expected = ['page' => 3, 'sort' => 'body'];
$this->assertEquals($expected, $result);
}
Expand All @@ -257,12 +262,14 @@ public function testRequestActionPostWithData() {
array('controller' => 'request_action', 'action' => 'post_pass'),
array('post' => $data)
);
$result = unserialize($result);
$this->assertEquals($data, $result);

$result = $this->object->requestAction(
'/request_action/post_pass',
array('post' => $data)
);
$result = unserialize($result);
$this->assertEquals($data, $result);
}

Expand All @@ -275,13 +282,15 @@ public function testRequestActionGetParameters() {
$result = $this->object->requestAction(
'/request_action/params_pass?get=value&limit=5'
);
$this->assertEquals('value', $result->query['get']);
$result = unserialize($result);
$this->assertEquals('value', $result['query']['get']);

$result = $this->object->requestAction(
array('controller' => 'request_action', 'action' => 'params_pass'),
array('query' => array('get' => 'value', 'limit' => 5))
);
$this->assertEquals('value', $result->query['get']);
$result = unserialize($result);
$this->assertEquals('value', $result['query']['get']);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function index() {
}

public function some_method() {
return 25;
$this->response->body(25);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ class OrangeSessionTestController extends Controller {
/**
* session_id method
*
* @return string
* @return void
*/
public function session_id() {
return $this->Session->id();
$this->response->body($this->Session->id());
}
}
12 changes: 8 additions & 4 deletions tests/test_app/TestApp/Controller/RequestActionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function paginate_request_action() {
* @return array
*/
public function post_pass() {
return $this->request->data;
$this->response->body(serialize($this->request->data));
}

/**
Expand All @@ -96,16 +96,20 @@ public function post_pass() {
* @return array
*/
public function query_pass() {
return $this->request->query;
$this->response->body(serialize($this->request->query));
}

/**
* test param passing and parsing.
*
* @return array
* @return void
*/
public function params_pass() {
return $this->request;
$this->response->body(serialize([
'params' => $this->request->params,
'query' => $this->request->query,
'url' => $this->request->url
]));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/test_app/TestApp/Controller/SessionTestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ class SessionTestController extends Controller {
/**
* session_id method
*
* @return string
* @return void
*/
public function session_id() {
return $this->Session->id();
$this->response->body($this->Session->id());
}
}
2 changes: 1 addition & 1 deletion tests/test_app/TestApp/Controller/TestsAppsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function index() {
}

public function some_method() {
return 5;
$this->response->body(5);
}

public function set_action() {
Expand Down

0 comments on commit 5ad0555

Please sign in to comment.