hi,
i have some problems with model testing, please help me out.
my setup: cakephp 1.2 ver. 6311.
here is my model:
class Author extends AppModel {
var $name = 'Author';
//var $useTable = 'authors';
var $hasAndBelongsToMany = array("Book" =>
array('className' => 'Book',
'joinTable' => 'books_authors',
'foreignKey' => 'author_id',
'associationForeignKey' => 'book_id',
'conditions' => '',
'order' => '',
'limit' => '',
'uniq' => true,
'finderQuery' => '',
'deleteQuery' => '',
'insertQuery' => ''
)
);
public function store($author) {
$this->recursive = 0;
$a = $this->findByName($author);
if(empty($a)) {
$this->data[$this->name]['name'] = $author;
$this->save($this->data, false);
$authorId = $this->id;
} else {
$authorId = $a[$this->name]['id'];
}
return $authorId;
}
}
fixture class:
class AuthorTestFixture extends CakeTestFixture {
var $name = 'AuthorTest';
var $import = 'Author';
var $records = array(
array ('id' => 1, 'name' => 'author 1', 'created' => '2007-06-03
10:39:23', 'status' => 1, 'modified' => '2007-06-03 10:39:23'),
array ('id' => 2, 'name' => 'author 2', 'created' => '2007-06-03
10:39:23', 'status' => 1, 'modified' => '2007-06-03 10:39:23'),
array ('id' => 3, 'name' => 'author 3', 'created' => '2007-06-03
10:39:23', 'status' => 1, 'modified' => '2007-06-03 10:39:23')
);
}
and this is my test class:
class AuthorTest extends Author {
var $name = 'AuthorTest';
var $useDbConfig = 'test_suite';
var $useTable = 'test_suite_author_tests';
}
class AuthorTestCase extends CakeTestCase {
var $fixtures = array( 'author_test' );
function testStore() {
$this->AuthorTest =& new AuthorTest();
$result = $this->AuthorTest->store("author 1");
$this->assertEqual($result, "1");
}
}
if i define the table name with the useTable variable my test works
well.
but if i comment out the "var $useTable = 'test_suite_author_tests';"
line i've got the following error:
Error: Database table author_tests for model AuthorTest was not
found.
the fixture part creates the "test_suite_author_tests" and populates
the data.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---