示例#1
0
 public function allAcomByCity($city)
 {
     $am = new AccommodationModel();
     $accomm = null;
     $accommodations = [];
     try {
         $accomm = DB::table('accommodations')->where('province', $city)->orWhere('city', $city)->paginate(5);
         if (count($accomm) == 0) {
             return null;
         }
         foreach ($accomm as $ac) {
             $a = new Accommodation();
             $a->setID($ac->id);
             $a->setBaths($ac->bathrooms);
             $a->setBeds($ac->beds);
             $a->setCapacity($ac->capacity);
             $a->setCity($ac->city);
             $a->setDesc($ac->desc);
             $a->setInside($ac->inside);
             $a->setOutside($ac->outside);
             $a->setPhotos($am->allPhotos($ac->id));
             $a->setPrice($ac->price_per_person);
             $a->setProvince($ac->province);
             $a->setTitle($ac->title);
             $a->setInitialDesc($ac->desc);
             $accommodations[] = $a;
         }
     } catch (QueryException $ex) {
         return null;
     }
     return $accommodations;
 }
 /**
  * A basic functional test example.
  *
  * @return void
  * @group accomm
  */
 public function testAccommodation()
 {
     $accomm = new Accommodation();
     $p1 = new Photo();
     $p2 = new Photo();
     $arrayPhoto = [];
     $arrayPhoto2 = [];
     $p1->setUrl('url/photo1');
     $p1->setMain(0);
     $p2->setUrl('url/photo2');
     $p2->setMain(1);
     $arrayPhoto[] = $p1;
     $arrayPhoto[] = $p2;
     $arrayPhoto2[] = $p1;
     $arrayPhoto2[] = $p2;
     $this->assertEquals('El propietario aún no ha detallado nada sobre las características interiores del alojamiento.', $accomm->getInside());
     $this->assertEquals('El propietario aún no ha detallado nada sobre las características exteriores del alojamiento.', $accomm->getOutside());
     $accomm->setBaths(2);
     $accomm->setBeds(3);
     $accomm->setCapacity(5);
     $accomm->setCity('Elche');
     $accomm->setDesc('Alojamiento de lujo.');
     $accomm->setInside('Descripción del interior del alojamiento.');
     $accomm->setOutside('Descripción del exterior del alojamiento.');
     $accomm->setPhotos($arrayPhoto);
     $accomm->setPrice(50);
     $accomm->setProvince('Alicante');
     $accomm->setTitle('Casa rural');
     $this->assertEquals(2, $accomm->getBaths());
     $this->assertEquals(3, $accomm->getBeds());
     $this->assertEquals(5, $accomm->getCapacity());
     $this->assertEquals('Elche', $accomm->getCity());
     $this->assertEquals('Alojamiento de lujo.', $accomm->getDesc());
     $this->assertEquals('Descripción del interior del alojamiento.', $accomm->getInside());
     $this->assertEquals('Descripción del exterior del alojamiento.', $accomm->getOutside());
     $this->assertEquals(50, $accomm->getPrice());
     $this->assertEquals('Alicante', $accomm->getProvince());
     $this->assertEquals('Casa rural', $accomm->getTitle());
     $this->assertEquals($arrayPhoto2, $accomm->getPhotos());
 }
 /**
  * Escenario: Buscar los alojamientos de una ciudad que sí tiene resultados desde página de búsqueda
  * Dado que soy un usuario del sistema y pretendo buscar los alojamientos de una determinada ciudad desde la página de búsqueda
  * Si escribo dicha ciudad en el buscador y sí se encuentran resultados
  * El sistema deberá redireccionar a la dirección 'search/accommodations/City/page/1'
  * Y mostrar los alojamientos disponibles
  *
  * @return void
  * @group searchAcceptance
  * @test
  */
 public function try_search()
 {
     $am = new AccommodationModel();
     $a1 = new Accommodation();
     $p1 = new Photo();
     $p2 = new Photo();
     $owner = new Owner();
     $um = new UserModel();
     $arrayPhoto = [];
     $owner->setName("Norman");
     $owner->setEmail("*****@*****.**");
     $owner->setSurname("Coloma");
     $owner->setPhone("654987321");
     $owner->setPassword("prueba");
     $um->createUser($owner);
     $p1->setUrl('url/photo1');
     $p1->setMain(1);
     $p2->setUrl('url/photo2');
     $p2->setMain(0);
     $arrayPhoto[] = $p1;
     $arrayPhoto[] = $p2;
     $a1->setBaths(2);
     $a1->setBeds(3);
     $a1->setCapacity(5);
     $a1->setCity('Madrid');
     $a1->setDesc('Alojamiento de lujo.');
     $a1->setInside('Descripción del interior del alojamiento.');
     $a1->setOutside('Descripción del exterior del alojamiento.');
     $a1->setPhotos($arrayPhoto);
     $a1->setPrice(50);
     $a1->setProvince('Madrid');
     $a1->setTitle('Casa rural');
     $am->createAccom($a1, $um->getID($owner->getEmail()));
     $this->visit('/')->see('Destacados')->type('Elche', 'city')->press('BUSCAR')->seePageIs('search/accommodations/Elche/page/1')->see('No hay resultados para la búsqueda introducida!')->type('Madrid', 'city')->press('Buscar')->seePageIs('/search/accommodations/Madrid/page/1')->see('Madrid');
 }
 /**
  * Recuperamos los alojamientos que tiene un owner de la base de datos
  *
  * @return void
  * @group getAccommByOwner
  */
 public function testGetAccommByOwnerID()
 {
     $am = new AccommodationModel();
     $a1 = new Accommodation();
     $a2 = new Accommodation();
     $p1 = new Photo();
     $p2 = new Photo();
     $p3 = new Photo();
     $p4 = new Photo();
     $owner = new Owner();
     $um = new UserModel();
     $arrayPhoto = [];
     $arrayPhoto2 = [];
     $owner->setName("Norman");
     $owner->setEmail("*****@*****.**");
     $owner->setSurname("Coloma");
     $owner->setPhone("654987321");
     $owner->setPassword("prueba");
     $um->createUser($owner);
     $p1->setUrl('url/photo1');
     $p1->setMain(1);
     $p2->setUrl('url/photo2');
     $p2->setMain(0);
     $p3->setUrl('url/photo3');
     $p3->setMain(1);
     $p4->setUrl('url/photo4');
     $p4->setMain(0);
     $arrayPhoto[] = $p1;
     $arrayPhoto[] = $p2;
     $arrayPhoto2[] = $p3;
     $arrayPhoto2[] = $p4;
     $a1->setBaths(2);
     $a1->setBeds(3);
     $a1->setCapacity(5);
     $a1->setCity('Elche');
     $a1->setDesc('Alojamiento de lujo.');
     $a1->setInside('Descripción del interior del alojamiento.');
     $a1->setOutside('Descripción del exterior del alojamiento.');
     $a1->setPhotos($arrayPhoto);
     $a1->setPrice(number_format((double) 50, 2, '.', ''));
     $a1->setProvince('Alicante');
     $a1->setTitle('Casa rural');
     $a1->setInitialDesc($a1->getDesc());
     $a2->setBaths(1);
     $a2->setBeds(2);
     $a2->setCapacity(3);
     $a2->setCity('Murcia');
     $a2->setDesc('Alojamiento de calidad media.');
     $a2->setInside('Descripción del interior del alojamiento.');
     $a2->setOutside('Descripción del exterior del alojamiento.');
     $a2->setPhotos($arrayPhoto2);
     $a2->setPrice(number_format((double) 20, 2, '.', ''));
     $a2->setProvince('Murcia');
     $a2->setTitle('Casa en la ciudad');
     $a2->setInitialDesc($a2->getDesc());
     $prueba1 = $am->createAccom($a1, $um->getID($owner->getEmail()));
     $prueba2 = $am->createAccom($a2, $um->getID($owner->getEmail()));
     $a1->setID($prueba1['id']);
     $a2->setID($prueba2['id']);
     $resultado = [];
     $resultado[] = $a1;
     $resultado[] = $a2;
     $this->assertEquals($resultado, $am->accommodationByOwner($um->getID($owner->getEmail())));
 }
 /**
  * Recuperamos los alojamientos de una determinada ciudad de la BD
  *
  * @return void
  * @group getAccomByCity
  */
 public function testgetAllAccommByCity()
 {
     $this->notSeeInDatabase('accommodations', ['title' => 'Casa rural']);
     $am = new AccommodationModel();
     $a1 = new Accommodation();
     $a2 = new Accommodation();
     $p1 = new Photo();
     $p3 = new Photo();
     $p2 = new Photo();
     $p4 = new Photo();
     $owner = new Owner();
     $owner2 = new Owner();
     $um = new UserModel();
     $sm = new \App\Models\SystemModel();
     $arrayPhoto = [];
     $arrayPhoto2 = [];
     $arrayAcomm = [];
     $owner->setName("Norman");
     $owner->setEmail("*****@*****.**");
     $owner->setSurname("Coloma");
     $owner->setPhone("654987321");
     $owner->setPassword("prueba");
     $owner2->setName("Norman");
     $owner2->setEmail("*****@*****.**");
     $owner2->setSurname("Coloma");
     $owner2->setPhone("654987321");
     $owner2->setPassword("prueba");
     $um->createUser($owner);
     $um->createUser($owner2);
     $p1->setUrl('url/photo1');
     $p1->setMain(1);
     $p2->setUrl('url/photo2');
     $p2->setMain(0);
     $p3->setUrl('url/photo3');
     $p3->setMain(1);
     $p4->setUrl('url/photo4');
     $p4->setMain(0);
     $arrayPhoto[] = $p1;
     $arrayPhoto[] = $p2;
     $arrayPhoto2[] = $p3;
     $arrayPhoto2[] = $p4;
     $a1->setBaths(2);
     $a1->setBeds(3);
     $a1->setCapacity(5);
     $a1->setCity('Elche');
     $a1->setDesc('Alojamiento de lujo.');
     $a1->setInside('Descripción del interior del alojamiento.');
     $a1->setOutside('Descripción del exterior del alojamiento.');
     $a1->setPhotos($arrayPhoto);
     $a1->setPrice(number_format((double) 50, 2, '.', ''));
     $a1->setProvince('Alicante');
     $a1->setTitle('Casa rural');
     $a1->setInitialDesc($a1->getDesc());
     $a2->setBaths(4);
     $a2->setBeds(5);
     $a2->setCapacity(20);
     $a2->setCity('Elche');
     $a2->setDesc('Alojamiento de caca.');
     $a2->setInside('Descripción del interior del alojamiento2.');
     $a2->setOutside('Descripción del exterior del alojamiento2.');
     $a2->setPhotos($arrayPhoto2);
     $a2->setPrice(number_format((double) 150, 2, '.', ''));
     $a2->setProvince('Alicante');
     $a2->setTitle('Casa rural2');
     $a2->setInitialDesc($a2->getDesc());
     $accom = $am->createAccom($a1, $um->getID($owner->getEmail()));
     $accom2 = $am->createAccom($a2, $um->getID($owner2->getEmail()));
     $a1->setID($accom['id']);
     $a2->setID($accom2['id']);
     $arrayAcomm[] = $a1;
     $arrayAcomm[] = $a2;
     $this->SeeInDatabase('accommodations', ['title' => 'Casa rural']);
     $this->SeeInDatabase('photos', ['url' => 'url/photo1']);
     $this->SeeInDatabase('photos', ['url' => 'url/photo2']);
     $this->SeeInDatabase('accommodations', ['title' => 'Casa rural2']);
     $this->SeeInDatabase('photos', ['url' => 'url/photo3']);
     $this->SeeInDatabase('photos', ['url' => 'url/photo4']);
     //Testeamos el método allAccomByCity
     $this->assertEquals($arrayAcomm, $sm->allAcomByCity("Elche"));
 }
 /**
  * Recibimos por parámetro los datos para insertar un nuevo alojamiento.
  *
  * @param  Request  $request
  * @return Response
  */
 public function addAccommodation(Request $request)
 {
     $am = new AccommodationModel();
     $accom = new Accommodation();
     $file = null;
     $files = null;
     $photos = [];
     $size = 0;
     if ($request->hasFile('new-accom-main-img')) {
         $file = $request->file('new-accom-main-img');
         $photo = new Photo();
         $photo->setUrl($file->getClientOriginalName());
         $photo->setMain(true);
         $photos[] = $photo;
         if ($request->hasFile('galery')) {
             $files = $request->file('galery');
             foreach ($files as $f) {
                 $size = $size + $f->getClientSize();
                 $photo = new Photo();
                 $photo->setUrl($f->getClientOriginalName());
                 $photo->setMain(false);
                 $photos[] = $photo;
             }
         }
     }
     if ($size > 30720000) {
         return redirect('/manage/owner#newAccom')->withErrors(['galery' => 'La galería no puede pesar más de 30mb'])->withInput();
     } else {
         $validator = Validator::make($request->all(), ['new-accom-title' => 'required|regex:/^[A-Z]+[a-zA-ZÁÉÍÓÚáéíóuñÑ\\s\']+$/', 'new-accom-city' => 'required|regex:/^[A-Z]+[a-zA-ZÁÉÍÓÚáéíóuñÑ\\s\']+$/', 'new-accom-desc' => 'required', 'new-accom-price' => 'required|numeric', 'new-accom-main-img' => 'required|image|mimes:jpeg,jpg,bmp,png,gif|max:5120'], $this->messages);
         if ($validator->fails()) {
             return redirect('/manage/owner#newAccom')->withErrors($validator)->withInput();
         } else {
             $accom->setTitle($request->input('new-accom-title'));
             $accom->setCity($request->input('new-accom-city'));
             $accom->setProvince($request->input('new-accom-province'));
             $accom->setBaths($request->input('new-accom-baths'));
             $accom->setBeds($request->input('new-accom-beds'));
             $accom->setCapacity($request->input('new-accom-capacity'));
             $accom->setPrice($request->input('new-accom-price'));
             if ($request->has('new-accom-inside')) {
                 $accom->setInside($request->input('new-accom-inside'));
             }
             if ($request->has('new-accom-outside')) {
                 $accom->setOutside($request->input('new-accom-outside'));
             }
             $accom->setDesc($request->input('new-accom-desc'));
             $accom->setPhotos($photos);
             echo "good";
             try {
                 $am->createAccom($accom, Auth::user()->id);
                 if ($this->uploadPhoto($file)) {
                     if ($files != null) {
                         foreach ($files as $file) {
                             $this->uploadPhoto($file);
                         }
                     }
                 }
                 flash()->overlay('Tu alojamiento se ha anunciado correctamente. Puedes comprobarlo desde tu panel de control.', 'Publicado');
                 return redirect("/manage/owner");
             } catch (QueryException $ex) {
                 echo $ex;
             }
         }
     }
 }
 public function accommodationByOwner($owner_id)
 {
     $accomm = null;
     $accommodations = [];
     try {
         $accomm = AccommodationModel::all()->where('user_id', $owner_id);
         if ($accomm->count() == 0) {
             return null;
         }
         foreach ($accomm as $ac) {
             $a = new Accommodation();
             $a->setID($ac->id);
             $a->setBaths($ac->bathrooms);
             $a->setBeds($ac->beds);
             $a->setCapacity($ac->capacity);
             $a->setCity($ac->city);
             $a->setDesc($ac->desc);
             $a->setInside($ac->inside);
             $a->setOutside($ac->outside);
             $a->setPhotos($this->allPhotos($ac->id));
             $a->setPrice($ac->price_per_person);
             $a->setProvince($ac->province);
             $a->setTitle($ac->title);
             $a->setInitialDesc($ac->desc);
             $accommodations[] = $a;
         }
     } catch (QueryException $ex) {
         return null;
     }
     return $accommodations;
 }