From 90a77f6ce5b6b6b39c9d643a79f43ec99143c383 Mon Sep 17 00:00:00 2001 From: James Tancock Date: Sun, 16 Aug 2015 19:06:12 +0100 Subject: [PATCH 1/5] Alter model exists to consider useTable --- lib/Cake/Model/Model.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/Cake/Model/Model.php b/lib/Cake/Model/Model.php index bfce2dd41..124bb394a 100644 --- a/lib/Cake/Model/Model.php +++ b/lib/Cake/Model/Model.php @@ -2895,6 +2895,10 @@ class Model extends Object implements CakeEventListener { return false; } + if ($this->useTable === false) { + return true; + } + return (bool)$this->find('count', array( 'conditions' => array( $this->alias . '.' . $this->primaryKey => $id From fd198ce0fa13b0dc72168f1ad33fcecdf341bd90 Mon Sep 17 00:00:00 2001 From: James Tancock Date: Mon, 17 Aug 2015 12:19:02 +0100 Subject: [PATCH 2/5] Edits to tests to cover the changes to Model::exists --- .../Test/Case/Model/ModelValidationTest.php | 38 +++++++++++++++++++ lib/Cake/Test/Case/Model/ModelWriteTest.php | 11 +----- 2 files changed, 39 insertions(+), 10 deletions(-) diff --git a/lib/Cake/Test/Case/Model/ModelValidationTest.php b/lib/Cake/Test/Case/Model/ModelValidationTest.php index ba81c7199..0edd3fe5f 100644 --- a/lib/Cake/Test/Case/Model/ModelValidationTest.php +++ b/lib/Cake/Test/Case/Model/ModelValidationTest.php @@ -554,6 +554,44 @@ class ModelValidationTest extends BaseModelTest { $this->assertEquals($expected, $result); } +/** + * test that validates() still performs correctly when useTable = false on the mode. + * + * @return void + */ + public function testValidatesWithNoTable() { + $TestModel = new TheVoid(); + $TestModel->validate = array( + 'title' => array( + 'notEmpty' => array( + 'rule' => array('notBlank'), + 'required' => true, + ), + 'tooShort' => array( + 'rule' => array('minLength', 10), + ), + ), + ); + $data = array( + 'TheVoid' => array( + 'title' => 'too short', + ), + ); + $TestModel->create($data); + $result = $TestModel->validates(); + $this->assertFalse($result); + + $data = array( + 'TheVoid' => array( + 'id' => '1', + 'title' => 'A good title', + ), + ); + $TestModel->create($data); + $result = $TestModel->validates(); + $this->assertTrue($result); + } + /** * test that validates() checks all the 'with' associations as well for validation * as this can cause partial/wrong data insertion. diff --git a/lib/Cake/Test/Case/Model/ModelWriteTest.php b/lib/Cake/Test/Case/Model/ModelWriteTest.php index 9ad34df01..63b22ab6c 100644 --- a/lib/Cake/Test/Case/Model/ModelWriteTest.php +++ b/lib/Cake/Test/Case/Model/ModelWriteTest.php @@ -2785,18 +2785,9 @@ class ModelWriteTest extends BaseModelTest { $TestModel = new TheVoid(); $this->assertFalse($TestModel->exists()); - } -/** - * testRecordExistsMissingTable method - * - * @expectedException PDOException - * @return void - */ - public function testRecordExistsMissingTable() { - $TestModel = new TheVoid(); $TestModel->id = 5; - $TestModel->exists(); + $this->assertTrue($TestModel->exists()); } /** From 2f7cc052d25af0b84734a76970b1f3c5c51835d4 Mon Sep 17 00:00:00 2001 From: James Tancock Date: Mon, 17 Aug 2015 13:15:35 +0100 Subject: [PATCH 3/5] Typo in tests docblock --- lib/Cake/Test/Case/Model/ModelValidationTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/Model/ModelValidationTest.php b/lib/Cake/Test/Case/Model/ModelValidationTest.php index 0edd3fe5f..bd65b16e9 100644 --- a/lib/Cake/Test/Case/Model/ModelValidationTest.php +++ b/lib/Cake/Test/Case/Model/ModelValidationTest.php @@ -555,7 +555,7 @@ class ModelValidationTest extends BaseModelTest { } /** - * test that validates() still performs correctly when useTable = false on the mode. + * test that validates() still performs correctly when useTable = false on the model. * * @return void */ From fdb41e01bbe9f8dbb96d4d506f7faba5d0b77c23 Mon Sep 17 00:00:00 2001 From: James Tancock Date: Tue, 18 Aug 2015 13:07:30 +0100 Subject: [PATCH 4/5] Alter Model::exists() to return false with no table --- lib/Cake/Model/Model.php | 2 +- lib/Cake/Test/Case/Model/ModelWriteTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Model/Model.php b/lib/Cake/Model/Model.php index 124bb394a..9ded1b59e 100644 --- a/lib/Cake/Model/Model.php +++ b/lib/Cake/Model/Model.php @@ -2896,7 +2896,7 @@ class Model extends Object implements CakeEventListener { } if ($this->useTable === false) { - return true; + return false; } return (bool)$this->find('count', array( diff --git a/lib/Cake/Test/Case/Model/ModelWriteTest.php b/lib/Cake/Test/Case/Model/ModelWriteTest.php index 63b22ab6c..7974fa7cc 100644 --- a/lib/Cake/Test/Case/Model/ModelWriteTest.php +++ b/lib/Cake/Test/Case/Model/ModelWriteTest.php @@ -2787,7 +2787,7 @@ class ModelWriteTest extends BaseModelTest { $this->assertFalse($TestModel->exists()); $TestModel->id = 5; - $this->assertTrue($TestModel->exists()); + $this->assertFalse($TestModel->exists()); } /** From 5b92c900e6318e067e7f47df0ade8f92790642f2 Mon Sep 17 00:00:00 2001 From: James Tancock Date: Tue, 18 Aug 2015 13:32:16 +0100 Subject: [PATCH 5/5] Missing test fix ModelIntegration --- lib/Cake/Test/Case/Model/ModelIntegrationTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/Model/ModelIntegrationTest.php b/lib/Cake/Test/Case/Model/ModelIntegrationTest.php index 1aacd7662..65ab2ad3a 100644 --- a/lib/Cake/Test/Case/Model/ModelIntegrationTest.php +++ b/lib/Cake/Test/Case/Model/ModelIntegrationTest.php @@ -1334,7 +1334,7 @@ class ModelIntegrationTest extends BaseModelTest { $Article->useTable = false; $Article->id = 1; $result = $Article->exists(); - $this->assertTrue($result); + $this->assertFalse($result); } /**