function testSearchByTitle() { //Arrange $title = "The Cat in the Hat"; $test_book = new Book($title); $test_book->save(); $title2 = "Misery"; $test_book2 = new Book($title2); $test_book2->save(); $title3 = "Cat on a Hot Tin Roof"; $test_book3 = new Book($title3); $test_book3->save(); $search_string = "Cat"; //Act $result = Book::searchByTitle($search_string); //Assert $this->assertEquals([$test_book, $test_book3], $result); }
$author_last = $_POST['author_last_name']; $book = new Book($title); $book->save(); $author = new Author($author_first, $author_last); $author->save(); $author->addBook($book); return $app['twig']->render('librarian.html.twig', array('books' => Book::getAll(), 'authors' => Author::getAll())); }); //Book page $app->get("/books/{id}", function ($id) use($app) { $book = Book::find($id); $author = $book->getAuthor(); return $app['twig']->render('book.html.twig', array('book' => $book, 'author' => $author)); }); //Search for title or author $app->post("/search/title", function () use($app) { $title = $_POST['search_title']; $books = Book::searchByTitle($title); return $app['twig']->render('search_results.html.twig', array('books' => $books)); }); $app->post("/search/author", function () use($app) { $author = $_POST['search_author']; $books = Author::searchByAuthorLast($author); return $app['twig']->render('search_results.html.twig', array('books' => $books)); }); //allows user to delete all books $app->post("/clear_library", function () use($app) { Book::deleteAll(); return $app['twig']->render('librarian.html.twig', array('books' => Book::getAll())); }); return $app;
$book->updateAuthorFirst($author_first); return $app['twig']->render('add_book.html.twig', array('books' => Book::getAll())); }); $app->patch("/book/{id}/authorlast", function ($id) use($app) { $author_last = $_POST['author_last']; $book = Book::find($id); $book->updateAuthorLast($author_last); return $app['twig']->render('add_book.html.twig', array('books' => Book::getAll())); }); $app->patch("/book/{id}/title", function ($id) use($app) { $title = $_POST['title']; $book = Book::find($id); $book->updateTitle($title); return $app['twig']->render('add_book.html.twig', array('books' => Book::getAll())); }); $app->delete("/book/{id}", function ($id) use($app) { $book = Book::find($id); $book->deleteOne(); return $app['twig']->render('add_book.html.twig', array('books' => Book::getAll())); }); $app->post("/search/title", function () use($app) { $title = $_POST['search_title']; $matches = Book::searchByTitle($title); return $app['twig']->render('search_results.html.twig', array('matches' => $matches)); }); $app->post("/search/author", function () use($app) { $author = $_POST['search_author']; $matches = Book::searchByAuthorLast($author); return $app['twig']->render('search_results.html.twig', array('matches' => $matches)); }); return $app;
function testSearchByTitle() { //Arrange $author_first = "Dr."; $author_last = "Seuss"; $title = "The Cat in the Hat"; $test_book = new Book($author_first, $author_last, $title); $test_book->save(); $author_first2 = "Stephen"; $author_last2 = "King"; $title2 = "Misery"; $test_book2 = new Book($author_first2, $author_last2, $title2); $test_book2->save(); $author_first3 = "Tennessee"; $author_last3 = "Williams"; $title3 = "Cat on a Hot Tin Roof"; $test_book3 = new Book($author_first3, $author_last3, $title3); $test_book3->save(); $search_string = "Cat"; //Act $result = Book::searchByTitle($search_string); //Assert $this->assertEquals([$test_book, $test_book3], $result); }
function testSearchByTitle() { //Arrange $author_first = "J.K."; $author_last = "Rowling"; $test_author = new Author($author_first, $author_last); $test_author->save(); $author_first2 = "Stephen"; $author_last2 = "King"; $test_author2 = new Author($author_first2, $author_last2); $test_author2->save(); $author_first3 = "John"; $author_last3 = "Steinbeck"; $test_author3 = new Author($author_first2, $author_last2); $test_author3->save(); $title = "Grapes of Wrath"; $test_book = new Book($title); $test_book->save(); $test_book->addAuthor($test_author3); $title2 = "Harry Potter"; $test_book2 = new Book($title2); $test_book2->save(); $test_book2->addAuthor($test_author); $title3 = "Evil Wrath"; $test_book3 = new Book($title3); $test_book3->save(); $test_book3->addAuthor($test_author2); $search_string = "Wrath"; //Act $result = Book::searchByTitle($search_string); //Assert $this->assertEquals([$test_book, $test_book3], $result); }