Example #1
0
 public function testBuildObject()
 {
     $this->fixtures('articles', 'users');
     $article = new Article(array('title' => 'Test Foo'));
     $user = $article->buildUser(array('name' => 'Test Bar', 'company_id' => 1));
     $this->assertEquals($user, $article->user);
     // this hasn't saved the associated object yet
     $notExists = User::find('first', array('conditions' => 'name=:nm'), array(':nm' => 'Test Bar'));
     $this->assertNull($notExists);
     // save, and make sure the association object is created
     $article->save();
     // make sure both were created, and are associated
     $article = Article::find('first', array('conditions' => 'title=:title'), array(':title' => 'Test Foo'));
     $user = User::find('first', array('conditions' => 'name=:nm'), array(':nm' => 'Test Bar'));
     $this->assertTrue($article instanceof Article);
     $this->assertTrue($user instanceof User);
     $this->assertEquals($article->user_id, $user->id);
 }