testのデータ(フィクスチャ)の作成


simpletestをする際のtestデータ作成
http://book.cakephp.org/ja/view/360/Creating-fixtures



モデル名にフィクスチャを宣言する


var $fixtures = array( 'app.モデル名' );



宣言するとtestのテーブルが使用されて、
testのテーブルに下記で登録したデータが入れられる。

app/tests/fixturesモデル名_fixtures.phpに以下を記述


class ArticleFixture extends CakeTestFixture {
var $name = 'Article';

//テーブルにあるフィールドはすべて宣言してあげないといけない
var $fields = array(
'id' => array('type' => 'integer', 'key' => 'primary'),
'title' => array('type' => 'string', 'length' => 255, 'null' => false),
'body' => 'text',
'published' => array('type' => 'integer', 'default' => '0', 'null' => false),
'created' => 'datetime',
'updated' => 'datetime'
);
var $records = array(
array ('id' => 1, 'title' => '1番目の記事', 'body' => '1番目の記事の内容', 'published' => '1', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'),
array ('id' => 2, 'title' => '2番目の記事', 'body' => '2番目の記事の内容', 'published' => '1', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'),
array ('id' => 3, 'title' => '3番目の記事', 'body' => '3番目の記事の内容', 'published' => '1', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31')
);
}







bakeのsimpletestの作成の選択でYESを選択すると
自動的に作ってくれるので便利!!!