示例#1
0
 static function findDueDate($search_id)
 {
     $found_checkout = null;
     $checkouts = Checkout::getAll();
     foreach ($checkouts as $checkout) {
         $checkout_id = $checkout->getId();
         if ($checkout_id == $search_id) {
             $found_checkout = $checkout;
         }
     }
     return $found_checkout;
 }
示例#2
0
 function testSave()
 {
     //Arrange
     $copy_id = 1;
     $patron_id = 1;
     $id = 1;
     $due_date = '2015-10-10';
     $test_checkout = new Checkout($copy_id, $patron_id, $due_date, $id);
     $test_checkout->save();
     //Act
     $result = Checkout::getAll();
     //Assert
     $this->assertEquals($test_checkout, $result[0]);
 }
示例#3
0
 function test_deleteAll()
 {
     //Arrange
     $due_date = "0001-01-01";
     $test_checkout = new Checkout($due_date);
     $test_checkout->save();
     $due_date2 = "2020-01-01";
     $test_checkout2 = new Checkout($due_date2);
     $test_checkout2->save();
     //Act
     Checkout::deleteAll();
     $result = Checkout::getAll();
     //Assert
     $this->assertEquals([], $result);
 }
 function testDeleteAll()
 {
     //Arrange
     $id = null;
     $patron_id = null;
     $copy_id = null;
     $due_date = "2012-12-12";
     $test_checkout = new Checkout($id, $patron_id, $copy_id, $due_date);
     $test_checkout->save();
     $due_date2 = "1989-09-04";
     $test_checkout2 = new Checkout($id, $patron_id, $copy_id, $due_date2);
     $test_checkout2->save();
     //Act
     Checkout::deleteAll();
     $result = Checkout::getAll();
     //Assert
     $this->assertEquals([], $result);
 }
示例#5
0
 function testAddCheckout()
 {
     $title = "Three Blind Mice";
     $test_book = new Book($title);
     $test_book->save();
     $test_copy = new Copy($amount = 1, $test_book->getId());
     $test_copy->save();
     $name = "Joe Bongtana";
     $test_patron = new Patron($name);
     $test_patron->save();
     $due_date = "01-01-2016";
     $status = 1;
     $test_checkout = new Checkout($test_copy->getId(), $test_patron->getId(), $due_date, $status);
     $test_checkout->save();
     $test_patron->addCheckout($test_checkout);
     $result = Checkout::getAll();
     $this->assertEquals($test_checkout, $result);
 }
示例#6
0
 function test_deleteAll()
 {
     //Arrange
     $due_date = "0001-01-01";
     $copy_id = 1;
     $patron_id = 2;
     $test_checkout = new Checkout($due_date, $copy_id, $patron_id);
     $test_checkout->save();
     $due_date2 = "2020-01-01";
     $copy_id2 = 3;
     $patron_id2 = 4;
     $test_checkout2 = new Checkout($due_date2, $copy_id2, $patron_id2);
     $test_checkout2->save();
     //Act
     Checkout::deleteAll();
     $result = Checkout::getAll();
     //Assert
     $this->assertEquals([], $result);
 }
示例#7
0
 function test_deleteAll()
 {
     //Arrange
     $copy_id = 1;
     $patron_id = 4;
     $due_date = "2015-09-03";
     $test_checkout = new Checkout($copy_id, $patron_id, $due_date);
     $test_checkout->save();
     $copy_id2 = 2;
     $patron_id2 = 1;
     $due_date2 = "2015-10-05";
     $test_checkout2 = new Checkout($copy_id2, $patron_id2, $due_date2);
     $test_checkout2->save();
     //Act
     Checkout::deleteAll();
     //Assert
     $result = Checkout::getAll();
     $this->assertEquals([], $result);
 }
示例#8
0
 static function find($search_id)
 {
     $found_checkout = null;
     $all_checkouts = Checkout::getAll();
     foreach ($all_checkouts as $checkout) {
         if ($checkout->getId() == $search_id) {
             $found_checkout = $checkout;
         }
     }
     return $found_checkout;
 }
示例#9
0
 function test_deleteAll()
 {
     //Arrange
     // Make a Patron
     $name = "Dan Brown";
     $phone = "3";
     $email = "*****@*****.**";
     $test_patron = new Patron($name, $phone, $email);
     $test_patron->save();
     // Make a Checkout and save
     $patron_id = $test_patron->getId();
     $copy_id = 1;
     $due_date = "2015-08-09";
     $test_checkout = new Checkout($patron_id, $copy_id, $due_date);
     $test_checkout->save();
     // Make a 2nd Checkout and save under the same patron
     $copy_id2 = 1;
     $due_date2 = "2015-08-09";
     $test_checkout2 = new Checkout($patron_id, $copy_id2, $due_date2);
     $test_checkout2->save();
     //Act
     Checkout::deleteAll();
     //Assert
     $result = Checkout::getAll();
     $this->assertEquals([], $result);
 }
示例#10
0
 function test_getAll()
 {
     // for now, feed a dummy copy_id just for testing
     // later, we will need to use getNextCopy() in Book class
     // to get a copy for a given book
     //Arrange
     // Make a Patron
     $name = "Dan Brown";
     $phone = "3";
     $email = "*****@*****.**";
     $test_patron = new Patron($name, $phone, $email);
     $test_patron->save();
     // Make a Checkout and save
     $patron_id = $test_patron->getId();
     $copy_id = 1;
     $date = "2015-08-09";
     $test_checkout = new Checkout($patron_id, $copy_id, $date);
     $test_checkout->save();
     // Make a 2nd Checkout and save under the same patron
     $copy_id2 = 1;
     $date2 = "2015-08-09";
     $test_checkout2 = new Checkout($patron_id, $copy_id2, $date2);
     $test_checkout2->save();
     //Act
     $result = Checkout::getAll();
     //Assert
     $this->assertEquals([$test_checkout, $test_checkout2], $result);
 }
示例#11
0
 function testGetAll()
 {
     $id = 1;
     $copy_id = 1;
     $patron_id = 1;
     $checkout_status = 0;
     $due_date = "2015-01-01";
     $test_checkout = new Checkout($patron_id, $copy_id, $due_date, $checkout_status, $id);
     $test_checkout->save();
     $id2 = 2;
     $copy_id2 = 2;
     $patron_id2 = 2;
     $checkout_status2 = 1;
     $due_date2 = "2015-02-02";
     $test_checkout2 = new Checkout($copy_id2, $patron_id2, $due_date2, $checkout_status2, $id2);
     $test_checkout2->save();
     $result = Checkout::getAll();
     $this->assertEquals([$test_checkout, $test_checkout2], $result);
 }
示例#12
0
$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));
示例#13
0
 function test_delete()
 {
     //Arrange
     $checked_in_status = 0;
     $due_date = "2000 BC";
     $copy_id = 4;
     $patron_id = 4;
     $test_checkout = new Checkout($checked_in_status, $due_date, $copy_id, $patron_id);
     $test_checkout->save();
     //Act
     $test_checkout->delete();
     $result = Checkout::getAll();
     //Assert
     $this->assertEquals([], $result);
 }
示例#14
0
 function test_updateReturned()
 {
     //Arrange
     $copy_id = 1;
     $patron_id = 4;
     $due_date = "2015-09-03";
     $test_checkout = new Checkout($copy_id, $patron_id, $due_date);
     $test_checkout->save();
     //Act
     $new_returned = true;
     $test_checkout->updateReturned($new_returned);
     //Assert
     $result = Checkout::getAll();
     $this->assertEquals($new_returned, $result[0]->getReturned());
 }
示例#15
0
 function testSave()
 {
     $patron_name = "Randy Mclure";
     $test_patron = new Patron($patron_name);
     $test_patron->save();
     $due_date = "2015-09-10";
     $copy_id = 1;
     $patron_id = 1;
     $checkin_status = 1;
     $test_checkout = new Checkout($due_date, $copy_id, $test_patron->getId(), $checkin_status);
     $test_checkout->save($test_patron);
     $result = Checkout::getAll();
     $this->assertEquals($test_checkout, $result[0]);
 }