Exemple #1
0
 /**
  * testDeleteAll method
  *
  * @return void
  */
 public function testDeleteAll()
 {
     $this->loadFixtures('Boat');
     $TestModel = new Boat();
     $data = array('Boat' => array('user_id' => 2, 'id' => 4, 'title' => 'Fourth Boat', 'published' => 'N'));
     $result = $TestModel->set($data) && $TestModel->save();
     $this->assertTrue($result);
     $data = array('Boat' => array('user_id' => 2, 'id' => 5, 'title' => 'Fifth Boat', 'published' => 'Y'));
     $result = $TestModel->set($data) && $TestModel->save();
     $this->assertTrue($result);
     $data = array('Boat' => array('user_id' => 1, 'id' => 6, 'title' => 'Sixth Boat', 'published' => 'N'));
     $result = $TestModel->set($data) && $TestModel->save();
     $this->assertTrue($result);
     $TestModel->recursive = -1;
     $result = $TestModel->find('all', array('fields' => array('id', 'user_id', 'title', 'published'), 'order' => array('Boat.id' => 'ASC')));
     $expected = array(array('Boat' => array('id' => 1, 'user_id' => 1, 'title' => 'First Boat', 'published' => 'Y')), array('Boat' => array('id' => 2, 'user_id' => 3, 'title' => 'Second Boat', 'published' => 'Y')), array('Boat' => array('id' => 3, 'user_id' => 1, 'title' => 'Third Boat', 'published' => 'Y')), array('Boat' => array('id' => 4, 'user_id' => 2, 'title' => 'Fourth Boat', 'published' => 'N')), array('Boat' => array('id' => 5, 'user_id' => 2, 'title' => 'Fifth Boat', 'published' => 'Y')), array('Boat' => array('id' => 6, 'user_id' => 1, 'title' => 'Sixth Boat', 'published' => 'N')));
     $this->assertEquals($expected, $result);
     $result = $TestModel->deleteAll(array('Boat.published' => 'N'));
     $this->assertTrue($result);
     $TestModel->recursive = -1;
     $result = $TestModel->find('all', array('fields' => array('id', 'user_id', 'title', 'published'), 'order' => array('Boat.id' => 'ASC')));
     $expected = array(array('Boat' => array('id' => 1, 'user_id' => 1, 'title' => 'First Boat', 'published' => 'Y')), array('Boat' => array('id' => 2, 'user_id' => 3, 'title' => 'Second Boat', 'published' => 'Y')), array('Boat' => array('id' => 3, 'user_id' => 1, 'title' => 'Third Boat', 'published' => 'Y')), array('Boat' => array('id' => 5, 'user_id' => 2, 'title' => 'Fifth Boat', 'published' => 'Y')));
     $this->assertEquals($expected, $result);
     $data = array('Boat.user_id' => array(2, 3));
     $result = $TestModel->deleteAll($data, true, true);
     $this->assertTrue($result);
     $TestModel->recursive = -1;
     $result = $TestModel->find('all', array('fields' => array('id', 'user_id', 'title', 'published'), 'order' => array('Boat.id' => 'ASC')));
     $expected = array(array('Boat' => array('id' => 1, 'user_id' => 1, 'title' => 'First Boat', 'published' => 'Y')), array('Boat' => array('id' => 3, 'user_id' => 1, 'title' => 'Third Boat', 'published' => 'Y')));
     $this->assertEquals($expected, $result);
     $result = $TestModel->deleteAll(array('Boat.user_id' => 999));
     $this->assertTrue($result, 'deleteAll returned false when all no records matched conditions. %s');
 }
Exemple #2
0
 /**
  * test that saveAll still behaves like previous versions (does not necessarily need a first argument)
  *
  * @return void
  */
 public function testSaveAllWithSet()
 {
     $this->loadFixtures('Boat', 'Tag', 'Comment', 'User', 'boatsTag');
     $data = array('Boat' => array('user_id' => 1, 'title' => 'Boat Has and belongs to Many Tags'), 'Tag' => array('Tag' => array(1, 2)), 'Comment' => array(array('comment' => 'Boat comment', 'user_id' => 1)));
     $Boat = new Boat();
     $Boat->set($data);
     $result = $Boat->saveAll();
     $this->assertFalse(empty($result));
 }
 /**
  * Test that 'required' and 'on' are not conflicting
  *
  * @return void
  */
 public function testOnRequiredConflictValidation()
 {
     $this->loadFixtures('Boat');
     $Boat = new Boat();
     // no title field present
     $data = array('Boat' => array('body' => 'Extra Fields Body', 'published' => '1'));
     $Boat->validate = array('title' => array('notBlank' => array('rule' => 'notBlank', 'required' => 'create', 'on' => 'create')));
     $Boat->create($data);
     $this->assertFalse($Boat->validates());
     $Boat->validate = array('title' => array('notBlank' => array('rule' => 'notBlank', 'required' => 'update', 'on' => 'create')));
     $Boat->create($data);
     $this->assertTrue($Boat->validates());
     $Boat->validate = array('title' => array('notBlank' => array('rule' => 'notBlank', 'required' => 'create', 'on' => 'update')));
     $Boat->create($data);
     $this->assertTrue($Boat->validates());
     $Boat->validate = array('title' => array('notBlank' => array('rule' => 'notBlank', 'required' => 'update', 'on' => 'update')));
     $Boat->create($data);
     $this->assertTrue($Boat->validates());
     $Boat->validate = array('title' => array('notBlank' => array('rule' => 'notBlank', 'required' => 'create', 'on' => 'create')));
     $Boat->save(null, array('validate' => false));
     $data['Boat']['id'] = $Boat->id;
     $Boat->set($data);
     $this->assertTrue($Boat->validates());
     $Boat->validate = array('title' => array('notBlank' => array('rule' => 'notBlank', 'required' => 'update', 'on' => 'create')));
     $Boat->set($data);
     $this->assertTrue($Boat->validates());
     $Boat->validate = array('title' => array('notBlank' => array('rule' => 'notBlank', 'required' => 'create', 'on' => 'update')));
     $Boat->set($data);
     $this->assertTrue($Boat->validates());
     $Boat->validate = array('title' => array('notBlank' => array('rule' => 'notBlank', 'required' => 'update', 'on' => 'update')));
     $Boat->set($data);
     $this->assertFalse($Boat->validates());
 }