Advertisement
Guest User

Untitled

a guest
Nov 10th, 2017
378
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.19 KB | None | 0 0
  1. <?php
  2.  
  3. namespace Tests\AppBundle\Controller;
  4.  
  5. use Louvre\BookingBundle\Entity\Booking;
  6. use Louvre\BookingBundle\Entity\Visitor;
  7. use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
  8. use Symfony\Component\HTTPFoundation\Response;
  9.  
  10.  
  11. class BookingControllerTest extends WebTestCase {
  12.  
  13. public function testHomepageIsUp()
  14. {
  15. $client = static::createClient();
  16. $crawler = $client->request('GET', '/');
  17.  
  18. $this->assertSame(200, $client->getResponse()->getStatusCode());
  19. }
  20.  
  21. public function testBookingIsUp()
  22. {
  23. $client = static::createClient();
  24. $client->request('GET', '/booking');
  25.  
  26. $this->assertSame(200, $client->getResponse()->getStatusCode());
  27. }
  28.  
  29. public function testCorrectBookingOneVisitor()
  30. {
  31. $dateObject = new \DateTime();
  32. $dateBooking = $dateObject->format('d-m-Y');
  33.  
  34. // Create client
  35. $client = static::createClient();
  36.  
  37. $crawler = $client->request('GET', '/booking');
  38.  
  39. // Select button and form
  40. $submitBookingButton = $crawler->selectButton('Réserver');
  41. $form = $submitBookingButton->form();
  42.  
  43. // Form values
  44. $bookingValues = array(
  45. 'louvre_bookingbundle_booking' => array(
  46. '_token' => $form['louvre_bookingbundle_booking[_token]']->getValue(),
  47. 'dateBooking' => $dateBooking,
  48. 'bookingType' => 1,
  49. 'visitorNumber' => 1,
  50. 'email' => 'gatienhrd@gmail.com',
  51. 'visitors' => array(
  52. 0 => array(
  53. 'name' => 'Dupont',
  54. 'firstName' => 'Michel',
  55. 'country' => 'France',
  56. 'birthDate' => array(
  57. 'month' => 1,
  58. 'day' => '24',
  59. 'year' => '1996'
  60. ),
  61. ),
  62. ),
  63. ),
  64. );
  65.  
  66. // Perform POST request
  67. $client->request($form->getMethod(), $form->getUri(), $bookingValues);
  68.  
  69. /*$this->assertTrue($client->getResponse()->isRedirect());*/
  70.  
  71. // Redirected to summary route
  72. $this->assertSame(302, $client->getResponse()->getStatusCode());
  73. // Find element in summary view
  74. $this->assertSame(1, $crawler->filter('div.go-booking')->count());
  75. }
  76.  
  77. public function testCorrectBookingSeveralVisitors()
  78. {
  79. $dateObject = new \DateTime();
  80. $dateBooking = $dateObject->format('d-m-Y');
  81.  
  82. // Create client
  83. $client = static::createClient();
  84.  
  85. $crawler = $client->request('GET', '/booking');
  86.  
  87. // Select button and form
  88. $submitBookingButton = $crawler->selectButton('Réserver');
  89. $form = $submitBookingButton->form();
  90.  
  91. // Form values
  92. $bookingValues = array(
  93. 'louvre_bookingbundle_booking' => array(
  94. '_token' => $form['louvre_bookingbundle_booking[_token]']->getValue(),
  95. 'dateBooking' => $dateBooking,
  96. 'bookingType' => 1,
  97. 'visitorNumber' => 3,
  98. 'email' => 'gatienhrd@gmail.com',
  99. 'visitors' => array(
  100. 0 => array(
  101. 'name' => 'Dupont',
  102. 'firstName' => 'Michel',
  103. 'country' => 'France',
  104. 'birthDate' => array(
  105. 'month' => 1,
  106. 'day' => '24',
  107. 'year' => '1996'
  108. ),
  109. ),
  110. 1 => array(
  111. 'name' => 'Dubois',
  112. 'firstName' => 'Georges',
  113. 'country' => 'France',
  114. 'birthDate' => array(
  115. 'month' => 1,
  116. 'day' => '24',
  117. 'year' => '1996'
  118. ),
  119. ),
  120. 2 => array(
  121. 'name' => 'Dumoulin',
  122. 'firstName' => 'Greg',
  123. 'country' => 'France',
  124. 'birthDate' => array(
  125. 'month' => 1,
  126. 'day' => '24',
  127. 'year' => '1996'
  128. ),
  129. ),
  130. ),
  131. ),
  132. );
  133.  
  134. // Perform POST request
  135. $client->request($form->getMethod(), $form->getUri(), $bookingValues);
  136.  
  137.  
  138. // Check redirection to summary route
  139. $this->assertSame(302, $client->getResponse()->getStatusCode());
  140. // Find element in summary view
  141. $this->assertSame(1, $crawler->filter('div.go-booking')->count());
  142. }
  143.  
  144. public function testIncorrectBookingEmptyFields()
  145. {
  146. $dateObject = new \DateTime();
  147. $dateBooking = $dateObject->format('d-m-Y');
  148.  
  149. // Create client
  150. $client = static::createClient();
  151.  
  152. $crawler = $client->request('GET', '/booking');
  153.  
  154. // Select button and form
  155. $submitBookingButton = $crawler->selectButton('Réserver');
  156. $form = $submitBookingButton->form();
  157.  
  158. // Form values
  159. $bookingValues = array(
  160. 'louvre_bookingbundle_booking' => array(
  161. '_token' => $form['louvre_bookingbundle_booking[_token]']->getValue(),
  162. 'dateBooking' => $dateBooking,
  163. 'bookingType' => 1,
  164. 'visitorNumber' => 1,
  165. 'email' => 'gatienhrd@gmail.com',
  166. 'visitors' => array(
  167. 0 => array(
  168. 'name' => '', // Empty field
  169. 'firstName' => '', // Empty field
  170. 'country' => 'France',
  171. 'birthDate' => array(
  172. 'month' => 1,
  173. 'day' => '24',
  174. 'year' => '1996'
  175. ),
  176. ),
  177. ),
  178. ),
  179. );
  180.  
  181. // Perform POST request
  182. $client->request($form->getMethod(), $form->getUri(), $bookingValues);
  183.  
  184. // Check that POST request failed, no redirection, status code = 200
  185. $this->assertSame(200, $client->getResponse()->getStatusCode());
  186. }
  187.  
  188. public function testIncorrectBookingPreviousDate()
  189. {
  190. // Create client
  191. $client = static::createClient();
  192.  
  193. $crawler = $client->request('GET', '/booking');
  194.  
  195. // Select button and form
  196. $submitBookingButton = $crawler->selectButton('Réserver');
  197. $form = $submitBookingButton->form();
  198.  
  199. // Form values
  200. $bookingValues = array(
  201. 'louvre_bookingbundle_booking' => array(
  202. '_token' => $form['louvre_bookingbundle_booking[_token]']->getValue(),
  203. 'dateBooking' => '01-10-2016',
  204. 'bookingType' => 1,
  205. 'visitorNumber' => 1,
  206. 'email' => 'gatienhrd@gmail.com',
  207. 'visitors' => array(
  208. 0 => array(
  209. 'name' => 'Dumoulin', // Empty field
  210. 'firstName' => 'Bob', // Empty field
  211. 'country' => 'France',
  212. 'birthDate' => array(
  213. 'month' => 1,
  214. 'day' => '24',
  215. 'year' => '1996'
  216. ),
  217. ),
  218. ),
  219. ),
  220. );
  221.  
  222. // Perform POST request
  223. $client->request($form->getMethod(), $form->getUri(), $bookingValues);
  224.  
  225. // Check that POST request failed, no redirection, status code = 200
  226. $this->assertSame(200, $client->getResponse()->getStatusCode());
  227. }
  228.  
  229. public function testIncorrectBookingUnknownEmail()
  230. {
  231. $dateObject = new \DateTime();
  232. $dateBooking = $dateObject->format('d-m-Y');
  233.  
  234. // Create client
  235. $client = static::createClient();
  236.  
  237. $crawler = $client->request('GET', '/booking');
  238.  
  239. // Select button and form
  240. $submitBookingButton = $crawler->selectButton('Réserver');
  241. $form = $submitBookingButton->form();
  242.  
  243. // Form values
  244. $bookingValues = array(
  245. 'louvre_bookingbundle_booking' => array(
  246. '_token' => $form['louvre_bookingbundle_booking[_token]']->getValue(),
  247. 'dateBooking' => $dateBooking,
  248. 'bookingType' => 1,
  249. 'visitorNumber' => 1,
  250. 'email' => 'gatienhrd@hfhfjhghg.com',
  251. 'visitors' => array(
  252. 0 => array(
  253. 'name' => 'Dupont', // Empty field
  254. 'firstName' => 'Michel', // Empty field
  255. 'country' => 'France',
  256. 'birthDate' => array(
  257. 'month' => 1,
  258. 'day' => '24',
  259. 'year' => '1996'
  260. ),
  261. ),
  262. ),
  263. ),
  264. );
  265.  
  266. // Perform POST request
  267. $client->request($form->getMethod(), $form->getUri(), $bookingValues);
  268.  
  269. // Check that POST request failed, no redirection, status code = 200
  270. $this->assertSame(200, $client->getResponse()->getStatusCode());
  271. }
  272.  
  273.  
  274. /*public function testBooking($formData,$status)
  275. {
  276. $client = static::createClient();
  277.  
  278. $parent = $client->getContainer()->get("doctrine.orm.entity_manager")->getRepository(Booking::class)->findOneByParent(null);
  279.  
  280. $booking = $client->getContainer()->get("doctrine.orm.entity_manager")->getRepository(Booking::class);
  281.  
  282.  
  283. $client->request('GET', $client->getContainer()->get("router")->generate("louvre_booking"));
  284. $this->assertEquals(Response::HTTP_OK, $client->getResponse()->getStatusCode());
  285.  
  286.  
  287. $client->request('POST', $client->getContainer()->get("router")->generate("louvre_booking"), $formData);
  288. $this->assertEquals($status, $client->getResponse()->getStatusCode());
  289.  
  290. echo $client->getResponse()->getContent();
  291.  
  292. }
  293.  
  294. public function dataTest()
  295. {
  296. return [
  297. [
  298. "formData" => [
  299. "booking" => [
  300. "dateBooking" => "01-0-2017",
  301. "bookingType" => 1,
  302. "visitorNumber" => 1,
  303. "email" => "gatienhrd@gmail.com",
  304. "visitors" => [
  305. [
  306. "name" => "Dupont",
  307. "firstName" => "Michel",
  308. "country" => "France",
  309. "birthDate" => "24-01-1996"
  310. ],
  311. ],
  312. ],
  313. ],
  314. "status" => Response::HTTP_OK
  315. ],
  316. ];
  317. }*/
  318.  
  319. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement