Exemplo n.º 1
0
 public function testManyToManyAdd()
 {
     $list = new BookClubList();
     $list->setGroupLeader('Archimedes Q. Porter');
     $book = new Book();
     $book->setTitle("Jungle Expedition Handbook");
     $book->setISBN('TEST');
     $list->addBook($book);
     $this->assertEquals(1, $list->countBooks(), 'addCrossFk() sets the internal collection properly');
     $this->assertEquals(1, $list->countBookListRels(), 'addCrossFk() sets the internal cross reference collection properly');
     $list->save();
     $this->assertFalse($book->isNew(), 'related object is saved if added');
     $rels = $list->getBookListRels();
     $rel = $rels[0];
     $this->assertFalse($rel->isNew(), 'cross object is saved if added');
     $list->clearBookListRels();
     $list->clearBooks();
     $books = $list->getBooks();
     $expected = new ObjectCollection(array($book));
     $expected->setModel('Book');
     $this->assertEquals($expected, $books, 'addCrossFk() adds the object properly');
     $this->assertEquals(1, $list->countBookListRels());
 }