More Info:
I just tested with latest version of the 1.3-dev branch and I have the same
issue.

Here are my fixtures and db schema:

<?php
/* BadWord Fixture generated on: 2010-05-20 11:05:17 : 1274374157 */
class BadWordFixture extends CakeTestFixture {
var $name = 'BadWord';

var $import = array('table'=>'bad_words', 'connection'=>'default',
'records'=>true);
}
?>


<?php
/* Like Fixture generated on: 2010-05-19 15:05:05 : 1274299565 */
class LikeFixture extends CakeTestFixture {
 var $name = 'Like';

var $import = array('table'=>'likes', 'connection'=>'default',
'records'=>false);
 var $records = array(
array(
 'id' => 1,
'fbid' => 234567, //This is Mariluz Gonzalez
 'suggestion_id' => 1
),
array(
 'id' => 2,
'fbid' => 234567, //This is Mariluz Gonzalez
 'suggestion_id' => 2
),
array(
 'id' => 3,
'fbid' => 234567, //This is Mariluz Gonzalez
 'suggestion_id' => 5
),
 array(
'id' => 4,
'fbid' => 234567, //This is Mariluz Gonzalez
 'suggestion_id' => 6
)
);
}
?>


<?php
/* Suggestion Fixture generated on: 2010-05-19 11:05:58 : 1274288338 */
class SuggestionFixture extends CakeTestFixture {
 var $name = 'Suggestion';

var $import = array('table'=>'suggestions', 'connection'=>'default',
'records'=>false);

var $records = array(
array(
'id' => 1,
 'fbid' => 123456,
'user_name' => 'Rafael Vega',
 'song_name' => 'Lasso by Wolfgang Amadeus Phoenix',
'created' => '2010-05-18 11:58:58',
 'flavor' => 'Coffee',
'picture_url' => 'http://some.url.com/an_image.jpg'
 ),
array(
'id' => 2,
 'fbid' => 123456,
'user_name' => 'Rafael Vega',
 'song_name' => 'Electric Feel by MGMT',
'created' => '2010-05-18 15:58:58',
 'flavor' => 'Chocolate',
'picture_url' => 'http://some.url.com/an_image.jpg'
 ),
array(
'id' => 3,
 'fbid' => 234567,
'user_name' => 'Mariluz Gonzalez',
 'song_name' => 'Lady by Fela Kuti',
'created' => '2010-05-21 11:28:58',
 'flavor' => 'Strawberry',
'picture_url' => 'http://some.url.com/an_image.jpg'
 ),
array(
'id' => 4,
 'fbid' => 234567,
'user_name' => 'Mariluz Gonzalez',
 'song_name' => 'Zombie by Fela Kuti',
'created' => '2010-05-22 09:20:02',
 'flavor' => 'Vanilla',
'picture_url' => 'http://some.url.com/an_image.jpg'
 ),
array(
'id' => 5,
 'fbid' => 567890,
'user_name' => 'John Doe',
 'song_name' => 'Bad by Michael Jackson',
'created' => '2010-05-19 11:58:58',
 'flavor' => 'Coffee',
'picture_url' => 'http://some.url.com/an_image.jpg'
 ),
array(
'id' => 6,
 'fbid' => 678901,
'user_name' => 'Cheetah-Ra',
 'song_name' => 'Love Cats by the Cure',
'created' => '2010-05-19 15:58:58',
 'flavor' => 'Chocolate',
'picture_url' => 'http://some.url.com/an_image.jpg'
 ),
array(
'id' => 7,
 'fbid' => 789012,
'user_name' => 'Leon-Oh',
 'song_name' => 'Mas allá de lo evidente by Leo Dan',
'created' => '2010-05-21 11:28:58',
 'flavor' => 'Strawberry',
'picture_url' => 'http://some.url.com/an_image.jpg'
 ),
array(
'id' => 8,
 'fbid' => 890123,
'user_name' => 'Jane Tarzan',
 'song_name' => 'Welcome to the Jungle by Guns n\' Roses',
'created' => '2010-05-22 09:20:02',
 'flavor' => 'Coconut',
'picture_url' => 'http://some.url.com/an_image.jpg'
 )
);
}
?>

<?php
/* SVN FILE: $Id$ */
/* App schema generated on: 2010-05-21 11:05:01 : 1274461141*/
class AppSchema extends CakeSchema {
var $name = 'App';

function before($event = array()) {
return true;
}

function after($event = array()) {
}

var $accesses = array(
 'id' => array('type' => 'integer', 'null' => false, 'default' => NULL,
'key' => 'primary'),
 'api_key' => array('type' => 'string', 'null' => false, 'default' => ' ',
'key' => 'unique'),
 'secret' => array('type' => 'string', 'null' => false, 'default' => ' '),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1),
'unique_api_key' => array('column' => 'api_key', 'unique' => 1)),
 'tableParameters' => array('charset' => 'utf8', 'collate' =>
'utf8_general_ci', 'engine' => 'MyISAM')
 );
var $bad_words = array(
'id' => array('type' => 'integer', 'null' => false, 'default' => NULL, 'key'
=> 'primary'),
 'bad_word' => array('type' => 'string', 'null' => false, 'default' => ' '),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1)),
 'tableParameters' => array('charset' => 'utf8', 'collate' =>
'utf8_general_ci', 'engine' => 'InnoDB')
 );
var $likes = array(
'id' => array('type' => 'integer', 'null' => false, 'default' => NULL, 'key'
=> 'primary'),
 'fbid' => array('type' => 'integer', 'null' => false, 'default' => NULL,
'length' => 20),
 'suggestion_id' => array('type' => 'integer', 'null' => false, 'default' =>
NULL, 'key' => 'index'),
 'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1),
'suggestion_id' => array('column' => 'suggestion_id', 'unique' => 0)),
 'tableParameters' => array('charset' => 'utf8', 'collate' =>
'utf8_general_ci', 'engine' => 'InnoDB')
 );
var $suggestions = array(
'id' => array('type' => 'integer', 'null' => false, 'default' => NULL, 'key'
=> 'primary'),
 'fbid' => array('type' => 'integer', 'null' => false, 'default' => NULL,
'length' => 20),
 'user_name' => array('type' => 'string', 'null' => true, 'default' =>
NULL),
'song_name' => array('type' => 'string', 'null' => true, 'default' => NULL),
 'picture_url' => array('type' => 'string', 'null' => true, 'default' =>
NULL),
'flavor' => array('type' => 'string', 'null' => true, 'default' => NULL),
 'created' => array('type' => 'datetime', 'null' => true, 'default' =>
NULL),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1)),
 'tableParameters' => array('charset' => 'utf8', 'collate' =>
'utf8_general_ci', 'engine' => 'InnoDB')
 );
}
?>

2010/5/21 Rafael Vega <[email protected]>

>
> Hello.
> I am using cake 1.3.0 and php 5.2.13. I'm trying to test a controller
> (code is below) using fixtures and a subclass of CakeTestCase.
>
> When I run the test, I get a SQL error: "Table
> 'coolata_test.suggestions' doesn't exist". So I went debugging until I
> found line 287 in cake_test_case.php which removes the created
> database tables after the testAction method is run.
>
> I commented out that line and everything seemed to be working fine
> until on my testAdd() method I wanted to make assertions about the
> rendered output.
> There is a SQL statement added to the rendered output:
>
> Query: CREATE TABLE `suggestions` (
>        `id` int(11) NOT NULL AUTO_INCREMENT,
>        `fbid` int(20) NOT NULL,
>        `user_name` varchar(255) DEFAULT NULL,
>        `song_name` varchar(255) DEFAULT NULL,
>        `picture_url` varchar(255) DEFAULT NULL,
>        `flavor` varchar(255) DEFAULT NULL,
>        `created` datetime DEFAULT NULL,        PRIMARY KEY  (`id`))    ;
>
> This is because the table already exists.
>
> This issue preventing me from making assertions and testing my
> rendered output. I could test by making assertions about the variables
> passed to the view but since CakeWebTests cannot use fixtures, I'm
> trying to do that here.
>
> I believe this is a bug in the test suite but maybe I'm missing
> soething. Please help!
>
> The code:
>
> ********************************************
> ********************************************
> THE CONTROLLER:
> ********************************************
> ********************************************
> <?php
> class SuggestionsController extends AppController {
>
>        var $name = 'Suggestions';
>        var $helpers = array('xml', 'Cache');
>        var $layout = 'xml';
>
>        var $cacheAction = array('index' => 600); //cache the index action
> for 10 minutes
>
>        // GET /suggestions/
>        function index() {
>                if(!isset($this->params['url']['fbid']) || !is_int($this-
> >params['url']['fbid']))
>                        $fbid = 0;
>                else
>                        $fbid = $this->params['url']['fbid'];
>
>                $recent_suggestions = $this->Suggestion->getRecent($fbid);
>                $this->set('recent_suggestions', $recent_suggestions);
>        }
>
>        // POST /suggestions/add
>        function add() {
>                if($this->hasPermissions($this->data)){
>                        unset($this->data['id']);
>                        App::import('Sanitize');
>                        $clean_data = Sanitize::clean($this->data);
>                        $new_suggestion = array('Suggestion'=>$clean_data);
>                        if(!$this->Suggestion->save($new_suggestion)){
>                                $errs = $this->Suggestion->invalidFields();
>                                $msgs = array_values($errs);
>                                $error = array('code'=>400,
> 'message'=>$msgs[0]);
>                                $this->set('error',$error);
>                        }
>                }
>        }
> }
> ?>
>
> ********************************************
> ********************************************
> THE TEST:
> ********************************************
> ********************************************
> <?php
> /* Suggestions Test cases generated on: 2010-05-19 12:05:35 :
> 1274291795*/
> App::import('Controller', 'Suggestions');
>
> class SuggestionsControllerTestCase extends CakeTestCase {
>        var $fixtures = array('app.suggestion', 'app.like', 'app.bad_word');
>        var $autoFixtures = true;
>
>        function testIndex() {
>                $result = $this->testAction('/suggestions/',array(
>                        'return'=>'vars',
>                        'fixturize'=>true,
>                        'method'=>'get',
>                        'data'=>array('fbid'=>232323)
>                ));
>                $this->AssertFalse(isset($result['error']), 'Should not
> return
> error');
>                $this->AssertEqual(count($result['recent_suggestions']), 6,
> 'Should
> return 6 suggestions');
>        }
>
>        function testAdd() {
>                //Inserting a new suggestion.
>                $result = $this->testAction('/suggestions/add',array(
>                        'return'=>'render',
>                        'fixturize'=>true,
>                        'method'=>'post',
>                        'data'=>array(
>                                'fbid'=>232323,
>                                'user_name'=>'Some Nice Guy',
>                                'song_name'=>'Some Nice Song',
>                                'picture_url'=>'http://nice.com/picture.jpg
> ',
>                                'flavor'=>'sweet'
>                        )
>                ));
>                pr($result);
>        }
> }
> ?>
>
>
> ********************************************
> ********************************************
> THE UGLY HACK IN cake_test_case.php:
> ********************************************
> ********************************************
>
> /**
>  * Callback issued when a controller's action has been invoked through
> testAction().
>  *
>  * @param Controller $controller Controller that has been invoked.
>  * @param array $params Additional parameters as sent by testAction().
>  * @return void
>  * @access public
>  */
>        function endController(&$controller, $params = array()) {
>                if (isset($this->db) && isset($this->_actionFixtures) && !
> empty($this->_actionFixtures) && $this->dropTables) {
>                        foreach ($this->_actionFixtures as $fixture) {
>                                //$fixture->drop($this->db);
>               //HERE IT IS !!!!
>                        }
>                }
>        }
>



-- 
Rafael Vega
[email protected]

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" 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