1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @author Markus Tacker <[email protected]> |
5
|
|
|
* @copyright 2013-2016 Verein zur Förderung der Netzkultur im Rhein-Main-Gebiet e.V. | http://netzkultur-rheinmain.de/ |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace BCRM\WebBundle\Tests\Functional; |
9
|
|
|
|
10
|
|
|
use BCRM\BackendBundle\Command\SendPayRegistrationMailCommand; |
11
|
|
|
use BCRM\BackendBundle\Command\SendTicketsMailCommand; |
12
|
|
|
use BCRM\BackendBundle\Entity\Event\Ticket; |
13
|
|
|
use BCRM\BackendBundle\Entity\Event\Registration; |
14
|
|
|
use BCRM\BackendBundle\Entity\Event\Unregistration; |
15
|
|
|
use BCRM\BackendBundle\Command\SendConfirmUnregistrationMailCommand; |
16
|
|
|
use BCRM\BackendBundle\Command\CreateTicketsCommand; |
17
|
|
|
use BCRM\BackendBundle\Command\ProcessUnregistrationsCommand; |
18
|
|
|
use BCRM\BackendBundle\Entity\Payment; |
19
|
|
|
use BCRM\BackendBundle\Service\Payment\PayRegistrationCommand; |
20
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
21
|
|
|
|
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) |
171
|
|
|
{ |
172
|
|
|
$this->runCommand($container, new CreateTicketsCommand(), 'bcrm:tickets:create'); |
173
|
|
|
} |
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) |
191
|
|
|
{ |
192
|
|
|
$client = static::createClient(); |
193
|
|
|
$crawler = $client->request('GET', '/stornierung'); |
194
|
|
|
|
195
|
|
|
$form = $crawler->selectButton('event_unregister[save]')->form(); |
196
|
|
|
$form['event_unregister[email]'] = $email; |
197
|
|
|
$form['event_unregister[days]'] = 3; |
198
|
|
|
$client->submit($form); |
|
|
|
|
199
|
|
|
$response = $client->getResponse(); |
200
|
|
|
$this->assertEquals(302, $response->getStatusCode()); |
201
|
|
|
$this->assertTrue($response->isRedirect('/stornierung/ok'), sprintf('Unexpected redirect to %s', $response->headers->get('Location'))); |
202
|
|
|
return $email; |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
/** |
206
|
|
|
* @test |
207
|
|
|
* @group functional |
208
|
|
|
* @depends eventUnregistration |
209
|
|
|
*/ |
210
|
|
|
public function confirmEventUnregistration($email) |
211
|
|
|
{ |
212
|
|
|
$client = static::createClient(); |
213
|
|
|
$container = $client->getContainer(); |
214
|
|
|
|
215
|
|
|
$this->confirmUnregistrationCommand($container); |
|
|
|
|
216
|
|
|
|
217
|
|
|
/* @var $em \Doctrine\Common\Persistence\ObjectManager */ |
218
|
|
|
$em = $container |
219
|
|
|
->get('doctrine') |
220
|
|
|
->getManager(); |
221
|
|
|
|
222
|
|
|
/* @var $registration Registration */ |
223
|
|
|
$registration = $em->getRepository('BCRMBackendBundle:Event\Unregistration')->findOneBy(array( |
224
|
|
|
'email' => $email |
225
|
|
|
)); |
226
|
|
|
|
227
|
|
|
// Confirm |
228
|
|
|
$client->request('GET', sprintf('/stornierung/bestaetigen/%d/%s', $registration->getId(), $registration->getConfirmationKey())); |
|
|
|
|
229
|
|
|
$response = $client->getResponse(); |
230
|
|
|
$this->assertEquals(302, $response->getStatusCode()); |
231
|
|
|
$this->assertTrue($response->isRedirect('/stornierung/aktiviert'), sprintf('Unexpected redirect to %s', $response->headers->get('Location'))); |
232
|
|
|
return $email; |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
protected function confirmUnregistrationCommand(ContainerInterface $container) |
236
|
|
|
{ |
237
|
|
|
$this->runCommand($container, new SendConfirmUnregistrationMailCommand(), 'bcrm:unregistration:confirm'); |
238
|
|
|
} |
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) |
269
|
|
|
{ |
270
|
|
|
$this->runCommand($container, new ProcessUnregistrationsCommand(), 'bcrm:tickets:process-unregistrations'); |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
/** |
274
|
|
|
* @test |
275
|
|
|
* @group functional |
276
|
|
|
* @depends removeTickets |
277
|
|
|
*/ |
278
|
|
|
public function thereShouldBeNoMoreTicketsThanCapacity() |
279
|
|
|
{ |
280
|
|
|
$client = static::createClient(); |
281
|
|
|
$container = $client->getContainer(); |
282
|
|
|
/* @var $em \Doctrine\Common\Persistence\ObjectManager */ |
283
|
|
|
$em = $container |
284
|
|
|
->get('doctrine') |
285
|
|
|
->getManager(); |
286
|
|
|
|
287
|
|
|
$this->assertEquals(0, count($em->getRepository('BCRMBackendBundle:Event\Ticket')->findAll())); |
288
|
|
|
|
289
|
|
|
$event = $em->getRepository('BCRMBackendBundle:Event\Event')->findAll()[0]; |
290
|
|
|
|
291
|
|
|
// Create registrations |
292
|
|
|
for ($i = 1; $i <= 5; $i++) { |
293
|
|
|
$email = 'john.doe.198' . $i . '@domain.com'; |
294
|
|
|
$registration = new Registration(); |
295
|
|
|
$registration->setName($i); |
296
|
|
|
$registration->setEvent($event); |
297
|
|
|
$registration->setEmail($email); |
298
|
|
|
$registration->setSaturday(true); |
299
|
|
|
$registration->setUuid($email); |
300
|
|
|
$payment = new Payment(); |
301
|
|
|
$payment->setMethod('cash'); |
302
|
|
|
$payment->setTransactionId($email); |
303
|
|
|
$em->persist($payment); |
304
|
|
|
$registration->setPayment($payment); |
305
|
|
|
$em->persist($registration); |
306
|
|
|
} |
307
|
|
|
$em->flush(); |
308
|
|
|
|
309
|
|
|
$this->createTicketsCommand($container); |
|
|
|
|
310
|
|
|
|
311
|
|
|
$tickets = $em->getRepository('BCRMBackendBundle:Event\Ticket')->findBy(array( |
312
|
|
|
'event' => $event, |
313
|
|
|
'day' => Ticket::DAY_SATURDAY, |
314
|
|
|
)); |
315
|
|
|
$this->assertEquals(3, count($tickets)); |
316
|
|
|
$this->assertInArray('[email protected]', array_map(function (Ticket $t) { |
317
|
|
|
return $t->getEmail(); |
318
|
|
|
}, $tickets)); |
319
|
|
|
|
320
|
|
|
// Unregister Tickets |
321
|
|
|
$unregistration = new Unregistration(); |
322
|
|
|
$unregistration->setEvent($event); |
323
|
|
|
$unregistration->setEmail('[email protected]'); |
324
|
|
|
$unregistration->setConfirmed(true); |
325
|
|
|
$unregistration->setSaturday(true); |
326
|
|
|
$em->persist($unregistration); |
327
|
|
|
$em->flush(); |
328
|
|
|
|
329
|
|
|
$this->processUnregistrationsCommand($container); |
|
|
|
|
330
|
|
|
|
331
|
|
|
$this->assertEquals(2, count($em->getRepository('BCRMBackendBundle:Event\Ticket')->findBy(array( |
332
|
|
|
'event' => $event, |
333
|
|
|
'day' => Ticket::DAY_SATURDAY, |
334
|
|
|
)))); |
335
|
|
|
|
336
|
|
|
$this->createTicketsCommand($container); |
|
|
|
|
337
|
|
|
|
338
|
|
|
$tickets = $em->getRepository('BCRMBackendBundle:Event\Ticket')->findBy(array( |
339
|
|
|
'event' => $event, |
340
|
|
|
'day' => Ticket::DAY_SATURDAY, |
341
|
|
|
)); |
342
|
|
|
$this->assertEquals(3, count($tickets)); |
343
|
|
|
$this->assertNotInArray('[email protected]', array_map(function (Ticket $t) { |
344
|
|
|
return $t->getEmail(); |
345
|
|
|
}, $tickets)); |
346
|
|
|
} |
347
|
|
|
|
348
|
|
|
/** |
349
|
|
|
* @test |
350
|
|
|
* @group functional |
351
|
|
|
* @depends thereShouldBeNoMoreTicketsThanCapacity |
352
|
|
|
*/ |
353
|
|
|
public function cancelTicketLink() |
354
|
|
|
{ |
355
|
|
|
$client = static::createClient(); |
356
|
|
|
$container = $client->getContainer(); |
357
|
|
|
/* @var $em \Doctrine\Common\Persistence\ObjectManager */ |
358
|
|
|
$em = $container |
359
|
|
|
->get('doctrine') |
360
|
|
|
->getManager(); |
361
|
|
|
$ticket = $em->getRepository('BCRMBackendBundle:Event\Ticket')->findOneBy(array('day' => 1)); |
362
|
|
|
|
363
|
|
|
// Confirm |
364
|
|
|
$crawler = $client->request('GET', sprintf('/stornierung/%d/%s', $ticket->getId(), $ticket->getCode())); |
365
|
|
|
$form = $crawler->selectButton('cancel_confirm')->form(); |
366
|
|
|
$client->submit($form); |
367
|
|
|
$response = $client->getResponse(); |
368
|
|
|
$this->assertEquals(302, $response->getStatusCode()); |
369
|
|
|
$this->assertTrue($response->isRedirect('/stornierung/aktiviert'), sprintf('Unexpected redirect to %s', $response->headers->get('Location'))); |
370
|
|
|
|
371
|
|
|
$this->processUnregistrationsCommand($container); |
|
|
|
|
372
|
|
|
|
373
|
|
|
$this->assertEquals(2, count($em->getRepository('BCRMBackendBundle:Event\Ticket')->findAll())); |
374
|
|
|
} |
375
|
|
|
|
376
|
|
|
/** |
377
|
|
|
* Test for https://github.com/BCRM/www/issues/1 |
378
|
|
|
* |
379
|
|
|
* @test |
380
|
|
|
* @group functional |
381
|
|
|
*/ |
382
|
|
|
public function tagsShouldAllowUmlauts() |
383
|
|
|
{ |
384
|
|
|
$email = '[email protected]'; |
385
|
|
|
$client = static::createClient(); |
386
|
|
|
$crawler = $client->request('GET', '/anmeldung'); |
387
|
|
|
|
388
|
|
|
$form = $crawler->selectButton('event_register[save]')->form(); |
389
|
|
|
$form['event_register[name]'] = 'John Doe'; |
390
|
|
|
$form['event_register[email]'] = $email; |
391
|
|
|
$form['event_register[days]'] = 3; |
392
|
|
|
$form['event_register[payment]'] = 'paypal'; |
393
|
|
|
$form['event_register[food]'] = 'default'; |
394
|
|
|
$form['event_register[tags]'] = '#zauberwürfel #bar #bcrm13'; |
395
|
|
|
$form['event_register[twitter]'] = '@somebody'; |
396
|
|
|
$form['event_register[participantList]'] = '1'; |
397
|
|
|
$client->submit($form); |
|
|
|
|
398
|
|
|
$response = $client->getResponse(); |
399
|
|
|
$this->assertEquals(302, $response->getStatusCode()); |
400
|
|
|
$this->assertTrue($response->isRedirect('/anmeldung/check'), sprintf('Unexpected redirect to %s', $response->headers->get('Location'))); |
401
|
|
|
return $email; |
402
|
|
|
} |
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: