Re: whats the relationship between CakePHP 1.2 test suite N SimpleTest

2007-05-09 Thread ks

Mariano,

Am I missing something simple? Can you let me know an example were you
were able to use with redirect? Should I do something different in my
application.

I am keen to use your new framework for our unit tests but right now I
am blocked on this.

Thanks
Krishnan

On May 1, 8:26 am, ks [EMAIL PROTECTED] wrote:
 Mariano,

 I have tried writing some tests. This looks great. Thanks.

 I am running into an issue when my controller actions is doing
 redirects. For e.g. in my login action, the user is redirected to
 another page if login is successful. However the cake redirect
 function has an exit in it ( which is useful for the web application)
 but thetestframework exits when that happens.

 What is the best way to handle this? In TestSuite, I think the
 dispatch maybe handled differently since I was able totestthe same
 action with a post.

 Thanks
 Krishnan

 On Apr 25, 2:04 am, ks [EMAIL PROTECTED] wrote:

  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 'h1StartingTestCase/h1';
   }

   function endCase() {
   echo 'h1EndingTestCase/h1';
   }

   function startTest($method) {
   echo 'h3Starting 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 

Re: whats the relationship between CakePHP 1.2 test suite N SimpleTest

2007-05-01 Thread ks

Mariano,

I have tried writing some tests. This looks great. Thanks.

I am running into an issue when my controller actions is doing
redirects. For e.g. in my login action, the user is redirected to
another page if login is successful. However the cake redirect
function has an exit in it ( which is useful for the web application)
but the test framework exits when that happens.

What is the best way to handle this? In TestSuite, I think the
dispatch maybe handled differently since I was able to test the same
action with a post.

Thanks
Krishnan

On Apr 25, 2:04 am, ks [EMAIL PROTECTED] wrote:
 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 'h1StartingTestCase/h1';
  }

  function endCase() {
  echo 'h1EndingTestCase/h1';
  }

  function startTest($method) {
  echo 'h3Starting 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 

Re: whats the relationship between CakePHP 1.2 test suite N SimpleTest

2007-04-25 Thread ks

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 'h1StartingTestCase/h1';
 }

 function endCase() {
 echo 'h1EndingTestCase/h1';
 }

 function startTest($method) {
 echo 'h3Starting 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: cake-php@googlegroups.com [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 

Re: whats the relationship between CakePHP 1.2 test suite N SimpleTest

2007-04-23 Thread ks

Mariano,

Great!

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?

Thanks
Krishnan

On Apr 17, 10:37 am, Mariano Iglesias [EMAIL PROTECTED]
wrote:
 Be a little patient and you are about to see some awesome stuff in 
 Caketestsuitetotestcontrollers.

 -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: cake-php@googlegroups.com [mailto:[EMAIL PROTECTED] En nombre
 de ks
 Enviado el: Martes, 17 de Abril de 2007 01:55 p.m.
 Para: Cake PHP
 Asunto: Re: whats the relationship between CakePHP 1.2testsuiteN
 SimpleTest

 Not sure if someone has found a way totestcontrollers with get/post
 in CakeTest


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: whats the relationship between CakePHP 1.2 test suite N SimpleTest

2007-04-17 Thread ks

Both use SimpleTest. In the case of test suite, you have add that in
your vendors folder as well.

From what I was able to do:

TestSuite allows you to test your controllers using get/post as well
which is useful. I did not find that in the CakeTest

TestSuite integrates with bake2 and can run from the command line as
well. Although with a small change to test.php ( that cake uses) you
can get that working from the command line as well.

Not sure if someone has found a way to test controllers with get/post
in CakeTest


On Apr 16, 5:49 am, hydra12 [EMAIL PROTECTED] wrote:
 I may be wrong, but I think it works like this:

 The cake testsuite (and cakebaker's) are wrappers for simpletest.
 Simpletest is used as a vendor, and the testsuite 'cake-ifies' it.
 (Is that a word?  Probably not . . .)  Anyway, simpletest is doing the
 actual testing, but the test suite makes everything work in a cakey
 way (loading models, controllers, etc).

 I hope that helps.  Somebody please correct me if I'm wrong.

 hydra12

 On Apr 16, 5:37 am, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:

  whats the relationship between CakePHP 1.2 test suite N SimpleTest?

  is test suite new feature of the 1.2 ? and does test suite just use
  SimpleTest as fundamental?
  and when you download and put SimpleTest in right place ,it enable the
  test suite??

  and when use bake.php ,it seems like it output test for SimpleTest not
  cakephp test suite .but why ?


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



RE: whats the relationship between CakePHP 1.2 test suite N SimpleTest

2007-04-17 Thread Mariano Iglesias

Be a little patient and you are about to see some awesome stuff in Cake test
suite to test controllers.

-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: cake-php@googlegroups.com [mailto:[EMAIL PROTECTED] En nombre
de ks
Enviado el: Martes, 17 de Abril de 2007 01:55 p.m.
Para: Cake PHP
Asunto: Re: whats the relationship between CakePHP 1.2 test suite N
SimpleTest

Not sure if someone has found a way to test controllers with get/post
in CakeTest


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: whats the relationship between CakePHP 1.2 test suite N SimpleTest

2007-04-17 Thread Sonic Baker
On 4/17/07, Mariano Iglesias [EMAIL PROTECTED] wrote:


 Be a little patient and you are about to see some awesome stuff in Cake
 test
 suite to test controllers.


Wicked I'm going to hold you to that now Mariano :)

Sonic

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: whats the relationship between CakePHP 1.2 test suite N SimpleTest

2007-04-16 Thread hydra12

I may be wrong, but I think it works like this:

The cake testsuite (and cakebaker's) are wrappers for simpletest.
Simpletest is used as a vendor, and the testsuite 'cake-ifies' it.
(Is that a word?  Probably not . . .)  Anyway, simpletest is doing the
actual testing, but the test suite makes everything work in a cakey
way (loading models, controllers, etc).

I hope that helps.  Somebody please correct me if I'm wrong.

hydra12

On Apr 16, 5:37 am, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 whats the relationship between CakePHP 1.2 test suite N SimpleTest?

 is test suite new feature of the 1.2 ? and does test suite just use
 SimpleTest as fundamental?
 and when you download and put SimpleTest in right place ,it enable the
 test suite??

 and when use bake.php ,it seems like it output test for SimpleTest not
 cakephp test suite .but why ?


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---