/** * testSaveField method * * @return void */ public function testSaveField() { $this->loadFixtures('Boat'); $TestModel = new Boat(); $TestModel->id = 1; $result = $TestModel->saveField('title', 'New First Boat'); $this->assertFalse(empty($result)); $TestModel->recursive = -1; $result = $TestModel->read(array('id', 'user_id', 'title', 'body'), 1); $expected = array('Boat' => array('id' => '1', 'user_id' => '1', 'title' => 'New First Boat', 'body' => 'First Boat Body')); $this->assertEquals($expected, $result); $TestModel->id = 1; $result = $TestModel->saveField('title', ''); $this->assertFalse(empty($result)); $TestModel->recursive = -1; $result = $TestModel->read(array('id', 'user_id', 'title', 'body'), 1); $expected = array('Boat' => array('id' => '1', 'user_id' => '1', 'title' => '', 'body' => 'First Boat Body')); $result['Boat']['title'] = trim($result['Boat']['title']); $this->assertEquals($expected, $result); $TestModel->id = 1; $TestModel->set('body', 'Messed up data'); $result = $TestModel->saveField('title', 'First Boat'); $this->assertFalse(empty($result)); $result = $TestModel->read(array('id', 'user_id', 'title', 'body'), 1); $expected = array('Boat' => array('id' => '1', 'user_id' => '1', 'title' => 'First Boat', 'body' => 'First Boat Body')); $this->assertEquals($expected, $result); $TestModel->recursive = -1; $TestModel->read(array('id', 'user_id', 'title', 'body'), 1); $TestModel->id = 1; $result = $TestModel->saveField('title', '', true); $this->assertFalse($result); $TestModel->recursive = -1; $TestModel->id = 1; $result = $TestModel->saveField('user_id', 9999); $this->assertTrue((bool) $result); $result = $TestModel->read(array('id', 'user_id'), 1); $expected = array('Boat' => array('id' => '1', 'user_id' => '9999')); $this->assertEquals($expected, $result); $this->loadFixtures('Node', 'Dependency'); $Node = new Node(); $Node->set('id', 1); $result = $Node->read(); $this->assertEquals(array('Second'), Hash::extract($result, 'ParentNode.{n}.name')); $Node->saveField('state', 10); $result = $Node->read(); $this->assertEquals(array('Second'), Hash::extract($result, 'ParentNode.{n}.name')); }
/** * ensure that exists() does not persist between method calls reset on create * * @return void */ public function testResetOfExistsOnCreate() { $this->loadFixtures('Boat'); $Boat = new Boat(); $Boat->id = 1; $Boat->saveField('title', 'Reset me'); $Boat->delete(); $Boat->id = 1; $this->assertFalse($Boat->exists()); $Boat->create(); $this->assertFalse($Boat->exists()); $Boat->id = 2; $Boat->saveField('title', 'Staying alive'); $result = $Boat->read(null, 2); $this->assertEquals('Staying alive', $result['Boat']['title']); }