Skip to content

Commit

Permalink
Start tests for magic finder methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Dec 1, 2013
1 parent 01f89f8 commit ad11d7f
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions Cake/Test/TestCase/ORM/TableTest.php
Expand Up @@ -1941,4 +1941,46 @@ public function testAfterValidate() {
$this->assertEquals(['Not good'], $entity->errors('username'));
}

/**
* Test magic findByXX method.
*
* @return void
*/
public function testMagicFindFirst() {
$table = TableRegistry::get('Users');

$result = $table->findByUsername('garrett');
$this->assertInstanceOf('Cake\ORM\Query', $result);
$this->assertEquals(1, $result->limit());
$this->assertEquals(['username' => 'garrett'], $result->clause('where'));

$result = $table->findByUsernameAndId('garrett', 4);
$this->assertInstanceOf('Cake\ORM\Query', $result);
$this->assertEquals(1, $result->limit());
$this->assertEquals(['username' => 'garrett'], $result->clause('where'));
}

/**
* Test magic findAllByXX method.
*
* @return void
*/
public function testMagicFindAll() {
$table = TableRegistry::get('Articles');

$result = $table->findAllByAuthorId(1);
$this->assertInstanceOf('Cake\ORM\Query', $result);
$this->assertEquals(null, $result->limit());
$this->assertEquals(['author_id' => '1'], $result->clause('where'));

$result = $table->findAllByAuthorIdOrPublished(1, 'Y');
$this->assertInstanceOf('Cake\ORM\Query', $result);
$this->assertEquals(null, $result->limit());
$expected = [
'author_id' => 1,
'published' => 'Y',
];
$this->assertEquals($expected, $result->clause('where'));
}

}

0 comments on commit ad11d7f

Please sign in to comment.