public function testRemoveObjectStoredInDBFromCollection() { BookQuery::create()->deleteAll(); BookClubListQuery::create()->deleteAll(); $list = new BookClubList(); $list->setGroupLeader('Archimedes Q. Porter'); $list2 = new BookClubList(); $list2->setGroupLeader('FooBar group'); // No save ... $book = new Book(); $book->setTitle("Jungle Expedition Handbook"); $book->setISBN('TEST'); $book->addBookClubList($list); $book->addBookClubList($list2); $book->save(); $this->assertEquals(2, BookClubListQuery::create()->count(), 'Two BookClubList'); $this->assertEquals(2, BookListRelQuery::create()->count(), 'Two BookClubList'); $book->removeBookClubList($list); $this->assertEquals(2, BookListRelQuery::create()->count(), 'still Two BookClubList in db before save()'); $this->assertCount(1, $book->getBookClubLists(), 'One BookClubList has been remove'); $book->save(); $this->assertCount(1, $book->getBookClubLists(), 'One BookClubList has been remove'); $this->assertEquals(1, BookListRelQuery::create()->count(), 'One BookClubList has been remove'); }
public function testPruneCompositeKey() { BookstoreDataPopulator::depopulate(); BookstoreDataPopulator::populate(); // save all books to make sure related objects are also saved - BookstoreDataPopulator keeps some unsaved $c = new ModelCriteria('bookstore', 'Book'); $books = $c->find(); foreach ($books as $book) { $book->save(); } BookPeer::clearInstancePool(); $nbBookListRel = BookListRelQuery::create()->prune()->count(); $this->assertEquals(2, $nbBookListRel, 'prune() does nothing when passed a null object'); $testBookListRel = BookListRelQuery::create()->findOne(); $nbBookListRel = BookListRelQuery::create()->prune($testBookListRel)->count(); $this->assertEquals(1, $nbBookListRel, 'prune() removes an object from the result'); }
public function testSetterCollectionReplacesOldObjectsByNewObjects() { // Ensure no data BookQuery::create()->deleteAll(); BookClubListQuery::create()->deleteAll(); BookListRelQuery::create()->deleteAll(); $books = new PropelObjectCollection(); foreach (array('foo', 'bar') as $title) { $b = new Book(); $b->setTitle($title); $books[] = $b; } $bookClubList = new BookClubList(); $bookClubList->setBooks($books); $bookClubList->save(); $books = $bookClubList->getBooks(); $this->assertEquals('foo', $books[0]->getTitle()); $this->assertEquals('bar', $books[1]->getTitle()); $books = new PropelObjectCollection(); foreach (array('bam', 'bom') as $title) { $b = new Book(); $b->setTitle($title); $books[] = $b; } $bookClubList->setBooks($books); $bookClubList->save(); $books = $bookClubList->getBooks(); $this->assertEquals('bam', $books[0]->getTitle()); $this->assertEquals('bom', $books[1]->getTitle()); $this->assertEquals(1, BookClubListQuery::create()->count()); $this->assertEquals(2, BookListRelQuery::create()->count()); $this->assertEquals(4, BookQuery::create()->count()); }