示例#1
0
 /**
  * testRecursiveDel method
  *
  * @return void
  */
 public function testRecursiveDel()
 {
     $this->loadFixtures('Boat', 'Comment', 'Attachment');
     $TestModel = new Boat();
     $result = $TestModel->delete(2);
     $this->assertTrue($result);
     $TestModel->recursive = 2;
     $result = $TestModel->read(null, 2);
     $this->assertSame(array(), $result);
     $result = $TestModel->Comment->read(null, 5);
     $this->assertSame(array(), $result);
     $result = $TestModel->Comment->read(null, 6);
     $this->assertSame(array(), $result);
     $result = $TestModel->Comment->Attachment->read(null, 1);
     $this->assertSame(array(), $result);
     $result = $TestModel->find('count');
     $this->assertEquals(2, $result);
     $result = $TestModel->Comment->find('count');
     $this->assertEquals(4, $result);
     $result = $TestModel->Comment->Attachment->find('count');
     $this->assertEquals(0, $result);
 }
示例#2
0
 /**
  * testSaveAssociatedValidateFirst method
  *
  * @return void
  */
 public function testSaveAssociatedValidateFirst()
 {
     $this->loadFixtures('Boat', 'Comment', 'Attachment');
     $model = new Boat();
     $model->deleteAll(true);
     $model->Comment->validate = array('comment' => 'notBlank');
     $result = $model->saveAssociated(array('Boat' => array('title' => 'Post with Author', 'body' => 'This post will be saved author'), 'Comment' => array(array('comment' => 'First new comment'), array('comment' => ''))), array('validate' => 'first'));
     $this->assertFalse($result);
     $result = $model->find('all');
     $this->assertSame(array(), $result);
     $expected = array('Comment' => array(1 => array('comment' => array('This field cannot be left blank'))));
     $this->assertEquals($expected['Comment'], $model->Comment->validationErrors);
     $this->assertSame($model->Comment->find('count'), 0);
     $result = $model->saveAssociated(array('Boat' => array('title' => 'Post with Author', 'body' => 'This post will be saved with an author', 'user_id' => 2), 'Comment' => array(array('comment' => 'Only new comment', 'user_id' => 2))), array('validate' => 'first'));
     $this->assertTrue($result);
     $result = $model->Comment->find('all');
     $this->assertSame(count($result), 1);
     $result = Hash::extract($result, '{n}.Comment.article_id');
     $this->assertEquals(4, $result[0]);
     $model->deleteAll(true);
     $data = array('Boat' => array('title' => 'Post with Author saveAlled from comment', 'body' => 'This post will be saved with an author', 'user_id' => 2), 'Comment' => array('comment' => 'Only new comment', 'user_id' => 2));
     $result = $model->Comment->saveAssociated($data, array('validate' => 'first'));
     $this->assertFalse(empty($result));
     $result = $model->find('all');
     $this->assertEquals('Post with Author saveAlled from comment', $result[0]['Boat']['title']);
     $this->assertEquals('Only new comment', $result[0]['Comment'][0]['comment']);
 }
示例#3
0
 /**
  * undocumented function
  *
  * @return void
  */
 public function testBindModelCallsInBehaviors()
 {
     // hasMany
     $Boat = new Boat();
     $Boat->unbindModel(array('hasMany' => array('Comment')));
     $result = $Boat->find('first');
     $this->assertFalse(array_key_exists('Comment', $result));
     $Boat->Behaviors->load('Test4');
     $result = $Boat->find('first');
     $this->assertTrue(array_key_exists('Comment', $result));
     // belongsTo
     $Boat->unbindModel(array('belongsTo' => array('User')));
     $result = $Boat->find('first');
     $this->assertFalse(array_key_exists('User', $result));
     $Boat->Behaviors->load('Test5');
     $result = $Boat->find('first');
     $this->assertTrue(array_key_exists('User', $result));
     // hasAndBelongsToMany
     $Boat->unbindModel(array('hasAndBelongsToMany' => array('Tag')));
     $result = $Boat->find('first');
     $this->assertFalse(array_key_exists('Tag', $result));
     $Boat->Behaviors->load('Test6');
     $result = $Boat->find('first');
     $this->assertTrue(array_key_exists('Comment', $result));
     // hasOne
     $Comment = new Comment();
     $Comment->unbindModel(array('hasOne' => array('Attachment')));
     $result = $Comment->find('first');
     $this->assertFalse(array_key_exists('Attachment', $result));
     $Comment->Behaviors->load('Test7');
     $result = $Comment->find('first');
     $this->assertTrue(array_key_exists('Attachment', $result));
 }
示例#4
0
 /**
  * testValidateFirstWithDefaults method
  *
  * @return void
  */
 public function testFirstWithDefaults()
 {
     $this->loadFixtures('Boat', 'Tag', 'Comment', 'User', 'boatsTag');
     $TestModel = new Boat();
     $result = $TestModel->find('first', array('conditions' => array('Boat.id' => 1)));
     $expected = array('Boat' => array('id' => 1, 'user_id' => 1, 'title' => 'First Boat', 'body' => 'First Boat Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23'));
     unset($result['Boat']['updated']);
     $this->assertEquals($expected['Boat'], $result['Boat']);
     $data = array('Boat' => array('id' => 1, 'title' => 'First Boat (modified)'), 'Comment' => array(array('comment' => 'Boat comment', 'user_id' => 1)));
     $result = $TestModel->saveAll($data, array('validate' => 'first'));
     $this->assertTrue($result);
     $result = $TestModel->find('first', array('conditions' => array('Boat.id' => 1)));
     $expected['Boat']['title'] = 'First Boat (modified)';
     unset($result['Boat']['updated']);
     $this->assertEquals($expected['Boat'], $result['Boat']);
 }
示例#5
0
 /**
  * testDynamicAssociations method
  *
  * @return void
  */
 public function testDynamicAssociations()
 {
     $this->loadFixtures('Boat', 'Comment');
     $TestModel = new Boat();
     $TestModel->belongsTo = $TestModel->hasAndBelongsToMany = $TestModel->hasOne = array();
     $TestModel->hasMany['Comment'] = array_merge($TestModel->hasMany['Comment'], array('foreignKey' => false, 'conditions' => array('Comment.user_id =' => '2')));
     $result = $TestModel->find('all');
     $expected = array(array('Boat' => array('id' => '1', 'user_id' => '1', 'title' => 'First Boat', 'body' => 'First Boat Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'), 'Comment' => array(array('id' => '1', 'article_id' => '1', 'user_id' => '2', 'comment' => 'First Comment for First Boat', 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31'), array('id' => '6', 'article_id' => '2', 'user_id' => '2', 'comment' => 'Second Comment for Second Boat', 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31'))), array('Boat' => array('id' => '2', 'user_id' => '3', 'title' => 'Second Boat', 'body' => 'Second Boat Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'), 'Comment' => array(array('id' => '1', 'article_id' => '1', 'user_id' => '2', 'comment' => 'First Comment for First Boat', 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31'), array('id' => '6', 'article_id' => '2', 'user_id' => '2', 'comment' => 'Second Comment for Second Boat', 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31'))), array('Boat' => array('id' => '3', 'user_id' => '1', 'title' => 'Third Boat', 'body' => 'Third Boat Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'), 'Comment' => array(array('id' => '1', 'article_id' => '1', 'user_id' => '2', 'comment' => 'First Comment for First Boat', 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31'), array('id' => '6', 'article_id' => '2', 'user_id' => '2', 'comment' => 'Second Comment for Second Boat', 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31'))));
     $this->assertEquals($expected, $result);
 }
示例#6
0
 /**
  * test to assert that != in key together with a single element array will work
  *
  * @return void
  */
 public function testNotEqualsInArrayWithOneValue()
 {
     $this->loadFixtures('Boat');
     $Boat = new Boat();
     $Boat->recursive = -1;
     $result = $Boat->find('all', array('conditions' => array('Boat.id !=' => array(1))));
     $this->assertTrue(is_array($result) && !empty($result));
 }
示例#7
0
 /**
  * test that saveAll works even with conditions that lack a model name.
  *
  * @return void
  */
 public function testUpdateAllWithNonQualifiedConditions()
 {
     $this->loadFixtures('Boat');
     $Boat = new Boat();
     $result = $Boat->updateAll(array('title' => "'Awesome'"), array('title' => 'Third Boat'));
     $this->assertTrue($result);
     $result = $Boat->find('count', array('conditions' => array('Boat.title' => 'Awesome')));
     $this->assertEquals(1, $result, 'Boat count is wrong or fixture has changed.');
 }