Example #1
0
 /**
  * Test returned array contains primary key when save creates a new record
  *
  * @return void
  */
 public function testPkInReturnArrayForCreate()
 {
     $this->loadFixtures('Boat');
     $TestModel = new Boat();
     $data = array('Boat' => array('user_id' => '1', 'title' => 'Fourth Boat', 'body' => 'Fourth Boat Body', 'published' => 'Y'));
     $result = $TestModel->save($data);
     $this->assertSame($result['Boat']['id'], $TestModel->id);
 }
Example #2
0
 public function actionAdd_boat()
 {
     $boat = new Boat();
     if (isset($_POST['source'])) {
         $boat->source = $_POST['source'];
     }
     if (isset($_POST['thumb'])) {
         $boat->thumb = $_POST['thumb'];
     }
     $boat->name = $_POST['title'];
     $boat->zaikeshu = $_POST['zaikeshu'];
     $boat->paishuiliang = $_POST['paishuiliang'];
     $boat->zuigaosudu = $_POST['zuigaosudu'];
     $boat->jiabanlouceng = $_POST['jiabanlouceng'];
     $boat->gongzuorenyuan = $_POST['gongzuorenyuan'];
     $boat->changdu = $_POST['changdu'];
     $boat->kuandu = $_POST['kuandu'];
     $boat->gaodu = $_POST['gaodu'];
     $boat->description = $_POST['content'];
     $boat->type = $_POST['type'];
     $boat->save();
     echo 1;
 }
Example #3
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');
 }
Example #4
0
 /**
  * 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());
 }