If you download latest CakePHP 1.2 revision there's now a new method to call
CakePHP urls from any test case that inherits CakeTestCase. Take a look at
method requestAction() in this changeset:
https://trac.cakephp.org/changeset/4863
Let's say we have the following controller:
<?php
class ArticlesController extends AppController {
var $name = 'Articles';
function index($short = null) {
if (!empty($short)) {
$result = $this->Article->findAll(null, array('id',
'title'));
} else {
$result = $this->Article->findAll();
}
if (isset($this->params['requested'])) {
if (!empty($this->data)) {
$result = am($result,
array('data'=>$this->data));
}
return $result;
}
}
}
?>
And now the following test case, where you can see:
1. New callbacks startCase(), endCase(), startTest(), and endTest() in
action.
2. Different test methods to test CakePHP URL execution, getting rendered
view html code, and sending data as POST to Cake action.
<?php
class ArticlesControllerTest extends CakeTestCase {
function startCase() {
echo '<h1>Starting Test Case</h1>';
}
function endCase() {
echo '<h1>Starting Test Case</h1>';
}
function startTest($method) {
echo '<h3>Starting method ' . $method . '</h3>';
}
function endTest($method) {
echo '<hr />';
}
function testIndex() {
$result = $this->requestAction('/articles/index');
debug($result);
}
function testIndexShort() {
$result = $this->requestAction('/articles/index/short');
debug($result);
}
function testIndexShortGetRenderedHtml() {
$result = $this->requestAction('/articles/index/short',
false);
debug(htmlentities($result));
}
function testIndexShortPostData() {
$data = array('Article' => array(
'id' => 4,
'title' => 'New Title'
));
$result = $this->requestAction('/articles/index', true,
$data, 'post');
debug($result);
}
}
?>
-MI
---------------------------------------------------------------------------
Remember, smart coders answer ten questions for every question they ask.
So be smart, be cool, and share your knowledge.
BAKE ON!
blog: http://www.MarianoIglesias.com.ar
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---