diff --git a/cake/libs/model/model.php b/cake/libs/model/model.php index a3708856c03..11769db6b0a 100644 --- a/cake/libs/model/model.php +++ b/cake/libs/model/model.php @@ -1722,6 +1722,7 @@ function saveAll($data = null, $options = array()) { break; } } + return $return; } /** diff --git a/cake/tests/cases/libs/model/model.test.php b/cake/tests/cases/libs/model/model.test.php index f9f04e596b1..aa378a404d2 100644 --- a/cake/tests/cases/libs/model/model.test.php +++ b/cake/tests/cases/libs/model/model.test.php @@ -69,35 +69,25 @@ abstract class BaseModelTest extends CakeTestCase { ); /** - * start method + * setUp method * * @access public * @return void */ - function start() { - parent::start(); + function setUp() { + parent::setUp(); $this->debug = Configure::read('debug'); - Configure::write('debug', 2); } /** - * end method + * tearDown method * * @access public * @return void */ - function end() { - parent::end(); + function tearDown() { + parent::tearDown(); Configure::write('debug', $this->debug); - } - -/** - * endTest method - * - * @access public - * @return void - */ - function endTest() { ClassRegistry::flush(); } } diff --git a/cake/tests/cases/libs/model/model_validation.test.php b/cake/tests/cases/libs/model/model_validation.test.php index 6da40853d16..d0201f27007 100644 --- a/cake/tests/cases/libs/model/model_validation.test.php +++ b/cake/tests/cases/libs/model/model_validation.test.php @@ -190,7 +190,7 @@ function testValidates() { 'body' => 'body' )); $result = $TestModel->create($data); - $this->assertTrue($result); + $this->assertEquals($result, $data); $result = $TestModel->validates(); $this->assertFalse($result); @@ -208,7 +208,7 @@ function testValidates() { 'body' => 'body' )); $result = $TestModel->create($data); - $this->assertTrue($result); + $this->assertEquals($result, $data); $result = $TestModel->validates(); $this->assertTrue($result); @@ -218,7 +218,7 @@ function testValidates() { 'body' => 'body' )); $result = $TestModel->create($data); - $this->assertTrue($result); + $this->assertEquals($result, $data); $result = $TestModel->validates(); $this->assertTrue($result); @@ -231,7 +231,7 @@ function testValidates() { 'modified' => '' )); $result = $TestModel->create($data); - $this->assertTrue($result); + $this->assertEquals($result, $data); $result = $TestModel->validates(); $this->assertTrue($result); @@ -242,7 +242,7 @@ function testValidates() { 'modified' => '2007-05-01' )); $result = $TestModel->create($data); - $this->assertTrue($result); + $this->assertEquals($result, $data); $result = $TestModel->validates(); $this->assertTrue($result); @@ -253,7 +253,7 @@ function testValidates() { 'modified' => 'invalid-date-here' )); $result = $TestModel->create($data); - $this->assertTrue($result); + $this->assertEquals($result, $data); $result = $TestModel->validates(); $this->assertFalse($result); @@ -264,7 +264,7 @@ function testValidates() { 'modified' => 0 )); $result = $TestModel->create($data); - $this->assertTrue($result); + $this->assertEquals($result, $data); $result = $TestModel->validates(); $this->assertFalse($result); @@ -275,7 +275,7 @@ function testValidates() { 'modified' => '0' )); $result = $TestModel->create($data); - $this->assertTrue($result); + $this->assertEquals($result, $data); $result = $TestModel->validates(); $this->assertFalse($result); @@ -283,19 +283,19 @@ function testValidates() { $data = array('TestValidate' => array('modified' => null)); $result = $TestModel->create($data); - $this->assertTrue($result); + $this->assertEquals($result, $data); $result = $TestModel->validates(); $this->assertFalse($result); $data = array('TestValidate' => array('modified' => false)); $result = $TestModel->create($data); - $this->assertTrue($result); + $this->assertEquals($result, $data); $result = $TestModel->validates(); $this->assertFalse($result); $data = array('TestValidate' => array('modified' => '')); $result = $TestModel->create($data); - $this->assertTrue($result); + $this->assertEquals($result, $data); $result = $TestModel->validates(); $this->assertFalse($result); @@ -303,7 +303,7 @@ function testValidates() { 'modified' => '2007-05-01' )); $result = $TestModel->create($data); - $this->assertTrue($result); + $this->assertEquals($result, $data); $result = $TestModel->validates(); $this->assertTrue($result); @@ -316,7 +316,7 @@ function testValidates() { 'slug' => '' )); $result = $TestModel->create($data); - $this->assertTrue($result); + $this->assertEquals($result, $data); $result = $TestModel->validates(); $this->assertFalse($result); @@ -327,7 +327,7 @@ function testValidates() { 'slug' => 'slug-right-here' )); $result = $TestModel->create($data); - $this->assertTrue($result); + $this->assertEquals($result, $data); $result = $TestModel->validates(); $this->assertTrue($result); @@ -338,7 +338,7 @@ function testValidates() { 'slug' => 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz' )); $result = $TestModel->create($data); - $this->assertTrue($result); + $this->assertEquals($result, $data); $result = $TestModel->validates(); $this->assertFalse($result); @@ -358,7 +358,7 @@ function testValidates() { 'number' => '0' )); $result = $TestModel->create($data); - $this->assertTrue($result); + $this->assertEquals($result, $data); $result = $TestModel->validates(); $this->assertFalse($result); @@ -367,7 +367,7 @@ function testValidates() { 'number' => 0 )); $result = $TestModel->create($data); - $this->assertTrue($result); + $this->assertEquals($result, $data); $result = $TestModel->validates(); $this->assertFalse($result); @@ -376,7 +376,7 @@ function testValidates() { 'number' => '3' )); $result = $TestModel->create($data); - $this->assertTrue($result); + $this->assertEquals($result, $data); $result = $TestModel->validates(); $this->assertTrue($result); @@ -385,7 +385,7 @@ function testValidates() { 'number' => 3 )); $result = $TestModel->create($data); - $this->assertTrue($result); + $this->assertEquals($result, $data); $result = $TestModel->validates(); $this->assertTrue($result); @@ -405,7 +405,7 @@ function testValidates() { 'number' => '3' )); $result = $TestModel->create($data); - $this->assertTrue($result); + $this->assertEquals($result, $data); $result = $TestModel->validates(); $this->assertFalse($result); @@ -414,7 +414,7 @@ function testValidates() { 'number' => 3 )); $result = $TestModel->create($data); - $this->assertTrue($result); + $this->assertEquals($result, $data); $result = $TestModel->validates(); $this->assertFalse($result); @@ -426,19 +426,19 @@ function testValidates() { $data = array('TestValidate' => array('title' => '')); $result = $TestModel->create($data); - $this->assertTrue($result); + $this->assertEquals($result, $data); $result = $TestModel->validates(); $this->assertFalse($result); $data = array('TestValidate' => array('title' => 'new title')); $result = $TestModel->create($data); - $this->assertTrue($result); + $this->assertEquals($result, $data); $result = $TestModel->validates(); $this->assertFalse($result); $data = array('TestValidate' => array('title' => 'title-new')); $result = $TestModel->create($data); - $this->assertTrue($result); + $this->assertEquals($result, $data); $result = $TestModel->validates(); $this->assertTrue($result); @@ -448,7 +448,7 @@ function testValidates() { )); $data = array('TestValidate' => array('title' => '')); $result = $TestModel->create($data); - $this->assertTrue($result); + $this->assertEquals($result, $data); $result = $TestModel->validates(); $this->assertTrue($result); @@ -460,7 +460,7 @@ function testValidates() { ))); $data = array('TestValidate' => array('title' => '')); $result = $TestModel->create($data); - $this->assertTrue($result); + $this->assertEquals($result, $data); $result = $TestModel->validates(); $this->assertTrue($result); @@ -470,7 +470,7 @@ function testValidates() { )); $data = array('TestValidate' => array('title' => 'My Article Title')); $result = $TestModel->create($data); - $this->assertTrue($result); + $this->assertEquals($result, $data); $result = $TestModel->validates(); $this->assertFalse($result); @@ -478,7 +478,7 @@ function testValidates() { 'title' => 'My Article With a Different Title' )); $result = $TestModel->create($data); - $this->assertTrue($result); + $this->assertEquals($result, $data); $result = $TestModel->validates(); $this->assertTrue($result); @@ -529,6 +529,7 @@ function testValidates() { * @return void */ function testValidatesWithAssociations() { + $this->loadFixtures('Something', 'SomethingElse', 'JoinThing'); $data = array( 'Something' => array( 'id' => 5, @@ -607,7 +608,7 @@ function testValidatesWithModelsAndSaveAll() { $Something->create(); $result = $Something->saveAll($data, array('validate' => 'first')); - $this->assertFalse($result); + $this->assertEquals($result, array()); $this->assertEqual($JoinThing->validationErrors, $expectedError); $count = $Something->find('count', array('conditions' => array('Something.id' => $data['Something']['id']))); @@ -626,7 +627,6 @@ function testValidatesWithModelsAndSaveAll() { * @return void */ function testMissingValidationErrorTriggering() { - $restore = Configure::read('debug'); Configure::write('debug', 2); $TestModel =& new ValidationTest1(); @@ -637,13 +637,27 @@ function testMissingValidationErrorTriggering() { 'required' => true ) ); - $this->expectError(new PatternExpectation('/thisOneBringsThePain for title/i')); + $this->expectError(); $TestModel->invalidFields(array('fieldList' => array('title'))); + } +/** + * Test that missing validation methods does not trigger errors in production mode. + * + * @return void + */ + function testMissingValidationErrorNoTriggering() { Configure::write('debug', 0); - $this->assertNoErrors(); + $TestModel =& new ValidationTest1(); + $TestModel->create(array('title' => 'foo')); + $TestModel->validate = array( + 'title' => array( + 'rule' => array('thisOneBringsThePain'), + 'required' => true + ) + ); $TestModel->invalidFields(array('fieldList' => array('title'))); - Configure::write('debug', $restore); + $this->assertEquals($TestModel->validationErrors, array()); } } diff --git a/cake/tests/cases/libs/model/models.php b/cake/tests/cases/libs/model/models.php index 6b24f9c491a..b23b4daf1d2 100644 --- a/cake/tests/cases/libs/model/models.php +++ b/cake/tests/cases/libs/model/models.php @@ -174,7 +174,7 @@ function validateNumber($value, $options) { * @return void */ function validateTitle($value) { - return (!empty($value) && strpos(low($value['title']), 'title-') === 0); + return (!empty($value) && strpos(strtolower($value['title']), 'title-') === 0); } }