function testDelete() { $book_id = 1; $test_copy = new Copy($book_id); $test_copy->save(); $book_id2 = 2; $test_copy2 = new Copy($book_id2); $test_copy2->save(); $test_copy->delete(); $this->assertEquals([$test_copy2], Copy::getAll()); }
function testGetAll() { $book_title = "Three Blind Mice"; $id = null; $test_book = new Book($book_title, $id); $test_book->save(); $test_copy = new Copy($amount = 1, $test_book->getId()); $test_copy->save(); $result = Copy::getAll(); $this->assertEquals([$test_copy], $result); }
static function findCopies($search_book_id) { $found_copies = array(); $copies = Copy::getAll(); foreach ($copies as $copy) { $book_id = $copy->getBookId(); if ($book_id == $search_book_id) { array_push($found_copies, $copy); } } return $found_copies; }
function test_delete() { //Arrange $book_id = 2; $test_copy = new Copy($book_id); $test_copy->save(); //Act $test_copy->delete(); $result = Copy::getAll(); //Assert $this->assertEquals([], $result); }
static function find($search_id) { $found = null; $copies = Copy::getAll(); foreach ($copies as $copy) { $copy_id = $copy->getId(); if ($copy_id == $search_id) { $found = $copy; } } return $found; }
static function findBook($search_book_id) { $found_copy = null; $copies = Copy::getAll(); foreach ($copies as $copy) { $book_id = $copy->getBookId(); if ($book_id == $search_book_id) { $found_copy = $copy; } } return $found_copy; }
function testDeleteAll() { $title = "Three Blind Mice"; $test_book = new Book($title); $test_book->save(); $amount = 3; $book_id = $test_book->getId(); $test_copy = new Copy($amount, $book_id); $test_copy->save(); Copy::deleteAll(); $result = Copy::getAll(); $this->assertEquals([], $result); }
function test_getAll() { //Arrange $copy_id = 1; $id = 11; $copy_id2 = 2; $id2 = 22; $test_copy = new Copy($copy_id, $id); $test_copy->save(); $test_copy2 = new Copy($copy_id2, $id2); $test_copy2->save(); //Act $result = Copy::getAll(); //Assert $this->assertEquals([$test_copy, $test_copy2], $result); }
function testDeleteAll() { //Arrange $due_date = '2015-10-10'; $book_id = 1; $id = 1; $test_copy = new Copy($due_date, $book_id, $id); $test_copy->save(); $due_date2 = '2015-11-11'; $book_id2 = 2; $id2 = 2; $test_copy2 = new Copy($due_date2, $book_id2, $id2); $test_copy2->save(); //Act Copy::deleteAll(); $result = Copy::getAll(); //Assert $this->assertEquals([], $result); }
function test_getCopies() { //Arrange $book_name = "The Martian"; $test_book = new Book($book_name); $test_book->save(); //Act $test_book->addCopies(4); $test_copies = $test_book->getCopies(); $result = Copy::getAll(); //Assert $this->assertEquals($test_copies, $result); }
function testDeleteAll() { //Arrange $book_id = 1; $test_copy = new Copy($book_id); $test_copy->save(); $book_id2 = 2; $test_copy2 = new Copy($book_id2); $test_copy2->save(); //Act Copy::deleteAll(); $result = Copy::getAll(); //Assert $this->assertEquals([], $result); }
$app->post("/add_copy", function () use($app) { $book_id = $_POST['book_id']; $book = Book::find($book_id); $author = $book->getAuthors(); $copy = new Copy($book_id); $copy->save(); $copies = Copy::findCopies($book_id); return $app['twig']->render('book.html.twig', array('book' => $book, 'author' => $author, 'copies' => $copies, 'patrons' => Patron::getAll(), 'checkouts' => Checkout::getAll())); }); $app->patch("/checkout_copy/{id}", function ($id) use($app) { $checkout = new Checkout($_POST['copy_id'], $_POST['patron_id'], $_POST['due_date']); $checkout->save(); $book_id = $_POST['book_id']; $book = Book::find($book_id); $author = $book->getAuthors(); return $app['twig']->render('book.html.twig', array('book' => $book, 'author' => $author, 'copies' => Copy::getAll(), 'patrons' => Patron::getAll(), 'checkouts' => Checkout::getAll())); }); // $app->patch("/checkout_copy/{id}", function($id) use ($app) { // $book = Book::find($id); // $author = $book->getAuthors(); // $copy_id = $_POST['copy_id']; // $copy = Copy::find($copy_id); // //$checkout = new Checkout($copy_id, $) // $copy->update($_POST['due_date']); // $copies = Copy::findCopies($id); // return $app['twig']->render('book.html.twig', array('book'=>$book, 'author'=>$author, 'copies'=> $copies, 'patrons'=>Patron::getAll())); // }); $app->patch("/patron/{id}", function ($id) use($app) { $patron = Patron::find($id); $patron->update($_POST['name']); return $app['twig']->render('patron.html.twig', array('patron' => $patron));
function test_delete() { //Arrange $available = true; $book_id = 4; $test_copy = new Copy($available, $book_id); $test_copy->save(); $available2 = true; $book_id2 = 5; $test_copy2 = new Copy($available2, $book_id2); $test_copy2->save(); //Act $test_copy->delete(); $result = Copy::getAll(); //Assert $this->assertEquals([$test_copy2], $result); }