Example #1
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());
 }
Example #2
0
 /**
  * test updating records and saving blank values.
  *
  * @return void
  */
 public function testUpdateSavingBlankValues()
 {
     $this->loadFixtures('Boat');
     $Boat = new Boat();
     $Boat->validate = array();
     $Boat->create();
     $result = $Boat->save(array('id' => 1, 'title' => '', 'body' => ''));
     $this->assertTrue((bool) $result);
     $result = $Boat->find('first', array('conditions' => array('Boat.id' => 1)));
     $this->assertEquals('', $result['Boat']['title'], 'Title is not blank');
     $this->assertEquals('', $result['Boat']['body'], 'Body is not blank');
 }
Example #3
0
 /**
  * testCreation method
  *
  * @return void
  */
 public function testCreation()
 {
     $this->loadFixtures('Boat', 'BoatFeaturedsTags', 'User', 'Featured');
     $TestModel = new Test();
     $result = $TestModel->create();
     $expected = array('Test' => array('notes' => 'write some notes here'));
     $this->assertEquals($expected, $result);
     $TestModel = new User();
     $result = $TestModel->schema();
     if (isset($this->db->columns['primary_key']['length'])) {
         $intLength = $this->db->columns['primary_key']['length'];
     } elseif (isset($this->db->columns['integer']['length'])) {
         $intLength = $this->db->columns['integer']['length'];
     } else {
         $intLength = 11;
     }
     foreach (array('collate', 'charset', 'comment', 'unsigned') as $type) {
         foreach ($result as $i => $r) {
             unset($result[$i][$type]);
         }
     }
     $expected = array('id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => $intLength, 'key' => 'primary'), 'user' => array('type' => 'string', 'null' => true, 'default' => '', 'length' => 255), 'password' => array('type' => 'string', 'null' => true, 'default' => '', 'length' => 255), 'created' => array('type' => 'datetime', 'null' => true, 'default' => null, 'length' => null), 'updated' => array('type' => 'datetime', 'null' => true, 'default' => null, 'length' => null));
     $this->assertEquals($expected, $result);
     $TestModel = new Boat();
     $result = $TestModel->create();
     $expected = array('Boat' => array('published' => 'N'));
     $this->assertEquals($expected, $result);
     $FeaturedModel = new Featured();
     $data = array('article_featured_id' => 1, 'category_id' => 1, 'published_date' => array('year' => 2008, 'month' => 06, 'day' => 11), 'end_date' => array('year' => 2008, 'month' => 06, 'day' => 20));
     $expected = array('Featured' => array('article_featured_id' => 1, 'category_id' => 1, 'published_date' => '2008-06-11 00:00:00', 'end_date' => '2008-06-20 00:00:00'));
     $this->assertEquals($expected, $FeaturedModel->create($data));
     $data = array('published_date' => array('year' => 2008, 'month' => 06, 'day' => 11), 'end_date' => array('year' => 2008, 'month' => 06, 'day' => 20), 'article_featured_id' => 1, 'category_id' => 1);
     $expected = array('Featured' => array('published_date' => '2008-06-11 00:00:00', 'end_date' => '2008-06-20 00:00:00', 'article_featured_id' => 1, 'category_id' => 1));
     $this->assertEquals($expected, $FeaturedModel->create($data));
 }