Skip to content
Permalink
Browse files

Unit tests added.

  • Loading branch information...
Nicolas
Nicolas committed Nov 17, 2012
1 parent 9c7f357 commit 1b704fb7cf4d3b18e883a9979fe0e87983c7dec4
Showing with 13 additions and 69 deletions.
  1. +13 −69 lib/Cake/Test/Case/Model/Datasource/DboSourceTest.php
@@ -159,6 +159,19 @@ public function testBooleanNullConditionsParsing() {
$this->assertEquals(' WHERE 1 = 1', $result);
}
/**
* test that booleans work on empty set.
*
* @return void
*/
public function testBooleanEmptyConditionsParsing() {
$result = $this->testDb->conditions(array('OR' => array()));
$this->assertEquals(' WHERE 1 = 1', $result, 'empty conditions failed %s');
$result = $this->testDb->conditions(array('OR' => array('OR' => array())));
$this->assertEquals(' WHERE 1 = 1', $result, 'nested empty conditions failed %s');
}
/**
* test that order() will accept objects made from DboSource::expression
*
@@ -1103,73 +1116,4 @@ public function testBuildJoinStatement($join, $expected) {
$this->assertEquals($expected, $result);
}
/**
* Test conditionKeysToString()
*
* @return void
*/
public function testConditionKeysToString() {
$Article = ClassRegistry::init('Article');
$conn = $this->getMock('MockPDO', array('quote'));
$db = new DboTestSource;
$db->setConnection($conn);
$conn->expects($this->at(0))
->method('quote')
->will($this->returnValue('just text'));
$conditions = array('Article.name' => 'just text');
$result = $db->conditionKeysToString($conditions, true, $Article);
$expected = "Article.name = just text";
$this->assertEquals($expected, $result[0]);
$conn->expects($this->at(0))
->method('quote')
->will($this->returnValue('just text'));
$conn->expects($this->at(1))
->method('quote')
->will($this->returnValue('other text'));
$conditions = array('Article.name' => array('just text', 'other text'));
$result = $db->conditionKeysToString($conditions, true, $Article);
$expected = "Article.name IN (just text, other text)";
$this->assertEquals($expected, $result[0]);
}
/**
* Test conditionKeysToString() with virtual field
*
* @return void
*/
public function testConditionKeysToStringVirtualField() {
$Article = ClassRegistry::init('Article');
$Article->virtualFields = array(
'extra' => 'something virtual'
);
$conn = $this->getMock('MockPDO', array('quote'));
$db = new DboTestSource;
$db->setConnection($conn);
$conn->expects($this->at(0))
->method('quote')
->will($this->returnValue('just text'));
$conditions = array('Article.extra' => 'just text');
$result = $db->conditionKeysToString($conditions, true, $Article);
$expected = "(" . $Article->virtualFields['extra'] . ") = just text";
$this->assertEquals($expected, $result[0]);
$conn->expects($this->at(0))
->method('quote')
->will($this->returnValue('just text'));
$conn->expects($this->at(1))
->method('quote')
->will($this->returnValue('other text'));
$conditions = array('Article.extra' => array('just text', 'other text'));
$result = $db->conditionKeysToString($conditions, true, $Article);
$expected = "(" . $Article->virtualFields['extra'] . ") IN (just text, other text)";
$this->assertEquals($expected, $result[0]);
}
}

0 comments on commit 1b704fb

Please sign in to comment.
You can’t perform that action at this time.