Thursday, September 3, 2009

Re: Simpletest Model Test Cases with HABTM Relationsships delete Tables from Test Database

Solved in a way. I added all fixtures to the Model Test Cases like
this:

var $fixtures = array('app.message', 'app.tag', 'app.user');

Marco


On 3 Sep., 14:55, Marco <marco.lehman...@googlemail.com> wrote:
> Hi guys,
>
> I set up a really basic cake 1.2.4 project to verify a behaviour I
> observed.
>
> This is my database layout:
>
> CREATE TABLE `messages` (
>   `id` int(10) unsigned NOT NULL auto_increment,
>   `text` text NOT NULL,
>   `user_id` int(10) unsigned NOT NULL,
>   PRIMARY KEY  (`id`)
> ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
>
> CREATE TABLE `messages_tags` (
>   `message_id` int(10) unsigned NOT NULL,
>   `tag_id` int(10) unsigned NOT NULL,
>   UNIQUE KEY `message_id` (`message_id`,`tag_id`)
> ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
>
> CREATE TABLE `tags` (
>   `id` int(10) unsigned NOT NULL auto_increment,
>   `text` varchar(20) NOT NULL,
>   PRIMARY KEY  (`id`)
> ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
>
> CREATE TABLE `users` (
>   `id` int(10) unsigned NOT NULL auto_increment,
>   `name` varchar(100) NOT NULL,
>   `type` enum('default','admin') NOT NULL,
>   PRIMARY KEY  (`id`)
> ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
>
> Here are my fixtures (everything made by the bake shell):
>
> <?php
> /* SVN FILE: $Id$ */
> /* Message Fixture generated on: 2009-09-03 08:06:40 : 1251958000*/
>
> class MessageFixture extends CakeTestFixture {
>         var $name = 'Message';
>         var $table = 'messages';
>         var $fields = array(
>                 'id' => array('type'=>'integer', 'null' => false, 'default' => NULL,
> 'length' => 10, 'key' => 'primary'),
>                 'text' => array('type'=>'text', 'null' => false),
>                 'user_id' => array('type'=>'integer', 'null' => false, 'length' =>
> 10),
>                 'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' =>
> 1))
>         );
>         var $records = array(array(
>                 'id'  => 1,
>                 'text'  => 'Lorem ipsum dolor sit amet, aliquet feugiat. Convallis
> morbi fringilla gravida,phasellus feugiat dapibus velit nunc, pulvinar
> eget sollicitudin venenatis cum nullam,vivamus ut a sed, mollitia
> lectus. Nulla vestibulum massa neque ut et, id hendrerit sit,feugiat
> in taciti enim proin nibh, tempor dignissim, rhoncus duis vestibulum
> nunc mattis convallis.',
>                 'user_id'  => 1
>         ));}
>
> ?>
>
> <?php
> /* SVN FILE: $Id$ */
> /* Tag Fixture generated on: 2009-09-03 08:06:53 : 1251958013*/
>
> class TagFixture extends CakeTestFixture {
>         var $name = 'Tag';
>         var $table = 'tags';
>         var $fields = array(
>                 'id' => array('type'=>'integer', 'null' => false, 'default' => NULL,
> 'length' => 10, 'key' => 'primary'),
>                 'text' => array('type'=>'string', 'null' => false, 'length' => 20),
>                 'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' =>
> 1))
>         );
>         var $records = array(array(
>                 'id'  => 1,
>                 'text'  => 'Lorem ipsum dolor '
>         ));}
>
> ?>
>
> <?php
> /* SVN FILE: $Id$ */
> /* User Fixture generated on: 2009-09-03 08:07:04 : 1251958024*/
>
> class UserFixture extends CakeTestFixture {
>         var $name = 'User';
>         var $table = 'users';
>         var $fields = array(
>                 'id' => array('type'=>'integer', 'null' => false, 'default' => NULL,
> 'length' => 10, 'key' => 'primary'),
>                 'name' => array('type'=>'string', 'null' => false, 'length' => 100),
>                 'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' =>
> 1))
>         );
>         var $records = array(array(
>                 'id'  => 1,
>                 'name'  => 'Lorem ipsum dolor sit amet'
>         ));}
>
> ?>
>
> ... and my test cases:
>
> <?php
> /* SVN FILE: $Id$ */
> /* Message Test cases generated on: 2009-09-03 08:06:42 : 1251958002*/
> App::import('Model', 'Message');
>
> class MessageTestCase extends CakeTestCase {
>         var $Message = null;
>         var $fixtures = array('app.message', 'app.user');
>
>         function startTest() {
>                 $this->Message =& ClassRegistry::init('Message');
>         }
>
>         function testMessageInstance() {
>                 $this->assertTrue(is_a($this->Message, 'Message'));
>         }
>
>         function testMessageFind() {
>                 $this->Message->recursive = -1;
>                 $results = $this->Message->find('first');
>                 $this->assertTrue(!empty($results));
>
>                 $expected = array('Message' => array(
>                         'id'  => 1,
>                         'text'  => 'Lorem ipsum dolor sit amet, aliquet feugiat. Convallis
> morbi fringilla gravida,phasellus feugiat dapibus velit nunc, pulvinar
> eget sollicitudin venenatis cum nullam,vivamus ut a sed, mollitia
> lectus. Nulla vestibulum massa neque ut et, id hendrerit sit,feugiat
> in taciti enim proin nibh, tempor dignissim, rhoncus duis vestibulum
> nunc mattis convallis.',
>                         'user_id'  => 1
>                 ));
>                 $this->assertEqual($results, $expected);
>         }}
>
> ?>
>
> <?php
> /* SVN FILE: $Id$ */
> /* Tag Test cases generated on: 2009-09-03 08:06:53 : 1251958013*/
> App::import('Model', 'Tag');
>
> class TagTestCase extends CakeTestCase {
>         var $Tag = null;
>         var $fixtures = array('app.tag');
>
>         function startTest() {
>                 $this->Tag =& ClassRegistry::init('Tag');
>         }
>
>         function testTagInstance() {
>                 $this->assertTrue(is_a($this->Tag, 'Tag'));
>         }
>
>         function testTagFind() {
>                 $this->Tag->recursive = -1;
>                 $results = $this->Tag->find('first');
>                 $this->assertTrue(!empty($results));
>
>                 $expected = array('Tag' => array(
>                         'id'  => 1,
>                         'text'  => 'Lorem ipsum dolor '
>                 ));
>                 $this->assertEqual($results, $expected);
>         }}
>
> ?>
>
> <?php
> /* SVN FILE: $Id$ */
> /* User Test cases generated on: 2009-09-03 08:07:04 : 1251958024*/
> App::import('Model', 'User');
>
> class UserTestCase extends CakeTestCase {
>         var $User = null;
>         var $fixtures = array('app.user', 'app.message');
>
>         function startTest() {
>                 $this->User =& ClassRegistry::init('User');
>         }
>
>         function testUserInstance() {
>                 $this->assertTrue(is_a($this->User, 'User'));
>         }
>
>         function testUserFind() {
>                 $this->User->recursive = -1;
>                 $results = $this->User->find('first');
>                 $this->assertTrue(!empty($results));
>
>                 $expected = array('User' => array(
>                         'id'  => 1,
>                         'name'  => 'Lorem ipsum dolor sit amet'
>                 ));
>                 $this->assertEqual($results, $expected);
>         }}
>
> ?>
>
> Running the corresponding controller tests is no problem. I get a
> green bar. But running the model tests fails. Running the Message
> Model Test passes with no errors, but deletes the tables Messages and
> Users.
>
> I'm confused. Can anyone help?
>
> Thanks in advance.
> Marco
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: