function test_GetRestaurants() { //Arrange $name = "Drinks"; $id = null; $test_cuisine = new Cuisine($name, $id); $test_cuisine->save(); $restaurant = "Aalto"; $address = "123 Belmont"; $phone = "123-456-7890"; $cuisine_id = $test_cuisine->getId(); $id = 1; $test_restaurant = new Restaurant($restaurant, $address, $phone, $cuisine_id, $id); $test_restaurant->save(); $restaurant2 = "Aalto"; $address2 = "123 Belmont"; $phone2 = "123-456-7890"; $cuisine_id2 = $test_cuisine->getId(); $id = 2; $test_restaurant2 = new Restaurant($restaurant, $address, $phone, $cuisine_id, $id); $test_restaurant2->save(); //Act $result = $test_cuisine->getRestaurants(); //Assert $this->assertEquals([$test_restaurant, $test_restaurant2], $result); }
function fest_allRestaurantsInCuisine() { //Arrange $cuisine = "Pizza"; $test_cuisine = new Cuisine($cuisine); $test_cuisine->save(); $cuisine = "Burgers"; $test_cuisine2 = new Cuisine($cuisine); $test_cuisine2->save(); $restaurant_name = "Antoons"; $cuisine_type = 1; $restaurant_phone = "4128675309"; $restaurant_address = "123 Atwood St"; $test_Restaurant = new Restaurant($restaurant_name, $cuisine_type, $restaurant_phone, $restaurant_address); $test_Restaurant->save(); $restaurant_name = "Spankys"; $cuisine_type = 2; $restaurant_phone = "8015715713"; $restaurant_address = "379 E 3333 S"; $test_next_Restaurant = new Restaurant($restaurant_name, $cuisine_type, $restaurant_phone, $restaurant_address); $test_next_Restaurant->save(); $restaurant_name = "Dave & Busters"; $cuisine_type = 1; $restaurant_phone = "44444444"; $restaurant_address = "HELL"; $test_third_restaurant = new Restaurant($restaurant_name, $cuisine_type, $restaurant_phone, $restaurant_address); $test_third_restaurant->save(); //Act $result = Cuisine::getRestaurants(); //Assert $this->assertEquals([$test_Restaurant, $test_third_restaurant], $result); }
function test_find() { //Arrange $restaurant_name = "Antoons"; $cuisine_type = 1; $restaurant_phone = "4128675309"; $restaurant_address = "123 Atwood St"; $test_Restaurant = new Restaurant($restaurant_name, $cuisine_type, $restaurant_phone, $restaurant_address); $test_Restaurant->save(); //Act $result = Restaurant::find($test_Restaurant->getId()); //Assert $this->assertEquals($test_Restaurant, $result); }
public function actionAdd_restaurant() { $restaurant = new Restaurant(); $restaurant->style = $_POST['style']; $restaurant->content = $_POST['content']; $restaurant->company = $_POST['company']; if (isset($_POST['source'])) { $restaurant->source = $_POST['source']; } if (isset($_POST['thumb'])) { $restaurant->thumb = $_POST['thumb']; } $restaurant->boat = $_POST['boat']; $restaurant->save(); //$this->redirect(Yii::app()->request->urlReferrer); echo 1; // echo CJSON::encode(array('title'=>$_POST['title'], 'area'=>$_POST['area'], 'port'=>$_POST['port']));//Yii 的方法将数组处理成json数据 }
/** * 添加餐厅 */ public function ActionAddRestaurant() { $restaurant_model = new Restaurant(); if (isset($_POST['Restaurant'])) { // 填充模型 $restaurant_model->attributes = $_POST['Restaurant']; // 执行添加 if ($restaurant_model->save()) { // 添加操作日志 [S] $log = Yii::app()->user->name . '于 ' . date('Y-m-d H:i:s', time()) . ' 添加了一个名为 【' . $_POST['Restaurant']['RestaurantName'] . '】 的餐厅'; OperationLogManage::AddOperationLog($log); // 添加日志 // 添加操作日志 [E] Yii::app()->user->setFlash('save_sign', '添加成功'); $this->redirect(Yii::app()->createUrl('Restaurant/ListRestaurant')); } else { Yii::app()->user->setFlash('save_sign', '添加失败'); $this->renderPartial('add_restaurant', array('restaurant_model' => $restaurant_model)); } } else { // 跳转至添加页 $this->renderPartial('add_restaurant', array('restaurant_model' => $restaurant_model)); } }
function testUpdateAnswer() { //Arrange //We need a User and a User saved //Arrange //We need a User and a User saved $user = "******"; $password = "******"; $id = null; $vegie = 0; $admin = 1; $test_User = new User($user, $password, $vegie, $admin, $id); $test_User->save(); $name = "Little Big Burger"; $address = "123 NW 23rd Ave."; $phone = "971-289-8000"; $price = 1; $vegie = 0; $opentime = 00; $closetime = 2100; $id = 1; $test_restaurant = new Restaurant($name, $address, $phone, $price, $vegie, $opentime, $closetime, $id); $test_restaurant->save(); $answer = 0; $restaurant_id = 1; $user_id = 1; $id2 = 1; $test_response = new Response($answer, $restaurant_id, $user_id, $id2); $test_response->save(); $test_User->addAnswer($test_User->getId(), $test_restaurant->getId(), $test_response->getAnswer()); $test_User->updateAnswer(2, 1); $this->assertEquals($test_User->getDisLikes(), [$test_restaurant]); }
function test_DeleteCuisineRestaurants() { //Arrange //cuisine $name = "Japanese"; $id = null; $test_cuisine = new Cuisine($name, $id); $test_cuisine->save(); //restaurant $name = "Good Fortune"; $cuisine_id = $test_cuisine->getId(); $description = "very tasty."; $address = "1111 SW 11th Ave"; $test_restaurant = new Restaurant($name, $id, $cuisine_id, $description, $address); $test_restaurant->save(); //Act $test_cuisine->delete(); //Assert $this->assertEquals([], Restaurant::getAll()); }
return $app['twig']->render('index.html.twig'); #, array('options' => Option::getAll())); }); $app->post('/options', function () use($app) { $suitable_option_names = $_POST["option_names"]; $suitable_option_ids = Option::getIdsFromNames($suitable_option_names); $options = Option::getObjects($suitable_option_ids); $suitable_restaurants = Restaurant::suitableRestaurants($suitable_option_ids); return $app['twig']->render('results.html.twig', array('suitable_restaurants' => $suitable_restaurants, 'options' => $options)); }); $app->get('/admin', function () use($app) { return $app['twig']->render('admin.html.twig', array('restaurants' => Restaurant::getAll(), 'options' => Option::getAll())); }); $app->post('/add_restaurants', function () use($app) { $restaurant_name = new Restaurant($_POST['restaurant_name']); $restaurant_name->save(); return $app['twig']->render('admin.html.twig', array('restaurants' => Restaurant::getAll(), 'options' => Option::getAll())); }); $app->post('/add_options', function () use($app) { $option_name = new Option($_POST['option_name']); $option_name->save(); return $app['twig']->render('admin.html.twig', array('restaurants' => Restaurant::getAll(), 'options' => Option::getAll())); }); $app->post('/add_restaurant_options', function () use($app) { $restaurant = Restaurant::find($_POST['restaurant_id']); $option = Option::find($_POST['option_id']); $restaurant->addOption($option); return $app['twig']->render('restaurant.html.twig', array('restaurant' => $restaurant, 'restaurant_options' => $restaurant->getOptions(), 'all_options' => Option::getAll())); }); $app->post('/add_option_restaurants', function () use($app) { $option = Option::find($_POST['option_id']);
function testDelete() { //Arrange $name = "Pizza Party"; $phone_number = "123-456-7890"; $address = "1234 Pepperoni Lane"; $id = null; $cuisine_id = 4; $test_restaurant = new Restaurant($name, $phone_number, $address, $id, $cuisine_id); $restaurant_id = $test_restaurant->getId(); $test_restaurant->save(); $name2 = "Burger Bash "; $test_restaurant2 = new Restaurant($name2, $phone_number, $address, $id, $cuisine_id); $test_restaurant2->save(); //Act $test_restaurant->delete(); //Assert $this->assertEquals([$test_restaurant2], Restaurant::getAll()); }
function test_DeleteCuisineRestaurants() { //Arrange $id = null; $cuisine_type = "Brazilian"; $test_cuisine_type = new Cuisine($id, $cuisine_type); $name = "Peles Brazilian Buffet"; $phone = "510-814-2012"; $address = "190b Mississippi St, Portland, OR 97221"; $hours = "9am - ?"; $test_cuisine_type_id = $test_cuisine_type->getId(); $test_restaurant = new Restaurant($id, $name, $phone, $address, $hours, $test_cuisine_type_id); $test_restaurant->save(); //Act $test_cuisine_type->delete(); //Assert $this->assertEquals([], Restaurant::getAll()); }
function test_cuisine_delete() { $style = "Thai"; $test_cuisine = new Cuisine($style); $test_cuisine->save(); $style2 = "burgers"; $test_cuisine2 = new Cuisine($style2); $test_cuisine2->save(); $name = "Pok Pok"; $category_id = $test_cuisine->getId(); $test_restaurant = new Restaurant($name, $category_id); $test_restaurant->save(); $name2 = "Dicks"; $category_id2 = $test_cuisine2->getId(); $test_restaurant2 = new Restaurant($name2, $category_id2); $test_restaurant2->save(); //Act $test_cuisine->delete(); //Assert $this->assertEquals([$test_restaurant2], Restaurant::getAll()); }
function test_deleteReviews() { $name = "Asian"; $id = null; $test_cuisine = new Cuisine($name, $id); $test_cuisine->save(); $restaurant_name = "The Golden Duck"; $location = "898 SW 5th Ave, Portland, OR"; $description = "A Chill Asian experince"; $price = "\$\$"; $cuisine_id = $test_cuisine->getId(); $test_restaurant = new Restaurant($restaurant_name, $location, $description, $price, $cuisine_id); $test_restaurant->save(); $restaurant_name2 = "The Red Dragon"; $location2 = "899 SW 5th Ave, Portland, OR"; $description2 = "A Intense Asian experince"; $price2 = "\$\$\$"; $cuisine_id2 = $test_cuisine->getId(); $test_restaurant2 = new Restaurant($restaurant_name2, $location2, $description2, $price2, $cuisine_id2); $test_restaurant2->save(); $user = "******"; $stars = 3; $headline = "It is aight."; $body = "Yeah, pretty aight bro"; $restaurant_id = $test_restaurant->getId(); $test_review = new Review($user, $stars, $headline, $body, $restaurant_id); $test_review->save(); $user2 = "6969babygirl"; $stars2 = 3; $headline2 = "XOXO"; $body2 = "I cant even"; $restaurant_id2 = $test_restaurant->getId(); $test_review2 = new Review($user2, $stars2, $headline2, $body2, $restaurant_id2); $test_review2->save(); $test_restaurant->delete(); $result = Review::getAll(); //var_dump($result); $this->assertEquals([], $result); }
function testGetRestaurants() { $type = "Thai"; $id = null; $test_Cuisine = new Cuisine($type, $id); $test_Cuisine->save(); $test_Restaurant = new Restaurant("Pok Pok", $id, "555-456-2345", "123 abcd street", "http://www.helloworld.com", $test_Cuisine->getId()); $test_Restaurant->save(); $test_Restaurant2 = new Restaurant("Whiskey Soda Lounge", $id, "555-555-5555", "678 DEF street", "http://www.pokpok.com", $test_Cuisine->getId()); $test_Restaurant2->save(); $result = $test_Cuisine->getRestaurants(); $this->assertEquals([$test_Restaurant, $test_Restaurant2], $result); }
function testDeleteCuisineRestaurants() { //Arrange $name = "Italian"; $id = null; $test_cuisine = new Cuisine($name, $id); $test_cuisine->save(); $name = "Piazza Italia"; $cuisine_id = $test_cuisine->getId(); $test_restaurant = new Restaurant($name, $id, $cuisine_id, $rating); $test_restaurant->save(); //Act $test_cuisine->delete(); //Assert $this->assertEquals([], Restaurant::getAll()); }
function testGetRestaurants() { //Arrange $type = "Italian"; $id = null; $test_cuisine = new Cuisine($type, $id); $test_cuisine->save(); $test_cuisine_id = $test_cuisine->getId(); $description = "OK Chinese food"; $name = "City Chinese"; $test_restaurant = new Restaurant($description, $id, $test_cuisine_id, $name); $test_restaurant->save(); $description2 = "OK Mexican"; $name2 = "City Mexican"; $test_restaurant2 = new Restaurant($description2, $id, $test_cuisine_id, $name2); $test_restaurant2->save(); //Act $result = $test_cuisine->getRestaurants(); //Assert $this->assertEquals([$test_restaurant, $test_restaurant2], $result); }
function test_restaurant_getStars() { //Arrange $style = "Thai"; $test_cuisine = new Cuisine($style); $test_cuisine->save(); $name = "Pok Pok"; $category_id = $test_cuisine->getId(); $stars = 5; $test_restaurant = new Restaurant($name, $category_id, null, $stars); $test_restaurant->save(); $name2 = "Dicks"; $stars2 = 3; $category_id2 = $test_cuisine->getId(); $test_restaurant2 = new Restaurant($name2, $category_id, null, $stars2); $test_restaurant2->save(); //Act $result = Restaurant::getAll(); //Assert $this->assertEquals(5, $result[0]->getStars()); }
function test_deleteAll() { //arrange $name = "Taco Hell"; $id = null; $test_restaurant = new Restaurant($name, $id); $test_restaurant->save(); $name2 = "Burger Queen"; $test_restaurant2 = new Restaurant($name2, $id); $test_restaurant2->save(); //act Restaurant::deleteAll(); //assert $result = Restaurant::getAll(); $this->assertEquals([], $result); }
function test_delete() { $address = "4234 N Interstate Ave, Portland OR 97217"; $phone = "503-287-9740"; $cuisine_id = 2; $place_name = "Happy House"; $id = null; $test_restaurant = new Restaurant($place_name, $id, $address, $phone, $cuisine_id); $test_restaurant->save(); $place_name2 = "Golden Dragon"; $test_restaurant2 = new Restaurant($place_name2, $id, $address, $phone, $cuisine_id); $test_restaurant2->save(); $test_restaurant->delete(); $this->assertEquals([$test_restaurant2], Restaurant::getAll()); }
function testDelete() { //Arrange $restaurant_name = "McDonalds"; $id = null; $test_restaurant = new Restaurant($restaurant_name, $id); $test_restaurant->save(); $restaurant_id = $test_restaurant->getId(); $cuisine_name = "burgers"; $test_cuisine = new Cuisine($cuisine_name, $id, $restaurant_id); $test_cuisine->save(); //Act $test_cuisine->deleteOne(); //Assert $this->assertEquals([], Cuisine::getAll()); }
function test_getRestaurants() { $name = "Chinese"; $id = null; $test_cuisine = new Cuisine($name, $id); $test_cuisine->save(); $address = "4234 N Interstate Ave, Portland OR 97217"; $phone = "503-287-9740"; $cuisine_id = $test_cuisine->getId(); $place_name = "Happy House"; $test_restaurant = new Restaurant($place_name, $id, $address, $phone, $cuisine_id); $test_restaurant->save(); $place_name2 = "Golden Dragon"; $test_restaurant2 = new Restaurant($place_name2, $id, $address, $phone, $cuisine_id); $test_restaurant2->save(); $result = $test_cuisine->getRestaurants(); $this->assertEquals([$test_restaurant, $test_restaurant2], $result); }
$p->lastname = "Smith"; $p->save(); $pid = $p->getPrimary(); dbm_debug('info', "When saving the first example Person, it received a primary key value of {$pid}"); $m = new Person(); $m->firstname = "Jane"; $m->lastname = "Doe"; $m->save(); $mid = $m->getPrimary(); dbm_debug('info', "When saving the second example Person, it received a primary key value of {$mid}"); $r = new Restaurant(); $r->name = "Joe's Place"; $r->rating = 5; $r->owner = $p; $r->manager = $m; $r->save(); dbm_debug('info', 'Done saving examples.'); $rid = $r->getPrimary(); dbm_debug('info', "When saving the example restaurant, it received a primary key value of {$rid}, which can be used later to load the Restaurant from the database."); dbm_debug('info', "Like this:"); $joes = new Restaurant($rid); dbm_debug('info', 'The restaurant object has been created, but there won\'t be any database traffic until you try to access its attributes:'); // This next line will trigger the load from the database echo "{$joes->name} is a {$joes->rating}-star restaurant."; dbm_debug('info', 'Similarly, the external table objects, in this case the owner and manager, have been created, but they won\'t load themselves from the database until you try to access their attributes.'); // This next line will trigger the owner object to load itself from the database echo "{$joes->name} is owned by {$joes->owner->firstname} {$joes->owner->lastname}."; // This next line will trigger the manager object to load itself from the database echo "{$joes->name} is run by {$joes->manager->firstname} {$joes->manager->lastname}."; dbm_debug('info', "Notice that the returned attribs include a Person object as the 'owner' and 'manager' attributes. You get the actual objects, not just their primary keys"); dbm_debug('data', $joes->attribs());
function testDelete() { //Arrange $name = "Drinks"; $id = null; $test_Cuisine = new Cuisine($name, $id); $test_Cuisine->save(); $restaurant = "Aalto"; $address = "123 Belmont"; $phone = "123-456-7890"; $cuisine_id = $test_Cuisine->getId(); $test_restaurant = new Restaurant($restaurant, $address, $phone, $cuisine_id, $id); $test_restaurant->save(); $restaurant2 = "HobNob"; $address2 = "999 somewhere"; $phone2 = "234-555-5555"; $cuisine_id2 = $test_Cuisine->getId(); $test_restaurant2 = new Restaurant($restaurant, $address, $phone, $cuisine_id, $id); $test_restaurant2->save(); //Act $test_restaurant->delete(); //Assert $this->assertEquals([$test_restaurant2], Restaurant::getAll()); }
function test_getRestaurants() { //Arrange $test_cuisine = new Cuisine("Lebanese", false, 5); $test_cuisine->save(); $test_cuisine_id = $test_cuisine->getId(); $test_restaurant1 = new Restaurant("Bens Bulkogi", 50, "eastside", true, $test_cuisine_id); $test_restaurant1->save(); //var_dump($test_restaurant1); $test_restaurant2 = new Restaurant("Marios Pizza Hole", 35, "Hole", false, $test_cuisine_id); $test_restaurant2->save(); //Act $result = $test_cuisine->getRestaurants(); //Assert $this->assertEquals([$test_restaurant1, $test_restaurant2], $result); //$this->assertEquals([], $result); }
function test_getRestaurants() { //arrange $name = "peanuts"; $test_allergen = new Allergen($name); $test_allergen->save(); $test_allergen_id = $test_allergen->getId(); $restaurant_name = "Taco Hell"; $test_restaurant = new Restaurant($restaurant_name); $test_restaurant->save(); $restaurant_name2 = "Burger Queen"; $test_restaurant2 = new Restaurant($restaurant_name2); $test_restaurant2->save(); //act //addRestaurant and getRestaurant are dependent on each other! $test_allergen->addRestaurant($test_restaurant); $test_allergen->addRestaurant($test_restaurant2); $result = $test_allergen->getRestaurants(); //assert $this->assertEquals([$test_restaurant, $test_restaurant2], $result); }
function test_find() { //Arrange $test_name = "Toms Tomatos "; $test_seats = 15; $test_location = "Farmville"; $test_evenings = true; $test_cuisine = new Cuisine("Mexican", true, 1); $test_cuisine->save(); $test_restaurant = new Restaurant($test_name, $test_seats, $test_location, $test_evenings, $test_cuisine->getId()); $test_restaurant->save(); //Act $result = Restaurant::find($test_restaurant->getId()); //Assert $this->assertEquals($test_restaurant, $result); }
function testUpdate() { //Arrange $type = "french"; $id = null; $test_cuisine = new Cuisine($type, $id); $test_cuisine->save(); $name = "Petit Provence"; $phone = "555-555-5555"; $price = "\$\$"; $cuisine_id = $test_cuisine->getId(); // $id = null; $test_restaurant = new Restaurant($name, $phone, $price, $cuisine_id); $test_restaurant->save(); $new_name = "Escargot"; $new_phone = "666-666-6666"; $new_price = "\$\$\$"; // $cuisine_id = 1; // $new_id = null; $new_test_restaurant = new Restaurant($new_name, $new_phone, $new_price, $cuisine_id, $test_restaurant->getId()); // $new_test_restaurant->save(); // var_dump($new_test_restaurant); //Act $test_restaurant->update($new_name, $new_phone, $new_price); //Assert $this->assertEquals($test_restaurant, $new_test_restaurant); }
function testDeleteCuisineRestaurants() { //Arrange $flavor = "Pizza"; $id = null; $test_cuisine = new Cuisine($flavor, $id); $test_cuisine->save(); $name = "Pizza Party"; $phone_number = "123-123-1234"; $address = "1234 Pepporoni Lane"; $cuisine_id = $test_cuisine->getId(); $test_restaurant = new Restaurant($name, $phone_number, $address, $id, $cuisine_id); $test_restaurant->save(); //Act $test_cuisine->delete(); //Assert $this->assertEquals([], Restaurant::getAll()); }
function test_DeleteCuisineRestaurantsReviews() { //Arrange //cuisine $name = "Japanese"; $id = null; $test_cuisine = new Cuisine($name, $id); $test_cuisine->save(); //restaurant $name = "Good Fortune"; $cuisine_id = $test_cuisine->getId(); $description = "very tasty."; $address = "1111 SW 11th Ave"; $test_restaurant = new Restaurant($name, $id, $cuisine_id, $description, $address); $test_restaurant->save(); //review $username = "******"; $date = 00 - 00 - 00; $rating = 5; $comment = "good one."; $restaurant_id = $test_restaurant->getId(); $test_review = new Review($username, $date, $rating, $comment, $restaurant_id, $id); //Act $test_cuisine->delete(); //Assert $this->assertEquals([], Review::getAll()); }
}); //clear database of all cuisines $app->post('/delete_cuisines', function () use($app) { Cuisine::deleteAll(); return $app['twig']->render('index.html.twig', array('cuisines' => Cuisine::getAll())); }); //creates new restaurants and displays them on the same page $app->post('/restaurants', function () use($app) { //takes the input values and builds a new restaurant and saves restaurant to database $restaurant_name = $_POST['restaurant_name']; $phone = $_POST['phone']; $address = $_POST['address']; $website = $_POST['website']; $cuisine_id = $_POST['cuisine_id']; $restaurant = new Restaurant($restaurant_name, $phone, $address, $website, $cuisine_id); $restaurant->save(); $cuisine = Cuisine::find($cuisine_id); return $app['twig']->render('cuisines.html.twig', array('cuisines' => $cuisine, 'restaurants' => $cuisine->getRestaurants())); }); //brings user to a page that allows a specific restaurant to be edited $app->get('/restaurant/{id}/edit', function ($id) use($app) { $restaurant = Restaurant::find($id); return $app['twig']->render('restaurant_edit.html.twig', array('restaurants' => $restaurant)); }); //posts edited data to the database to update a property in the existing restaurant $app->patch('/restaurant/{id}', function ($id) use($app) { $restaurant = Restaurant::find($id); $cuisine = Cuisine::find($_POST['cuisine_id']); foreach ($_POST as $key => $value) { if (!empty($value)) { $restaurant->update($key, $value);
function test_getRestaurants() { //arrange $name = "peanuts"; $test_allergen = new Allergen($name); $test_allergen->save(); $test_allergen_id = $test_allergen->getId(); $restaurant_name = "Taco Hell"; $test_restaurant = new Restaurant($restaurant_name, $test_allergen_id); $test_restaurant->save(); $restaurant_name2 = "Burger Queen"; $test_restaurant2 = new Restaurant($restaurant_name2, $test_allergen_id); $test_restaurant2->save(); //act $result = $test_allergen->getRestaurants(); //assert $this->assertEquals([$test_restaurant, $test_restaurant2], $result); }