Great! Thanks Mariano.
I downloaded the code yesterday and see the testAction method which i
did not have in the previous version. Thanks for your help, I will
give this a try
Krishnan
On Apr 23, 3:28 pm, "Mariano Iglesias" <[EMAIL PROTECTED]>
wrote:
> I haven't had time to write a Bakery article regarding this, but update to
> latest SVN head and look for testAction() in CakeTestSuite. I still have to
> add a couple of things but I'll try to give you an idea here:
>
> Say you have typical Articles controller, with articles model, and it looks
> like this:
>
> <?php
>
> class ArticlesController extends AppController {
> var $name = 'Articles';
> var $helpers = array('Ajax', 'Form', 'Html');
>
> function index($short = null) {
> if (!empty($this->data)) {
> $this->Article->save($this->data);
> }
>
> if (!empty($short)) {
> $result = $this->Article->findAll(null, array('id',
> 'title'));
> } else {
> $result = $this->Article->findAll();
> }
>
> if (isset($this->params['requested'])) {
> return $result;
> }
>
> $this->set('title', 'Articles');
> $this->set('articles', $result);
> }
>
> }
>
> ?>
>
> Create then a file named articles_controller.test.php on your
> app/tests/cases/controllers directory and inside put:
>
> <?php
>
> class ArticlesControllerTest extends CakeTestCase {
> function startCase() {
> echo '<h1>StartingTestCase</h1>';
> }
>
> function endCase() {
> echo '<h1>EndingTestCase</h1>';
> }
>
> function startTest($method) {
> echo '<h3>Starting method ' . $method . '</h3>';
> }
>
> function endTest($method) {
> echo '<hr />';
> }
>
> function testIndex() {
> $result = $this->testAction('/articles/index');
> debug($result);
> }
>
> function testIndexShort() {
> $result = $this->testAction('/articles/index/short');
> debug($result);
> }
>
> function testIndexShortGetRenderedHtml() {
> $result = $this->testAction('/articles/index/short',
> array('return' => 'render'));
> debug(htmlentities($result));
> }
>
> function testIndexShortGetViewVars() {
> $result = $this->testAction('/articles/index/short',
> array('return' => 'vars'));
> debug($result);
> }
>
> function testIndexFixturized() {
> $result = $this->testAction('/articles/index/short',
> array('fixturize' => true));
> debug($result);
> }
>
> function testIndexPostFixturized() {
> $data = array('Article' => array('user_id' => 1, 'published'
> => 1, 'slug'=>'new-article', 'title' => 'New Article', 'body' => 'New
> Body'));
> $result = $this->testAction('/articles/index',
> array('fixturize' => true, 'data' => $data, 'method' => 'post'));
> debug($result);
> }
>
> }
>
> ?>
>
> Ok couple of things:
>
> * In second parameter of testAction() you send an array with attributes.
> Among others use:
>
> - return: set to what you want returned. Valid values are: 'vars'
> (so you get the view vars available after executing action), 'render' (so
> you get html generated once action is run), or 'return' to get the returned
> value when action uses $this->params['requested']. Default is 'return'.
>
> - fixturize: set to true if you want your models auto-fixturized (so
> your application tables get copied, along with their records, totesttables
> so if you change data it does not affect your real application.) If you set
> 'fixturize' to an array of models, then only those models will be
> auto-fixturized while the other will remain with live tables.
>
> - data: see last item
>
> - method: see last item
>
> * testAction()can auto-fixturize the model so if yourtestsubmits data (and
> therefore saves records, see next item) you can safely do it ontesttables,
> automatically created for you.
>
> * You can POST data as POST or GET using the 'data' setting, where you set
> it to be an associative array consisting of fields => value. Take a look at
> function testIndexPostFixturized() in abovetestcase to see how we emulate
> posting form data for a new article submission.
>
> -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
>
> -----Mensaje original-----
> De: [email protected] [mailto:[EMAIL PROTECTED] En nombre
> de ks
> Enviado el: Lunes, 23 de Abril de 2007 05:44 p.m.
> Para: Cake PHP
> Asunto: Re: whats the relationship between CakePHP 1.2testsuiteN
> SimpleTest
>
> Do you know when that will be available in ? We currently need to
> write unit tests for our controllers and I am debating if we should
> wait until this is released or use testsuite in the meantime and move
> to CakeTest once thats available?
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---