/**
  * Test update some fields
  */
 public function testUpdate()
 {
     $fieldsValues = array('id' => 10001, 'title' => 'lala', 'message' => 'mes', 'writer_id' => 10001);
     $Post = new ARTPost(array('id' => 10001, 'title' => 'lala', 'message' => '', 'writer_id' => 10001));
     $Post->Comments[] = new ARTComment(array('message' => 'updc1'));
     $Post->Comments[] = new ARTComment(array('message' => 'updc2', 'post_id' => 1));
     $Post->save();
     ActiveRecordManager::clearPool();
     $Post = new ARTPost(array('id' => 10001, 'message' => 'mes'));
     $Post->Comments[] = new ARTComment(array('message' => 'updc3'));
     $Post->save();
     foreach ($fieldsValues as $field => $value) {
         $this->assertEqual($Post->{$field}, $value);
     }
     $this->assertCount(3, $Post->Comments);
     ActiveRecordManager::clearPool();
     $post = $this->TPost->find('first', array('recursive' => -1, 'conditions' => array('id' => 10001), 'contain' => array('Comments')));
     foreach ($fieldsValues as $field => $value) {
         $this->assertEqual($post['TPost'][$field], $value);
     }
 }
 /**
  * Test save when first record is associated with second record 
  * and second associated with first
  */
 public function testCrossAssociation()
 {
     $ARTPost = new ARTPost(array('title' => 'lala', 'message' => '', 'writer_id' => 1));
     $ARTComment = new ARTComment(array('message' => 'coment1 lala1'));
     $ARTComment->Post = $ARTPost;
     $ARTPost->Comments[] = $ARTComment;
     $ARTPost->save();
     $this->assertCount(1, $ARTPost->Comments);
     $ARTPost->id = 666;
     $ARTPost->save();
     $this->assertCount(1, $ARTPost->Comments);
 }
 /**
  * Comment belongs to a Post
  * Post & Comment are both new records
  */
 public function testSetWithNew2BelongsTo()
 {
     $writer = $this->TWriter->find('first', array('recursive' => -1, 'conditions' => array('id' => 1), 'activeRecord' => true));
     $newPost = new ARTPost(array('Writer' => $writer, 'title' => 'TestTitle', 'message' => 'TestMessage'));
     $newComment = new ARTComment(array('message' => 'TestMessage', 'Post' => $newPost));
     $this->assertEquals($newPost->save(), true);
     $this->assertEquals($newComment->save(), true);
     $this->assertEquals($newPost->Comments[0]->message, 'TestMessage');
     $this->assertEquals($newComment->Post->title, 'TestTitle');
     ActiveRecordManager::clearPool();
     $comment = $this->TComment->find('first', array('recursive' => -1, 'conditions' => array('message' => 'TestMessage'), 'activeRecord' => true));
     $this->assertEquals($comment->Post->title, 'TestTitle');
     ActiveRecordManager::clearPool();
     $post = $this->TPost->find('first', array('recursive' => -1, 'conditions' => array('title' => 'TestTitle'), 'activeRecord' => true));
     $this->assertEquals($post->Comments[0]->message, 'TestMessage');
 }