Пример #1
0
 function testGetBook()
 {
     $title = "Carrie";
     $test_book = new Book($title);
     $test_book->save();
     $book_id = $test_book->getId();
     $test_copy = new Copy($book_id);
     $test_copy->save();
     $result = $test_copy->getBook();
     $this->assertEquals($test_book, $result);
 }
Пример #2
0
 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);
 }
Пример #3
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);
 }
Пример #4
0
 function testDeleteAll()
 {
     //Arrange
     $book_id = 1;
     $due_date = '0000-00-00';
     $id = 1;
     $test_copy = new Copy($book_id, $due_date, $id);
     $test_copy->save();
     $book_id2 = 2;
     $due_date2 = '0000-00-00';
     $id2 = 2;
     $test_copy2 = new Copy($book_id2, $due_date2, $id2);
     $test_copy2->save();
     //Act
     Copy::deleteALl();
     //Assert
     $result = Copy::getAll();
     $this->assertEquals([], $result);
 }
Пример #5
0
 function test_addCheckout()
 {
     //Arrange
     $book_id = 4;
     $test_copy = new Copy($book_id);
     $test_copy->save();
     $name = "Phyllis the kind Grandma";
     $test_patron = new Patron($name);
     $test_patron->save();
     //Act
     $test_copy->addCheckout($test_patron);
     $result = $test_copy->getCheckout();
     //Assert
     $this->assertEquals($test_copy->getId(), $result->getCopyId());
 }
Пример #6
0
 function testGetCheckouts()
 {
     //Arrange
     $name = "Jim Bob";
     $id = 1;
     $test_patron = new Patron($name, $id);
     $test_patron->save();
     $book_id = 1;
     $id = 1;
     $test_copy = new Copy($book_id, $id);
     $test_copy->save();
     $book_id2 = 2;
     $id2 = 2;
     $test_copy2 = new Copy($book_id2, $id2);
     $test_copy2->save();
     $copy_id = $test_copy->getId();
     $patron_id = $test_patron->getId();
     $id = null;
     $due_date = "2015-09-30";
     $test_checkout = new Checkout($copy_id, $patron_id, $due_date, $id);
     $test_checkout->save();
     // $copy_id2 = $test_copy2->getId();
     // $patron_id2 = $test_patron->getId();
     // $id2 = null;
     // $due_date2 = "2015-09-30";
     // $test_checkout2 = new Checkout($copy_id2, $patron_id2, $id2, $due_date2);
     $copy_id2 = $test_copy2->getId();
     $patron_id2 = $test_patron->getId();
     $id2 = null;
     $due_date2 = "2015-04-20";
     $test_checkout2 = new Checkout($copy_id2, $patron_id2, $due_date2, $id2);
     $test_checkout2->save();
     // var_dump($test_checkout);
     // var_dump($test_checkout2);
     //Act
     // $test_patron->addCheckout($test_checkout);
     // $test_patron->addCheckout($test_checkout2);
     $result = $test_patron->getCheckouts();
     // var_dump($result);
     //Assert
     $this->assertEquals(2, count($test_patron->getCheckouts()));
 }
Пример #7
0
 function testFindBookCopy()
 {
     $title = "Three Blind Mice";
     $test_book = new Book($title);
     $test_book->save();
     $test_copy = new Copy($amount = 1, $test_book->getId());
     $test_copy->save();
     $title2 = "Chicken Dog";
     $test_book2 = new Book($title2);
     $test_book2->save();
     $test_copy2 = new Copy($amount2 = 2, $test_book2->getId());
     $test_copy2->save();
     $result = Copy::findBookCopy($test_book->getId());
     $this->assertEquals($test_copy, $result);
 }
Пример #8
0
 function testDelete()
 {
     //Arrange
     $due_date = "2015-10-10";
     $book_id = 1;
     $id = 1;
     $test_copy = new Copy($due_date, $book_id, $id);
     $test_copy->save();
     $name = "Jim Bob";
     $id = 1;
     $test_patron = new Patron($name, $id);
     $test_patron->save();
     //Act
     $test_patron->addCopy($test_copy);
     $test_patron->delete();
     //Assert
     $this->assertEquals([], $test_copy->getPatrons());
 }
Пример #9
0
 function testGetPatron()
 {
     //Arrange
     $book_id = 1;
     $id = 1;
     $test_copy = new Copy($book_id, $id);
     $test_copy->save();
     $name = "Ping Pong";
     $id2 = 1;
     $test_patron = new Patron($name, $id2);
     $test_patron->save();
     $name2 = "Ding Dong";
     $id3 = 2;
     $test_patron2 = new Patron($name2, $id3);
     $test_patron2->save();
     //Act
     $test_copy->addPatron($test_patron->getId());
     $test_copy->addPatron($test_patron2->getId());
     //Assert
     $this->assertEquals($test_copy->getPatron(), [$test_patron, $test_patron2]);
 }
Пример #10
0
 function testGetCopy()
 {
     //Arrange
     $copy_id = 1;
     $test_copy = new Copy($copy_id);
     $test_copy->save();
     $copy_id2 = 2;
     $id2 = 2;
     $test_copy2 = new Copy($copy_id2);
     $test_copy2->save();
     $name = "Ping Pong";
     $id2 = 1;
     $test_patron = new Patron($name);
     $test_patron->save();
     //Act
     $test_patron->addCopy($test_copy->getId());
     $test_patron->addCopy($test_copy2->getId());
     //Assert
     $this->assertEquals($test_patron->getCopy(), [$test_copy, $test_copy2]);
 }
Пример #11
0
    $authors = $book->getAuthors();
    $copies = Copy::findCopies($id);
    return $app['twig']->render('book.html.twig', array('book' => $book, 'authors' => $authors, 'copies' => $copies, 'all_authors' => Author::getAll()));
});
$app->get("/author/{id}", function ($id) use($app) {
    $author = Author::find($id);
    $books = $author->getBooks();
    $copies = Copy::findCopies($id);
    return $app['twig']->render('author.html.twig', array('author' => $author, 'books' => $books, 'copies' => $copies, 'all_books' => Book::getAll()));
});
$app->post("/add_copy", function () use($app) {
    $book_id = $_POST['book_id'];
    $book = Book::find($book_id);
    $authors = $book->getAuthors();
    $copy = new Copy('0000-00-00', $book_id);
    $copy->save();
    $copies = Copy::findCopies($book_id);
    return $app['twig']->render('book.html.twig', array('book' => $book, 'authors' => $authors, 'copies' => $copies));
});
$app->patch("/checkout_copy/{id}", function ($id) use($app) {
    $book = Book::find($id);
    $authors = $book->getAuthors();
    $copy_id = $_POST['copy_id'];
    $copy = Copy::find($copy_id);
    $copy->update($_POST['due_date']);
    $copies = Copy::findCopies($id);
    return $app['twig']->render('book.html.twig', array('book' => $book, 'authors' => $authors, 'copies' => $copies));
});
$app->post("/delete_books", function () use($app) {
    Book::deleteAll();
    return $app['twig']->render('books.html.twig', array('books' => Book::getAll()));
Пример #12
0
 function test_getCopy()
 {
     //Arrange
     $book_id = 1;
     $test_copy = new Copy($book_id);
     $test_copy->save();
     $checked_in_status = 0;
     $due_date = "2000 BC";
     $patron_id = 1;
     $test_checkout = new Checkout($checked_in_status, $due_date, $test_copy->getId(), $patron_id);
     $test_checkout->save();
     //Act
     $result = $test_checkout->getCopy();
     //Assert
     $this->assertEquals($test_copy, $result);
 }
Пример #13
0
 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);
 }
Пример #14
0
 function testFindCopies()
 {
     //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 = 1;
     $id2 = 2;
     $test_copy2 = new Copy($due_date2, $book_id2, $id2);
     $test_copy2->save();
     $title = "Harry Potter";
     $id = 1;
     $test_book = new Book($title, $id);
     $test_book->save();
     //Act
     $result = Copy::findCopies($book_id);
     //var_dump($result);
     //Assert
     $this->assertEquals([$test_copy, $test_copy2], $result);
 }
Пример #15
0
 function test_addCheckout()
 {
     //Arrange
     $name = "Jerald the crotchety grandpa";
     $test_patron = new Patron($name);
     $test_patron->save();
     $book_id = 8;
     $test_copy = new Copy($book_id);
     $test_copy->save();
     //Act
     $test_patron->addCheckout($test_copy);
     $result = $test_patron->getCheckouts();
     //Assert
     $this->assertEquals($test_patron->getId(), $result[0]->getPatronId());
 }
Пример #16
0
 function test_addCopy()
 {
     $title = "Three Blind Mice";
     $test_book = new Book($title);
     $test_book->save();
     $test_copy = new Copy($amount = 1, $test_book->getId());
     $test_copy->save();
     $title2 = "Chicken Dog";
     $test_book2 = new Book($title2);
     $test_book2->save();
     $test_book->addCopies(1);
     $result = $test_copy->getAmount();
     $this->assertEquals(2, $result);
 }
Пример #17
0
 function testFind()
 {
     $book_title = "Snow Crash";
     $id = null;
     $amount = 1;
     $test_book = new Book($book_title, $id);
     $test_book->save();
     $book_title2 = "Dune";
     $id2 = null;
     $amount2 = 2;
     $test_book2 = new Book($book_title2, $id2);
     $test_book2->save();
     $test_copy = new Copy($amount, $test_book->getId());
     $test_copy->save();
     $test_copy2 = new Copy($amount2, $test_book2->getId());
     $test_copy2->save();
     $result = Copy::find($test_copy->getId());
     $this->assertEquals($test_copy, $result);
 }