1 | <?php |
||
22 | class EventControllerTest extends Base |
||
23 | { |
||
24 | /** |
||
25 | * The setUpBeforeClass() and tearDownAfterClass() template methods are called before the first test of the test |
||
26 | * case class is run and after the last test of the test case class is run, respectively. |
||
27 | */ |
||
28 | public static function setUpBeforeClass() |
||
29 | { |
||
30 | static::resetDatabase(); |
||
31 | } |
||
32 | |||
33 | /** |
||
34 | * @test |
||
35 | * @group functional |
||
36 | */ |
||
37 | public function eventRegistration() |
||
38 | { |
||
39 | $email = '[email protected]'; |
||
40 | $client = static::createClient(); |
||
41 | $crawler = $client->request('GET', '/anmeldung'); |
||
42 | |||
43 | $form = $crawler->selectButton('event_register[save]')->form(); |
||
44 | $form['event_register[name]'] = 'John Doe'; |
||
45 | $form['event_register[email]'] = $email; |
||
46 | $form['event_register[days]'] = 3; |
||
47 | $form['event_register[donationEur]'] = '12,34'; |
||
48 | $form['event_register[payment]'] = 'paypal'; |
||
49 | $form['event_register[food]'] = 'default'; |
||
50 | $form['event_register[tags]'] = '#foo #bar #bcrm13'; |
||
51 | $form['event_register[twitter]'] = '@somebody'; |
||
52 | $form['event_register[participantList]'] = '1'; |
||
53 | $client->submit($form); |
||
|
|||
54 | $response = $client->getResponse(); |
||
55 | $this->assertEquals(302, $response->getStatusCode()); |
||
56 | $this->assertTrue($response->isRedirect('/anmeldung/check'), sprintf('Unexpected redirect to %s', $response->headers->get('Location'))); |
||
57 | |||
58 | $crawler = $client->followRedirect(); |
||
59 | $form = $crawler->selectButton('event_register_review[save]')->form(); |
||
60 | $form['event_register_review[norefund]'] = '1'; |
||
61 | $form['event_register_review[autocancel]'] = '1'; |
||
62 | $client->submit($form); |
||
63 | $response = $client->getResponse(); |
||
64 | $this->assertEquals(302, $response->getStatusCode()); |
||
65 | $this->assertTrue($response->isRedirect('/anmeldung/ok'), sprintf('Unexpected redirect to %s', $response->headers->get('Location'))); |
||
66 | return $email; |
||
67 | } |
||
68 | |||
69 | /** |
||
70 | * @test |
||
71 | * @group functional |
||
72 | * @depends eventRegistration |
||
73 | */ |
||
74 | public function createTickets($email) |
||
75 | { |
||
76 | $client = static::createClient(); |
||
77 | $container = $client->getContainer(); |
||
78 | |||
79 | $this->createTicketsCommand($container); |
||
80 | $this->sendTicketsCommand($container); // Tickets should not be sent, because not yet paid for |
||
81 | $this->sendPayTicketCommand($container); // but a payment notification should be sent |
||
82 | |||
83 | /* @var $em \Doctrine\Common\Persistence\ObjectManager */ |
||
84 | $em = $container |
||
85 | ->get('doctrine') |
||
86 | ->getManager(); |
||
87 | |||
88 | /* @var $tickets Ticket[] */ |
||
89 | $tickets = $em->getRepository('BCRMBackendBundle:Event\Ticket')->findAll(); |
||
90 | $this->assertEquals(2, count($tickets)); |
||
91 | $this->assertEquals($email, $tickets[0]->getEmail()); |
||
92 | $this->assertEquals($email, $tickets[1]->getEmail()); |
||
93 | $days = array( |
||
94 | $tickets[0]->getDay(), |
||
95 | $tickets[1]->getDay() |
||
96 | ); |
||
97 | $this->assertTrue(in_array(Ticket::DAY_SATURDAY, $days)); |
||
98 | $this->assertTrue(in_array(Ticket::DAY_SUNDAY, $days)); |
||
99 | $this->assertEquals(1, $tickets[0]->getEvent()->getId()); |
||
100 | $this->assertEquals(1, $tickets[1]->getEvent()->getId()); |
||
101 | $this->assertNull($tickets[0]->getPayment()); |
||
102 | $this->assertNull($tickets[1]->getPayment()); |
||
103 | $this->assertFalse($tickets[0]->isNotified()); |
||
104 | $this->assertFalse($tickets[1]->isNotified()); |
||
105 | |||
106 | /** @var Registration[] $registration */ |
||
107 | $registration = $em->getRepository('BCRMBackendBundle:Event\Registration')->findOneByEmail($email); |
||
108 | $this->assertTrue($registration->isPaymentNotified()); |
||
109 | |||
110 | return $email; |
||
111 | } |
||
112 | |||
113 | /** |
||
114 | * @test |
||
115 | * @group functional |
||
116 | * @depends createTickets |
||
117 | */ |
||
118 | public function payRegistration($email) |
||
119 | { |
||
120 | $client = static::createClient(); |
||
121 | $container = $client->getContainer(); |
||
122 | /* @var $em \Doctrine\Common\Persistence\ObjectManager */ |
||
123 | $em = $container |
||
124 | ->get('doctrine') |
||
125 | ->getManager(); |
||
126 | /** @var Registration $registration */ |
||
127 | $registration = $em->getRepository('BCRMBackendBundle:Event\Registration')->findOneByEmail($email); |
||
128 | $this->assertEquals('paypal', $registration->getPaymentMethod()); |
||
129 | $this->assertNull($registration->getPayment()); |
||
130 | |||
131 | $client = static::createClient(); |
||
132 | $client->request('GET', '/anmeldung/' . $registration->getUuid() . '/payment'); |
||
133 | $response = $client->getResponse(); |
||
134 | $this->assertEquals(200, $response->getStatusCode()); |
||
135 | preg_match('/data-number="([^"]+)"/', $response->getContent(), $registrationUuidMatch); |
||
136 | preg_match('/data-amount="([^"]+)"/', $response->getContent(), $registrationAmountMatch); |
||
137 | $this->assertEquals($registration->getUuid(), $registrationUuidMatch[1]); |
||
138 | $this->assertEquals(sprintf('%.2f', ceil((2000 + 1234) * 1.019 + 35) / 100), $registrationAmountMatch[1]); |
||
139 | |||
140 | // Add payment |
||
141 | $payment = new Payment(); |
||
142 | $payment->setMethod('cash'); |
||
143 | $payment->setTransactionId($email); |
||
144 | $em->persist($payment); |
||
145 | $em->flush(); |
||
146 | |||
147 | $command = new PayRegistrationCommand(); |
||
148 | $command->registration = $registration; |
||
149 | $command->payment = $payment; |
||
150 | /** @var \LiteCQRS\Bus\CommandBus $commandBus */ |
||
151 | $commandBus = $container->get('command_bus'); |
||
152 | $commandBus->handle($command); |
||
153 | $registration = $em->getRepository('BCRMBackendBundle:Event\Registration')->findOneByEmail($email); |
||
154 | $this->assertEquals($payment, $registration->getPayment()); |
||
155 | |||
156 | // Send tickets |
||
157 | $this->sendTicketsCommand($container); |
||
158 | |||
159 | /* @var $tickets Ticket[] */ |
||
160 | $tickets = $em->getRepository('BCRMBackendBundle:Event\Ticket')->findAll(); |
||
161 | $this->assertEquals(2, count($tickets)); |
||
162 | $this->assertEquals($payment, $tickets[0]->getPayment()); |
||
163 | $this->assertEquals($payment, $tickets[1]->getPayment()); |
||
164 | $this->assertTrue($tickets[0]->isNotified()); |
||
165 | $this->assertTrue($tickets[1]->isNotified()); |
||
166 | |||
167 | return $email; |
||
168 | } |
||
169 | |||
170 | protected function createTicketsCommand(ContainerInterface $container) |
||
174 | |||
175 | protected function sendTicketsCommand(ContainerInterface $container) |
||
176 | { |
||
177 | $this->runCommand($container, new SendTicketsMailCommand(), 'bcrm:tickets:send'); |
||
178 | } |
||
179 | |||
180 | protected function sendPayTicketCommand(ContainerInterface $container) |
||
181 | { |
||
182 | $this->runCommand($container, new SendPayRegistrationMailCommand(), 'bcrm:registration:pay'); |
||
183 | } |
||
184 | |||
185 | /** |
||
186 | * @test |
||
187 | * @group functional |
||
188 | * @depends payRegistration |
||
189 | */ |
||
190 | public function eventUnregistration($email) |
||
204 | |||
205 | /** |
||
206 | * @test |
||
207 | * @group functional |
||
208 | * @depends eventUnregistration |
||
209 | */ |
||
210 | public function confirmEventUnregistration($email) |
||
234 | |||
235 | protected function confirmUnregistrationCommand(ContainerInterface $container) |
||
239 | |||
240 | /** |
||
241 | * @test |
||
242 | * @group functional |
||
243 | * @depends confirmEventUnregistration |
||
244 | */ |
||
245 | public function removeTickets($email) |
||
246 | { |
||
247 | $client = static::createClient(); |
||
248 | $container = $client->getContainer(); |
||
249 | |||
250 | $this->processUnregistrationsCommand($container); |
||
251 | |||
252 | /* @var $em \Doctrine\Common\Persistence\ObjectManager */ |
||
253 | $em = $container |
||
254 | ->get('doctrine') |
||
255 | ->getManager(); |
||
256 | |||
257 | /* @var $registration Registration */ |
||
258 | $registration = $em->getRepository('BCRMBackendBundle:Event\Registration')->findOneById(2); |
||
259 | $this->assertEquals(0, $registration->getSaturday()); |
||
260 | $this->assertEquals(0, $registration->getSunday()); |
||
261 | |||
262 | /* @var $tickets Ticket[] */ |
||
263 | $tickets = $em->getRepository('BCRMBackendBundle:Event\Ticket')->findAll(); |
||
264 | $this->assertEquals(0, count($tickets)); |
||
265 | return $email; |
||
266 | } |
||
267 | |||
268 | protected function processUnregistrationsCommand(ContainerInterface $container) |
||
272 | |||
273 | /** |
||
274 | * @test |
||
275 | * @group functional |
||
276 | * @depends removeTickets |
||
277 | */ |
||
278 | public function thereShouldBeNoMoreTicketsThanCapacity() |
||
347 | |||
348 | /** |
||
349 | * @test |
||
350 | * @group functional |
||
351 | * @depends thereShouldBeNoMoreTicketsThanCapacity |
||
352 | */ |
||
353 | public function cancelTicketLink() |
||
375 | |||
376 | /** |
||
377 | * Test for https://github.com/BCRM/www/issues/1 |
||
378 | * |
||
379 | * @test |
||
380 | * @group functional |
||
381 | */ |
||
382 | public function tagsShouldAllowUmlauts() |
||
403 | } |
||
404 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: