Example #1
0
 public function testCreateObject()
 {
     $this->fixtures('articles', 'users');
     $article = new Article(array('title' => 'Test Foo'));
     $newUser = $article->createUser(array('name' => 'Test Bar', 'company_id' => 1));
     $this->assertEquals($newUser->id, $article->user->id);
     // this HAS saved the associated object
     $user = User::find('first', array('conditions' => 'name=:nm'), array(':nm' => 'Test Bar'));
     $this->assertTrue($user instanceof User);
     $this->assertEquals($article->user_id, $user->id);
     // 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);
 }