/** * testFindMagic method * * @return void */ public function testFindMagic() { $this->loadFixtures('User'); $TestModel = new User(); $result = $TestModel->findByUser('mariano'); $expected = array('User' => array('id' => '1', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31')); $this->assertEquals($expected, $result); $result = $TestModel->findByPassword('5f4dcc3b5aa765d61d8327deb882cf99'); $expected = array('User' => array('id' => '1', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31')); $this->assertEquals($expected, $result); }
/** * testFindMagic method * * @return void */ public function testFindMagic() { $this->loadFixtures('User', 'Comment', 'Article'); $TestModel = new User(); $result = $TestModel->findByUser('mariano'); $expected = array('User' => array('id' => '1', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31')); $this->assertEquals($expected, $result); $result = $TestModel->findByPassword('5f4dcc3b5aa765d61d8327deb882cf99'); $expected = array('User' => array('id' => '1', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31')); $this->assertEquals($expected, $result); $Comment = new Comment(); $Comment->recursive = -1; $results = $Comment->findAllByUserId(1); $expected = array(array('Comment' => array('id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31')), array('Comment' => array('id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article', 'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31')), array('Comment' => array('id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31'))); $this->assertEquals($expected, $results); $results = $Comment->findAllByUserIdAndPublished(1, 'Y'); $expected = array(array('Comment' => array('id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31')), array('Comment' => array('id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31'))); $this->assertEquals($expected, $results); $Article = new CustomArticle(); $Article->recursive = -1; $results = $Article->findListByUserId(1); $expected = array(1 => 'First Article', 3 => 'Third Article'); $this->assertEquals($expected, $results); $results = $Article->findPublishedByUserId(1); $expected = array(array('CustomArticle' => array('id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31')), array('CustomArticle' => array('id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'))); $this->assertEquals($expected, $results); $results = $Article->findUnPublishedByUserId(1); $expected = array(); $this->assertEquals($expected, $results); }