|
|
@@ -1412,4 +1412,45 @@ class DboSourceTest extends CakeTestCase {
|
|
|
$result = $db->insertMulti('articles', array_keys($data[0]), $data);
|
|
|
$this->assertTrue($result, 'Data was saved');
|
|
|
}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Test defaultConditions()
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public function testDefaultConditions() {
|
|
|
+ $this->loadFixtures('Article');
|
|
|
+ $Article = ClassRegistry::init('Article');
|
|
|
+ $db = $Article->getDataSource();
|
|
|
+
|
|
|
+ // Creates a default set of conditions from the model if $conditions is null/empty.
|
|
|
+ $Article->id = 1;
|
|
|
+ $result = $db->defaultConditions($Article, null);
|
|
|
+ $this->assertEquals(array('Article.id' => 1), $result);
|
|
|
+
|
|
|
+ // $useAlias == false
|
|
|
+ $Article->id = 1;
|
|
|
+ $result = $db->defaultConditions($Article, null, false);
|
|
|
+ $this->assertEquals(array($db->fullTableName($Article, false) . '.id' => 1), $result);
|
|
|
+
|
|
|
+ // If conditions are supplied then they will be returned.
|
|
|
+ $Article->id = 1;
|
|
|
+ $result = $db->defaultConditions($Article, array('Article.title' => 'First article'));
|
|
|
+ $this->assertEquals(array('Article.title' => 'First article'), $result);
|
|
|
+
|
|
|
+ // If a model doesn't exist and no conditions were provided either null or false will be returned based on what was input.
|
|
|
+ $Article->id = 1000000;
|
|
|
+ $result = $db->defaultConditions($Article, null);
|
|
|
+ $this->assertNull($result);
|
|
|
+
|
|
|
+ $Article->id = 1000000;
|
|
|
+ $result = $db->defaultConditions($Article, false);
|
|
|
+ $this->assertFalse($result);
|
|
|
+
|
|
|
+ // Safe update mode
|
|
|
+ $Article->id = 1000000;
|
|
|
+ $Article->__safeUpdateMode = true;
|
|
|
+ $result = $db->defaultConditions($Article, null);
|
|
|
+ $this->assertFalse($result);
|
|
|
+ }
|
|
|
}
|