Example #1
0
 public function testBuildObject()
 {
     $this->fixtures('users', 'avatars');
     $user = new User(array('name' => 'Foo Name', 'company_id' => 1));
     $avatar = $user->buildAvatar(array('filepath' => 'test.gif'));
     $this->assertEquals($avatar, $user->avatar);
     // this hasn't saved the associated object yet
     $notExists = Avatar::find('first', array('conditions' => 'filepath=:nm'), array(':nm' => 'test.gif'));
     $this->assertNull($notExists);
     // save, and make sure the association object is created
     $user->save();
     // make sure both were created, and are associated
     $user = User::find('first', array('conditions' => 'name=:nm'), array(':nm' => 'Foo Name'));
     $avatar = Avatar::find('first', array('conditions' => 'filepath=:nm'), array(':nm' => 'test.gif'));
     $this->assertTrue($user instanceof User);
     $this->assertTrue($avatar instanceof Avatar);
     $this->assertEquals($user->id, $avatar->user_id);
 }