Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Tests\AppBundle\Controller;
- use Louvre\BookingBundle\Entity\Booking;
- use Louvre\BookingBundle\Entity\Visitor;
- use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
- use Symfony\Component\HTTPFoundation\Response;
- class BookingControllerTest extends WebTestCase {
- public function testHomepageIsUp()
- {
- $client = static::createClient();
- $crawler = $client->request('GET', '/');
- $this->assertSame(200, $client->getResponse()->getStatusCode());
- }
- public function testBookingIsUp()
- {
- $client = static::createClient();
- $client->request('GET', '/booking');
- $this->assertSame(200, $client->getResponse()->getStatusCode());
- }
- public function testCorrectBookingOneVisitor()
- {
- $dateObject = new \DateTime();
- $dateBooking = $dateObject->format('d-m-Y');
- // Create client
- $client = static::createClient();
- $crawler = $client->request('GET', '/booking');
- // Select button and form
- $submitBookingButton = $crawler->selectButton('Réserver');
- $form = $submitBookingButton->form();
- // Form values
- $bookingValues = array(
- 'louvre_bookingbundle_booking' => array(
- '_token' => $form['louvre_bookingbundle_booking[_token]']->getValue(),
- 'dateBooking' => $dateBooking,
- 'bookingType' => 1,
- 'visitorNumber' => 1,
- 'email' => 'gatienhrd@gmail.com',
- 'visitors' => array(
- 0 => array(
- 'name' => 'Dupont',
- 'firstName' => 'Michel',
- 'country' => 'France',
- 'birthDate' => array(
- 'month' => 1,
- 'day' => '24',
- 'year' => '1996'
- ),
- ),
- ),
- ),
- );
- // Perform POST request
- $client->request($form->getMethod(), $form->getUri(), $bookingValues);
- /*$this->assertTrue($client->getResponse()->isRedirect());*/
- // Redirected to summary route
- $this->assertSame(302, $client->getResponse()->getStatusCode());
- // Find element in summary view
- $this->assertSame(1, $crawler->filter('div.go-booking')->count());
- }
- public function testCorrectBookingSeveralVisitors()
- {
- $dateObject = new \DateTime();
- $dateBooking = $dateObject->format('d-m-Y');
- // Create client
- $client = static::createClient();
- $crawler = $client->request('GET', '/booking');
- // Select button and form
- $submitBookingButton = $crawler->selectButton('Réserver');
- $form = $submitBookingButton->form();
- // Form values
- $bookingValues = array(
- 'louvre_bookingbundle_booking' => array(
- '_token' => $form['louvre_bookingbundle_booking[_token]']->getValue(),
- 'dateBooking' => $dateBooking,
- 'bookingType' => 1,
- 'visitorNumber' => 3,
- 'email' => 'gatienhrd@gmail.com',
- 'visitors' => array(
- 0 => array(
- 'name' => 'Dupont',
- 'firstName' => 'Michel',
- 'country' => 'France',
- 'birthDate' => array(
- 'month' => 1,
- 'day' => '24',
- 'year' => '1996'
- ),
- ),
- 1 => array(
- 'name' => 'Dubois',
- 'firstName' => 'Georges',
- 'country' => 'France',
- 'birthDate' => array(
- 'month' => 1,
- 'day' => '24',
- 'year' => '1996'
- ),
- ),
- 2 => array(
- 'name' => 'Dumoulin',
- 'firstName' => 'Greg',
- 'country' => 'France',
- 'birthDate' => array(
- 'month' => 1,
- 'day' => '24',
- 'year' => '1996'
- ),
- ),
- ),
- ),
- );
- // Perform POST request
- $client->request($form->getMethod(), $form->getUri(), $bookingValues);
- // Check redirection to summary route
- $this->assertSame(302, $client->getResponse()->getStatusCode());
- // Find element in summary view
- $this->assertSame(1, $crawler->filter('div.go-booking')->count());
- }
- public function testIncorrectBookingEmptyFields()
- {
- $dateObject = new \DateTime();
- $dateBooking = $dateObject->format('d-m-Y');
- // Create client
- $client = static::createClient();
- $crawler = $client->request('GET', '/booking');
- // Select button and form
- $submitBookingButton = $crawler->selectButton('Réserver');
- $form = $submitBookingButton->form();
- // Form values
- $bookingValues = array(
- 'louvre_bookingbundle_booking' => array(
- '_token' => $form['louvre_bookingbundle_booking[_token]']->getValue(),
- 'dateBooking' => $dateBooking,
- 'bookingType' => 1,
- 'visitorNumber' => 1,
- 'email' => 'gatienhrd@gmail.com',
- 'visitors' => array(
- 0 => array(
- 'name' => '', // Empty field
- 'firstName' => '', // Empty field
- 'country' => 'France',
- 'birthDate' => array(
- 'month' => 1,
- 'day' => '24',
- 'year' => '1996'
- ),
- ),
- ),
- ),
- );
- // Perform POST request
- $client->request($form->getMethod(), $form->getUri(), $bookingValues);
- // Check that POST request failed, no redirection, status code = 200
- $this->assertSame(200, $client->getResponse()->getStatusCode());
- }
- public function testIncorrectBookingPreviousDate()
- {
- // Create client
- $client = static::createClient();
- $crawler = $client->request('GET', '/booking');
- // Select button and form
- $submitBookingButton = $crawler->selectButton('Réserver');
- $form = $submitBookingButton->form();
- // Form values
- $bookingValues = array(
- 'louvre_bookingbundle_booking' => array(
- '_token' => $form['louvre_bookingbundle_booking[_token]']->getValue(),
- 'dateBooking' => '01-10-2016',
- 'bookingType' => 1,
- 'visitorNumber' => 1,
- 'email' => 'gatienhrd@gmail.com',
- 'visitors' => array(
- 0 => array(
- 'name' => 'Dumoulin', // Empty field
- 'firstName' => 'Bob', // Empty field
- 'country' => 'France',
- 'birthDate' => array(
- 'month' => 1,
- 'day' => '24',
- 'year' => '1996'
- ),
- ),
- ),
- ),
- );
- // Perform POST request
- $client->request($form->getMethod(), $form->getUri(), $bookingValues);
- // Check that POST request failed, no redirection, status code = 200
- $this->assertSame(200, $client->getResponse()->getStatusCode());
- }
- public function testIncorrectBookingUnknownEmail()
- {
- $dateObject = new \DateTime();
- $dateBooking = $dateObject->format('d-m-Y');
- // Create client
- $client = static::createClient();
- $crawler = $client->request('GET', '/booking');
- // Select button and form
- $submitBookingButton = $crawler->selectButton('Réserver');
- $form = $submitBookingButton->form();
- // Form values
- $bookingValues = array(
- 'louvre_bookingbundle_booking' => array(
- '_token' => $form['louvre_bookingbundle_booking[_token]']->getValue(),
- 'dateBooking' => $dateBooking,
- 'bookingType' => 1,
- 'visitorNumber' => 1,
- 'email' => 'gatienhrd@hfhfjhghg.com',
- 'visitors' => array(
- 0 => array(
- 'name' => 'Dupont', // Empty field
- 'firstName' => 'Michel', // Empty field
- 'country' => 'France',
- 'birthDate' => array(
- 'month' => 1,
- 'day' => '24',
- 'year' => '1996'
- ),
- ),
- ),
- ),
- );
- // Perform POST request
- $client->request($form->getMethod(), $form->getUri(), $bookingValues);
- // Check that POST request failed, no redirection, status code = 200
- $this->assertSame(200, $client->getResponse()->getStatusCode());
- }
- /*public function testBooking($formData,$status)
- {
- $client = static::createClient();
- $parent = $client->getContainer()->get("doctrine.orm.entity_manager")->getRepository(Booking::class)->findOneByParent(null);
- $booking = $client->getContainer()->get("doctrine.orm.entity_manager")->getRepository(Booking::class);
- $client->request('GET', $client->getContainer()->get("router")->generate("louvre_booking"));
- $this->assertEquals(Response::HTTP_OK, $client->getResponse()->getStatusCode());
- $client->request('POST', $client->getContainer()->get("router")->generate("louvre_booking"), $formData);
- $this->assertEquals($status, $client->getResponse()->getStatusCode());
- echo $client->getResponse()->getContent();
- }
- public function dataTest()
- {
- return [
- [
- "formData" => [
- "booking" => [
- "dateBooking" => "01-0-2017",
- "bookingType" => 1,
- "visitorNumber" => 1,
- "email" => "gatienhrd@gmail.com",
- "visitors" => [
- [
- "name" => "Dupont",
- "firstName" => "Michel",
- "country" => "France",
- "birthDate" => "24-01-1996"
- ],
- ],
- ],
- ],
- "status" => Response::HTTP_OK
- ],
- ];
- }*/
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement