Davide said:
> Davide said:
>> The main problem is that I don't know how to use the testsuite, so I
>> ...

> Actually I've solved in this way[1] and seems to work. I would like to
> know if this is the right way to proceed or there's a better way to do
> that: something more automatic.
> ...

ok, here it is a way to make it working. I still don't know if it's the
right way to do things but it seems to works right.

Following the code of the tests and of the controller.

If someone has any other ideas or know how to use the suite, he/she is
welcome :)

Thanks a lot
Bye
Davide

<?php
/*
 * app/test/app/controllers/posts_controller.test.php
 */

class PostsControllerTest extends UnitTestCase{
   var $posts = null;

   function PostsControllerTest($label=false){
      parent::UnitTestCase($label);
      loadController("posts");
      loadModel("post");
      $this->posts =& new PostsController();
      $this->posts->Post =& new Post();
   }

   function testIndex(){
      $this->posts->index();
      //do we get something?
      $this->assertTrue(is_array($this->posts->data));
   }

   function testAdd(){
      //trying to view the page
      $this->assertTrue($this->posts->add());

      //try insert a right post
      $this->posts->data["Post"]["title"] = "UnitTest";
      $this->posts->data["Post"]["body"] = "UnitTest";
      $this->assertTrue($this->posts->add());

      //try insert a wrong post (should hang up)
      $this->posts->data["Post"]["title"] = "";
      $this->posts->data["Post"]["body"] = "";
      $this->assertFalse($this->posts->add());
   }
}
?>

<?php
/*
 * app/controllers/posts_controller.php
 */
class PostsController extends AppController{
    var $name = 'Posts';

    function index(){
        $this->set('data',$this->Post->findAll());
    }

    function add(){
        $ret = false;
        if(empty($this->data)){
            $ret = true;
        }else{
            if($this->Post->save($this->data)){
                $this->flash("Your post has been saved","/posts");
                $ret = true;
            }else{
                $this->set('data',$this->data);
                $this->validateErrors($this->Post);
            }
        }
        return $ret;
    }
    ...
}
?>


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to