Example #1
0
 function testAddBook()
 {
     //Arrange
     $name = "Ben";
     $test_author = new Author($name);
     $test_author->save();
     $book_name = "Intro to Art";
     $test_book = new Book($book_name);
     $test_book->save();
     //Act
     $test_author->addBook($test_book);
     //Assert
     $this->assertEquals($test_author->getBooks(), [$test_book]);
 }
Example #2
0
 public function testRemoveObjectOneToMany()
 {
     BookQuery::create()->deleteAll();
     AuthorQuery::create()->deleteAll();
     $book = new Book();
     $book->setTitle('Propel Book');
     $book2 = new Book();
     $book2->setTitle('Propel2 Book');
     $author = new Author();
     $author->setFirstName('François');
     $author->setLastName('Z');
     $author->addBook($book);
     $author->addBook($book2);
     $this->assertCount(2, $author->getBooks());
     $author->removeBook($book);
     $books = $author->getBooks();
     $this->assertCount(1, $books);
     $this->assertEquals('Propel2 Book', reset($books)->getTitle());
     $author->save();
     $book->save();
     $book2->save();
     $this->assertEquals(2, BookQuery::create()->count(), 'Two Book');
     $this->assertEquals(1, AuthorQuery::create()->count(), 'One Author');
     $this->assertEquals(1, BookQuery::create()->filterByAuthor($author)->count());
     $author->addBook($book);
     $author->save();
     $this->assertEquals(2, BookQuery::create()->filterByAuthor($author)->count());
     $author->removeBook($book2);
     $author->save();
     $this->assertEquals(1, BookQuery::create()->filterByAuthor($author)->count());
     $this->assertEquals(2, BookQuery::create()->count(), 'Two Book because FK is not required so book is not delete when removed from author\'s book collection');
 }
 public function testSetUp()
 {
     $this->assertTrue(Propel::isInstancePoolingEnabled());
     $this->assertEquals(2, count($this->author->getBooks()));
     $this->assertEquals(2, $this->author->countBooks());
 }
Example #4
0
 function testGetBooks()
 {
     $title = "Kama Sutra";
     $id = 1;
     $test_book = new Book($title, $id);
     $test_book->save();
     $title2 = "Oh Yeah";
     $id2 = 2;
     $test_book2 = new Book($title2, $id2);
     $test_book2->save();
     $name = "Uncle Ben";
     $id3 = 3;
     $test_author = new Author($name, $id3);
     $test_author->save();
     //Act
     $test_author->addBook($test_book);
     $test_author->addBook($test_book2);
     //Assert
     $this->assertEquals($test_author->getBooks(), [$test_book, $test_book2]);
 }
Example #5
0
 function test_deleteAllBooks()
 {
     //Arrange
     $name = "Benjamin";
     // $id = 1;
     $test_author = new Author($name);
     $test_author->save();
     $title = "Book Title";
     // $id2 = 1;
     $test_book = new Book($title);
     $test_book->save();
     $title = "Book Title2";
     // $id3 = 2;
     $test_book2 = new Book($title);
     $test_book2->save();
     $test_author->addBook($test_book);
     $test_author->addBook($test_book2);
     //Act
     $test_author->deleteAllBooks();
     $result = $test_author->getBooks();
     //Assert
     $this->assertEquals([], $result);
 }
Example #6
0
 public function testSetterOneToManyReplacesOldObjectsByNewObjects()
 {
     // Ensure no data
     BookQuery::create()->deleteAll();
     AuthorQuery::create()->deleteAll();
     $books = new PropelObjectCollection();
     foreach (array('foo', 'bar') as $title) {
         $b = new Book();
         $b->setTitle($title);
         $books[] = $b;
     }
     $a = new Author();
     $a->setBooks($books);
     $a->save();
     $books = $a->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;
     }
     $a->setBooks($books);
     $a->save();
     $books = $a->getBooks();
     $this->assertEquals('bam', $books[0]->getTitle());
     $this->assertEquals('bom', $books[1]->getTitle());
     $this->assertEquals(1, AuthorQuery::create()->count());
     $this->assertEquals(2, BookQuery::create()->count());
 }
Example #7
0
 function testGetBooks()
 {
     //Arrange
     $author_name = "Super Dog";
     $id2 = 2;
     $test_author = new Author($author_name, $id2);
     $test_author->save();
     $book_title = "Snow Crash";
     $id = null;
     $test_book = new Book($book_title, $id);
     $test_book->save();
     $book_title2 = "Ready Player One";
     $id2 = null;
     $test_book2 = new Book($book_title2, $id2);
     $test_book2->save();
     //Act
     $test_author->addBook($test_book);
     $test_author->addBook($test_book2);
     $result = $test_author->getBooks();
     //Assert
     $this->assertEquals($result, [$test_book, $test_book2]);
 }
Example #8
0
 function testGetBooks()
 {
     $name = "Stephen King";
     $test_author = new Author($name);
     $test_author->save();
     $title = "Carrie";
     $test_book = new Book($title);
     $test_book->save();
     $test_author->addBook($test_book);
     $title2 = "Misery";
     $test_book2 = new Book($title2);
     $test_book2->save();
     $test_author->addBook($test_book2);
     $this->assertEquals([$test_book, $test_book2], $test_author->getBooks());
 }
Example #9
0
 function testGetBooks()
 {
     //Arrange
     $name = "JK Rowling";
     $id = 1;
     $test_author = new Author($name, $id);
     $test_author->save();
     $title = "Harry Potter";
     $id = 1;
     $test_book = new Book($title, $id);
     $test_book->save();
     $title2 = "Moby Dick";
     $id2 = 2;
     $test_book2 = new Book($title, $id);
     $test_book2->save();
     //Act
     $test_author->addBook($test_book);
     $test_author->addBook($test_book2);
     $result = $test_author->getBooks();
     //Assert
     $this->assertEquals([$test_book, $test_book2], $result);
 }
Example #10
0
 function test_addBook_getBooks()
 {
     $name = "Jerry Garcia";
     $test_author = new Author($name);
     $test_author->save();
     $name2 = "Frank Sinatra";
     $test_author2 = new Author($name2);
     $test_author2->save();
     $book_title = "Three Blind Mice";
     $test_book = new Book($book_title);
     $test_book->save();
     $test_author->addBook($test_book);
     $result = $test_author->getBooks();
     $this->assertEquals([$test_book], $result);
 }
Example #11
0
 function test_getBooks()
 {
     $name = "Roberto Bolano";
     $test_author = new Author($name);
     $test_author->save();
     $title = "Infinite Jest";
     $test_book = new Book($title);
     $test_book->save();
     $title2 = "Infinite Jest";
     $test_book2 = new Book($title2);
     $test_book2->save();
     //Act
     $test_author->addBook($test_book2);
     $test_author->addBook($test_book);
     $result = $test_author->getBooks();
     //Assert
     $this->assertEquals([$test_book, $test_book2], $result);
 }
Example #12
0
 function test_addBook()
 {
     //Arrange
     $author_name = "Jack London";
     $test_author = new Author($author_name);
     $test_author->save();
     $title = "Sea Wolf";
     $test_book = new Book($title);
     $test_book->save();
     //Act
     $result = [$test_book];
     $test_author->addBook($test_book);
     //Assert
     $this->assertEquals($test_author->getBooks(), $result);
 }
Example #13
0
 function test_getBooks()
 {
     //Arrange
     $name = "Bob";
     $test_author = new Author($name);
     $test_author->save();
     $title = "dog book";
     $test_book = new Book($title);
     $test_book->save();
     $title2 = "History of nothing";
     $test_book2 = new Book($title2);
     $test_book2->save();
     //Act
     $test_author->addBook($test_book);
     $test_author->addBook($test_book2);
     //Assert
     $result = $test_author->getBooks();
     $this->assertEquals([$test_book, $test_book2], $result);
 }
Example #14
0
 function testGetBooks()
 {
     //Arrange
     $name = "Paul Jones";
     $id = 1;
     $test_author = new Author($name, $id);
     $test_author->save();
     $title = "Little Cat";
     $id = 1;
     $test_book = new Book($title, $id);
     $test_book->save();
     $title2 = "Little Dog";
     $id2 = 2;
     $test_book2 = new Book($title2, $id2);
     $test_book2->save();
     //Act
     $test_author->addBook($test_book);
     $test_author->addBook($test_book2);
     $result = $test_author->getBooks();
     //Assert
     $this->assertEquals([$test_book, $test_book2], $result);
 }
Example #15
0
 function test_getBooks()
 {
     //Arrange
     $name = "Pladoh";
     $test_author = new Author($name);
     $test_author->save();
     $title = "Theory of Everything and Nothing at All";
     $genre = "Nonsense";
     $test_book = new Book($title, $genre);
     $test_book->save();
     $title2 = "Philosoraptor: A Memoir";
     $genre2 = "Alternate History/Dinosaurs";
     $test_book2 = new Book($title, $genre);
     $test_book2->save();
     //Act
     $test_author->addBook($test_book);
     $test_author->addBook($test_book2);
     //Assert
     $this->assertEquals($test_author->getBooks(), [$test_book, $test_book2]);
 }
Example #16
0
 public function testDeletedBookDisappears()
 {
     $this->markTestSkipped();
     $a = new Author();
     $a->setFirstName("Douglas");
     $a->setLastName("Adams");
     $b1 = new Book();
     $b1->setTitle("The Hitchhikers Guide To The Galaxy");
     $a->addBook($b1);
     $b2 = new Book();
     $b2->setTitle("The Restaurant At The End Of The Universe");
     $a->addBook($b2);
     /* As you cannot write $a->remove($b2), you have to delete $b2
     		directly. */
     /* All objects unsaved. As of revision 851, this circumvents the
     		$colBooks cache. Anyway, fails because getBooks() never checks if
     		a colBooks entry has been deleted. */
     $this->assertEquals(2, count($a->getBooks()));
     $b2->delete();
     $this->assertEquals(1, count($a->getBooks()));
     /* Even if we had saved everything before and the delete() had
     		actually updated the DB, the $b2 would still be a "zombie" in
     		$a's $colBooks field. */
 }
Example #17
0
 function testGetBooks()
 {
     //Arrange
     $title = "Where the Red Fern Grows";
     $year_published = 1961;
     $id = null;
     $test_book = new Book($title, $year_published, $id);
     $test_book->save();
     $title2 = "Where the Wild Things Are";
     $year_published2 = 1964;
     $test_book2 = new Book($title2, $year_published2, $id);
     $test_book2->save();
     $name = "Nathan Young";
     $test_author = new Author($name, $id);
     $test_author->save();
     //Act
     $test_author->addBook($test_book);
     $test_author->addBook($test_book2);
     //Assert
     $this->assertEquals([$test_book, $test_book2], $test_author->getBooks());
 }
 /**
  * This tests to see whether modified objects are being silently overwritten by calls to fk accessor methods.
  * @link       http://propel.phpdb.org/trac/ticket/509#comment:5
  */
 public function testModifiedObjectOverwrite()
 {
     BookstoreDataPopulator::populate();
     $author = new Author();
     $author->setFirstName("John");
     $author->setLastName("Public");
     $books = $author->getBooks();
     // empty, of course
     $this->assertEquals(0, count($books), "Expected empty collection.");
     $book = new Book();
     $book->setTitle("A sample book");
     $book->setISBN("INITIAL ISBN");
     $author->addBook($book);
     $author->save();
     $book->setISBN("MODIFIED ISBN");
     $books = $author->getBooks();
     $this->assertEquals(1, count($books), "Expected 1 book.");
     $this->assertSame($book, $books[0], "Expected the same object to be returned by fk accessor.");
     $this->assertEquals("MODIFIED ISBN", $books[0]->getISBN(), "Expected the modified value NOT to have been overwritten.");
 }
 function test_getBooks()
 {
     //Arrange
     $test_author = new Author("J.K. Rowling");
     $test_author->save();
     $test_author2 = new Author("Harry Potter");
     $test_author2->save();
     $test_book = new Book("Harry Potter and the Dish Stone", "Non-fiction");
     $test_book->save();
     $test_book2 = new Book("Kelli Potter and the Three Bananas", "Fanasty");
     $test_book2->save();
     //Act
     $test_author->addBook($test_book);
     $test_author->addBook($test_book2);
     $test_author2->addBook($test_book);
     //Assert
     $this->assertEquals($test_author->getBooks(), [$test_book, $test_book2]);
 }
 function testGetBooks()
 {
     //Arrange
     $id = null;
     $name = "Lemony Snicket";
     $test_author = new Author($id, $name);
     $test_author->save();
     $name2 = "Fresh Off The Boat";
     $test_book = new Book($id, $name2);
     $test_book->save();
     $test_author->addBook($test_book);
     $name3 = "A Series of Unfortunate Events";
     $test_book2 = new Book($id, $name3);
     $test_book2->save();
     $test_author->addBook($test_book2);
     //Act
     $result = $test_author->getBooks();
     //Assert
     $this->assertEquals([$test_book, $test_book2], $result);
 }
Example #21
0
 function test_getBooks()
 {
     $title = "War and Peace";
     $id = null;
     $test_book = new Book($title, $id);
     $test_book->save();
     $author_name2 = "Plato";
     $test_author2 = new Author($author_name2, $id);
     $test_author2->save();
     //Act
     $test_author2->addBook($test_book);
     $result = $test_author2->getBooks();
     //Assert
     $this->assertEquals([$test_book], $result);
 }
 public function testSetterOneToManyReplacesOldObjectsByNewObjects()
 {
     // Ensure no data
     BookQuery::create()->deleteAll();
     AuthorQuery::create()->deleteAll();
     $books = new PropelObjectCollection();
     foreach (array('foo', 'bar') as $title) {
         $b = new Book();
         $b->setTitle($title);
         $b->setIsbn('12354');
         $books[] = $b;
     }
     $a = new Author();
     $a->setFirstName('Foo');
     $a->setLastName('Bar');
     $a->setBooks($books);
     $a->save();
     $books = $a->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);
         $b->setIsbn('1235');
         $books[] = $b;
     }
     $a->setBooks($books);
     $a->save();
     $books = $a->getBooks();
     $this->assertEquals('bam', $books[0]->getTitle());
     $this->assertEquals('bom', $books[1]->getTitle());
     $this->assertEquals(1, AuthorQuery::create()->count());
     // the replaced book are still there because the PK is not required
     $this->assertEquals(4, BookQuery::create()->count());
 }
Example #23
0
 function testGetBooks()
 {
     //make an author
     $author_name = "Murakami";
     $test_author = new Author($author_name);
     $test_author->save();
     //wrote books!
     $title = "yur not a wizard harry";
     $test_book = new Book($title);
     $test_book->save();
     $title = "rum diaries";
     $test_book2 = new Book($title);
     $test_book2->save();
     //give murakami books that he wrote!
     $test_author->addBook($test_book);
     $test_author->addBook($test_book2);
     //TEST!!!!
     $result = $test_author->getBooks();
     $this->assertEquals([$test_book, $test_book2], $result);
 }