Ejemplo n.º 1
0
 public function testbelongsToSave()
 {
     /*
     *	Profile BelongsTo User
     */
     $user1 = User::create(['name' => 'newUser']);
     $profile = Profile::create();
     $profile->User = $user1;
     print_r($profile);
     $this->assertEquals(true, $profile->save());
     $this->assertEquals($profile->user_id, $user1->id);
     /*
     *	本当にセーブできたかreadで確認
     */
     $savedUser1 = User::read($profile->User->id);
     $this->assertEquals($profile->User->name, $savedUser1->name);
     $this->assertEquals($profile->User->id, $savedUser1->id);
     /*
     *	Comment BelongsTo User
     */
     $user2 = User::newRecord(['name' => 'newUser2']);
     $comment = Comment::create();
     $comment->User = $user2;
     $this->assertEquals(true, $comment->save());
     //print_r($comment);
     $this->assertEquals($comment->user_id, $user2->id);
     /*
     *	本当にセーブできたかreadで確認
     */
     $savedUser2 = User::read($comment->User->id);
     $this->assertEquals($comment->User->name, $savedUser2->name);
     $this->assertEquals($comment->User->id, $savedUser2->id);
 }