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); }
function testDelete() { $name = "Randy Mclure"; $test_patron = new Patron($name); $test_patron->save(); $name2 = "Ballface Majure"; $test_patron2 = new Patron($name2); $test_patron2->save(); $test_patron->delete(); $this->assertEquals([$test_patron2], Patron::getAll()); }
function testGetPatronId() { $patron_name = "Eduardo"; $patron_id = 1; $test_patron = new Patron($patron_name, $patron_id); $test_patron->save(); $copy_id = 1; $due_date = "2015-01-01"; $checkout_status = false; $test_checkout = new Checkout($patron_id, $copy_id, $due_date, $checkout_status); $result = $test_checkout->getPatronId(); $this->assertEquals(1, $result); }
protected function tearDown() { Checkout::deleteAll(); Book::deleteAll(); Author::deleteAll(); Patron::deleteAll(); }
protected function tearDown() { Author::deleteAll(); Book::deleteAll(); Patron::deleteAll(); Copies::deleteAll(); }
function testGetAll() { //Arrange $patron_name = "Butterball"; $id = null; $test_patron = new Patron($patron_name, $id); $test_patron->save(); $patron_name2 = "Lance Armstrang"; $id2 = null; $test_patron2 = new Patron($patron_name2, $id2); $test_patron2->save(); //Act $result = Patron::getAll(); //Assert $this->assertEquals([$test_patron, $test_patron2], $result); }
protected function tearDown() { Book::deleteAll(); Copy::deleteAll(); Author::deleteAll(); Patron::deleteAll(); }
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); }
static function find($searchId) { $patrons_returned = Patron::getAll(); foreach ($patrons_returned as $patron) { if ($searchId == $patron->getId()) { return $patron; } } }
static function find($search_id) { $found_patron = null; $all_patrons = Patron::getAll(); foreach ($all_patrons as $patron) { if ($patron->getId() == $search_id) { $found_patron = $patron; } } return $found_patron; }
static function search($search_email) { $found_patron = NULL; $patrons = Patron::getAll(); foreach ($patrons as $patron) { $patron_email = $patron->getEmail(); if ($patron_email == $search_email) { $found_patron = $patron; } } return $found_patron; }
static function find($search_id) { $found_patron = NULL; $patrons = Patron::getAll(); foreach ($patrons as $patron) { $patron_id = $patron->getId(); if ($patron_id == $search_id) { $found_patron = $patron; } } return $found_patron; }
static function find($search_id) { $found = null; $patrons = Patron::getAll(); foreach ($patrons as $patron) { $patron_id = $patron->getId(); if ($patron_id == $search_id) { $found = $patron; } } //end foreach return $found; }
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]); }
$patron_id = $patron->getId(); return $app['twig']->render('patron.html.twig', array('patron' => $patron, 'checkouts' => $patron->getCheckouts())); }); //-------------------------------------------------------// $app->post("/books", function () use($app) { $new_book = new Book($_POST['title']); $new_book->save(); return $app['twig']->render('books.html.twig', array('books' => Book::getAll())); }); $app->post("/authors", function () use($app) { $new_author = new Author($_POST['name']); $new_author->save(); return $app['twig']->render('authors.html.twig', array('authors' => Author::getAll())); }); $app->post("/patrons", function () use($app) { $new_patron = new Patron($_POST['name']); $new_patron->save(); return $app['twig']->render('patrons.html.twig', array('patrons' => Patron::getAll())); }); $app->post("/add_author", function () use($app) { $book = Book::find($_POST['book_id']); $author = Author::find($_POST['author_id']); $book->addAuthor($author); return $app['twig']->render('book.html.twig', array('copies' => $book->getCopies(), 'book' => $book, 'authors' => $book->getAuthors(), 'all_authors' => Author::getAll())); }); $app->post("/add_book", function () use($app) { $book = Book::find($_POST['book_id']); $author = Author::find($_POST['author_id']); $author->addBook($book); return $app['twig']->render('author.html.twig', array('author' => $author, 'books' => $author->getBooks(), 'all_books' => Book::getAll())); });
function testGetAllTokens() { $name = "Side Street"; $phone = "555-555-5555"; $address = "123 ABC. Street"; $website = "http://www.sidestreetpdx.com"; $test_bar = new Bar($name, $phone, $address, $website); $test_bar->save(); $test_item = new Item("tacos", 2.25); $test_item->save(); $test_bar->addItem($test_item); $returned_ids = $GLOBALS['DB']->query("SELECT id FROM menus WHERE bar_id = {$test_bar->getId()};"); $ids = array(); foreach ($returned_ids as $returned_id) { $id = $returned_id['id']; array_push($ids, $id); } $name = "Kyle Pratuch"; $email = "*****@*****.**"; $test_patron = new Patron($name, $email); $test_patron->save(); $test_token = new Token($test_patron->getId(), $ids[0], 3); $test_token->save(); // var_dump($test_token); $result = $test_bar->getAllTokens(); $this->assertEquals($test_token, $result[0]); }
$mail->addReplyTo('*****@*****.**', 'Beer Me!'); $mail->isHTML(true); $mail->Subject = 'Somebody sent you a token!'; $mail->Body = 'HEY YOU GUYS! LOOK WAT I DONE DID!!!!!!.'; $mail->AltBody = 'Received token.'; $email = $_POST['email']; $name = $_POST['name']; if (!$mail->send()) { $message = 'Message could not be sent. <p>'; } else { $message = 'Message has been sent.'; } return $app['twig']->render("email.html.twig", array('message' => $message)); }); $app->post("/add_preferred_bar/{id}", function ($id) use($app) { $user = Patron::find($id); $all_bars = Bar::getAll(); $bar = Bar::find($_POST['add_bar']); $user->addPreferredBar($bar); return $app['twig']->render("patron.html.twig", array('user' => $user, 'user_tokens' => $user->getTokens(), 'all_bars' => $all_bars, 'preferred_bars' => true, 'send_token' => false, 'token_form' => false, 'edit_user' => false)); }); // $app->delete("/delete_preferred_bar/{id}/{bar_id}", function($id, $bar_id) use($app) { // $user = Patron::find($id); // $all_bars = Bar::getAll(); // $bar = Bar::find($bar_id); // $user->deleteBar($bar); // return $app['twig']->render("patron.html.twig", array( // 'user' => $user, // 'user_tokens' =>$user->getTokens(), // 'all_bars' => $all_bars, // 'preferred_bars' => false,
function testDeleteOne() { //Arrange $patron_name = "Sally"; $phone_number = "1234567890"; $test_patron = new Patron($patron_name, $phone_number); $test_patron->save(); $patron_name2 = "Joe"; $phone_number2 = "0987654321"; $test_patron2 = new Patron($patron_name2, $phone_number2); $test_patron2->save(); //Act $test_patron->deleteOne(); //Assert $this->assertEquals([$test_patron2], Patron::getAll()); }
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()); }
protected function tearDown() { Patron::deleteAll(); Book::deleteAll(); Checkout::deleteAll(); }
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())); }
return $app['twig']->render("index.html.twig", array('about' => false, 'sign_up' => false, "sign_in" => false, 'team' => false)); } elseif ($bar == NULL) { return $app['twig']->render("patron.html.twig", array('user' => $user, 'user_tokens' => $user->getTokens(), 'all_bars' => $all_bars, 'preferred_bars' => false, 'send_token' => false, 'token_form' => false, 'edit_user' => false)); } else { return $app['twig']->render("bar.html.twig", array('bar' => $bar, 'tokens' => $bar->getAllTokens(), 'items' => $bar->getAllItems(), 'get_tokens' => false, 'show_menu' => false, 'edit_bar' => false)); } }); //Sign Up Routes: $app->get("/show_customer_signup", function () use($app) { return $app['twig']->render('index.html.twig', array('about' => false, 'sign_up' => true, "sign_in" => false, 'team' => false, 'customer_signup' => true, 'business_signup' => false)); }); $app->get("/show_business_signup", function () use($app) { return $app['twig']->render('index.html.twig', array('about' => false, 'sign_up' => true, "sign_in" => false, 'team' => false, 'customer_signup' => false, 'business_signup' => true)); }); $app->post("/customer_signup", function () use($app) { $new_user = new Patron($_POST['username'], $_POST['email']); $new_user->save(); return $app['twig']->render("signup_confirmation.html.twig"); }); $app->post("/business_signup", function () use($app) { $new_bar = new Bar($_POST['name'], $_POST['phone'], $_POST['address'], $_POST['website']); $new_bar->save(); return $app['twig']->render("signup_confirmation.html.twig"); }); //Get Show email search $app->get("/show_email_search/{id}", function ($id) use($app) { $user = Patron::find($id); $all_bars = Bar::getAll(); return $app['twig']->render("patron.html.twig", array('user' => $user, 'user_tokens' => $user->getTokens(), 'all_bars' => $all_bars, 'preferred_bars' => false, 'send_token' => true, 'token_form' => false, 'edit_user' => false)); }); //Get Show User Tokens
function test_updateDueDate() { //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(); $new_due_date = "2015-08-27"; //Act $test_checkout->updateDueDate($new_due_date); //Assert $result = $test_checkout->getDueDate(); $this->assertEquals($new_due_date, $result); }
/** * Lista de proyectos para ser revisados por el cron/daily * en campaña * o financiados hace más de dos meses y con retornos/recompensas pendientes * * solo carga datos necesarios para cron/daily * * @return array de instancias parciales de proyecto */ public static function review() { $projects = array(); $sql = "SELECT \n id, status, \n DATE_FORMAT(from_unixtime(unix_timestamp(now()) - unix_timestamp(published)), '%j') as dias\n FROM project \n WHERE status IN ('3', '4')\n HAVING status = 3 OR (status = 4 AND dias > 138)\n ORDER BY days ASC"; $query = self::query($sql); foreach ($query->fetchAll(\PDO::FETCH_CLASS, __CLASS__) as $proj) { $the_proj = self::getMedium($proj->id); $the_proj->percent = floor($the_proj->invested / $the_proj->mincost * 100); $the_proj->days = (int) $proj->dias - 1; $the_proj->patrons = Patron::numRecos($proj->id); $projects[] = $the_proj; } return $projects; }
function testUpdatePatronName() { //Arrange $patron_name = "Joe Patron"; $id = 1; $test_patron = new Patron($patron_name, $id); $test_patron->save(); $new_name = "James Patron"; //Act $test_patron->updatePatronName($new_name); //Assert $this->assertEquals("James Patron", $test_patron->getPatronName()); }
function testDelete() { //Arrange $id = null; $name = "Allen"; $phone = "4444"; $test_patron = new Patron($id, $name, $phone); $name2 = "Phil"; $phone2 = "5555"; $test_patron2 = new Patron($id, $name2, $phone2); $test_patron2->save(); //Act $test_patron->delete(); //Assert $this->assertEquals([$test_patron2], Patron::getAll()); }
function test_getAllCheckouts() { //Arrange // create 2 test patrons. $name = "Suzie Palloozi"; $phone = "1-800-439-0398"; $test_patron = new Patron($name, $phone); $test_patron->save(); // create 2 test checkouts. hard code copy_id for now $copy_id = 1; $patron_id = $test_patron->getId(); $due_date = "2015-03-04"; $test_checkout = new Checkout($copy_id, $patron_id, $due_date); $test_checkout->save(); //Act $result = $test_patron->getAllCheckouts(); //Assert $this->assertEquals([$test_checkout], $result); }
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()); }
function testGetPatrons() { //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(); $name2 = "Sally Sue"; $id2 = 2; $test_patron2 = new Patron($name, $id); $test_patron2->save(); //Act $test_copy->addPatron($test_patron); $test_copy->addPatron($test_patron2); $result = $test_copy->getPatrons(); //Assert $this->assertEquals([$test_patron, $test_patron2], $result); }
function test_find() { //Arrange $name = "Dan Brown"; $phone = "3"; $email = "*****@*****.**"; $test_patron = new Patron($name, $phone, $email); $test_patron->save(); //Act $result = Patron::find($test_patron->getId()); //Assert $this->assertEquals($test_patron, $result); }