Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added accidentally removed tests back in.

  • Loading branch information...
commit a77e46cbfda7786e1ff51f84995e7b90900c77d4 1 parent 1b704fb
Nicolas authored
Showing with 71 additions and 2 deletions.
  1. +71 −2 lib/Cake/Test/Case/Model/Datasource/DboSourceTest.php
View
73 lib/Cake/Test/Case/Model/Datasource/DboSourceTest.php
@@ -166,10 +166,10 @@ public function testBooleanNullConditionsParsing() {
*/
public function testBooleanEmptyConditionsParsing() {
$result = $this->testDb->conditions(array('OR' => array()));
- $this->assertEquals(' WHERE 1 = 1', $result, 'empty conditions failed %s');
+ $this->assertEquals(' WHERE 1 = 1', $result, 'empty conditions failed');
$result = $this->testDb->conditions(array('OR' => array('OR' => array())));
- $this->assertEquals(' WHERE 1 = 1', $result, 'nested empty conditions failed %s');
+ $this->assertEquals(' WHERE 1 = 1', $result, 'nested empty conditions failed');
}
/**
@@ -1116,4 +1116,73 @@ 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]);
+ }
+
}
Please sign in to comment.
Something went wrong with that request. Please try again.