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\CreateTicketsCommand; |
11
|
|
|
use BCRM\BackendBundle\Entity\Event\Registration; |
12
|
|
|
use BCRM\BackendBundle\Entity\Event\Ticket; |
13
|
|
|
use BCRM\BackendBundle\Entity\Payment; |
14
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* - VIPs and Sponsors must always be given tickets. |
18
|
|
|
* - The events capacity must only be applied to the regular tickets. |
19
|
|
|
*/ |
20
|
|
|
class VipTicketsTest extends Base |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* The setUpBeforeClass() and tearDownAfterClass() template methods are called before the first test of the test |
24
|
|
|
* case class is run and after the last test of the test case class is run, respectively. |
25
|
|
|
*/ |
26
|
|
|
public static function setUpBeforeClass() |
27
|
|
|
{ |
28
|
|
|
static::resetDatabase(); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @test |
33
|
|
|
* @group functional |
34
|
|
|
*/ |
35
|
|
|
public function vipTicketsShouldAlwaysBeCreated() |
36
|
|
|
{ |
37
|
|
|
/* @var $em \Doctrine\Common\Persistence\ObjectManager */ |
38
|
|
|
$client = static::createClient(); |
39
|
|
|
$container = $client->getContainer(); |
40
|
|
|
$em = $container |
41
|
|
|
->get('doctrine') |
42
|
|
|
->getManager(); |
43
|
|
|
|
44
|
|
|
$event = $em->getRepository('BCRMBackendBundle:Event\Event')->findAll()[0]; |
45
|
|
|
|
46
|
|
|
// Create normal registrations |
47
|
|
|
$johnPays = new Payment(); |
48
|
|
|
$johnPays->setTransactionId('johnpay'); |
49
|
|
|
$johnPays->setMethod('cash'); |
50
|
|
|
$em->persist($johnPays); |
51
|
|
|
$john = new Registration(); |
52
|
|
|
$john->setUuid('john'); |
53
|
|
|
$john->setName('John'); |
54
|
|
|
$john->setEvent($event); |
55
|
|
|
$john->setEmail('[email protected]'); |
56
|
|
|
$john->setSaturday(true); |
57
|
|
|
$john->setPayment($johnPays); |
58
|
|
|
$em->persist($john); |
59
|
|
|
|
60
|
|
|
$maryPays = new Payment(); |
61
|
|
|
$maryPays->setTransactionId('marypay'); |
62
|
|
|
$maryPays->setMethod('cash'); |
63
|
|
|
$em->persist($maryPays); |
64
|
|
|
$mary = new Registration(); |
65
|
|
|
$mary->setUuid('mary'); |
66
|
|
|
$mary->setName('Mary'); |
67
|
|
|
$mary->setEvent($event); |
68
|
|
|
$mary->setEmail('[email protected]'); |
69
|
|
|
$mary->setSaturday(true); |
70
|
|
|
$mary->setPayment($maryPays); |
71
|
|
|
$em->persist($mary); |
72
|
|
|
|
73
|
|
|
$em->flush(); |
74
|
|
|
|
75
|
|
|
$this->createTicketsCommand($container); |
|
|
|
|
76
|
|
|
|
77
|
|
|
$this->assertEquals(2, count($em->getRepository('BCRMBackendBundle:Event\Ticket')->findBy(array( |
78
|
|
|
'event' => $event, |
79
|
|
|
'day' => Ticket::DAY_SATURDAY, |
80
|
|
|
)))); |
81
|
|
|
|
82
|
|
|
// Create VIP registration |
83
|
|
|
$vip = new Registration(); |
84
|
|
|
$vip->setUuid('VIP'); |
85
|
|
|
$vip->setName('VIP'); |
86
|
|
|
$vip->setEvent($event); |
87
|
|
|
$vip->setEmail('[email protected]'); |
88
|
|
|
$vip->setSaturday(true); |
89
|
|
|
$vip->setType(Registration::TYPE_VIP); |
90
|
|
|
$em->persist($vip); |
91
|
|
|
|
92
|
|
|
// Create Sponsor registration |
93
|
|
|
$sponsor = new Registration(); |
94
|
|
|
$sponsor->setUuid('Sponsor'); |
95
|
|
|
$sponsor->setName('Sponsor'); |
96
|
|
|
$sponsor->setEvent($event); |
97
|
|
|
$sponsor->setEmail('[email protected]'); |
98
|
|
|
$sponsor->setSaturday(true); |
99
|
|
|
$sponsor->setType(Registration::TYPE_SPONSOR); |
100
|
|
|
$em->persist($sponsor); |
101
|
|
|
|
102
|
|
|
$em->flush(); |
103
|
|
|
|
104
|
|
|
$this->createTicketsCommand($container); |
|
|
|
|
105
|
|
|
|
106
|
|
|
$this->assertEquals(4, count($em->getRepository('BCRMBackendBundle:Event\Ticket')->findBy(array( |
107
|
|
|
'event' => $event, |
108
|
|
|
'day' => Ticket::DAY_SATURDAY, |
109
|
|
|
)))); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
protected function createTicketsCommand(ContainerInterface $container) |
113
|
|
|
{ |
114
|
|
|
$this->runCommand($container, new CreateTicketsCommand(), 'bcrm:tickets:create'); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @test |
119
|
|
|
* @depends vipTicketsShouldAlwaysBeCreated |
120
|
|
|
*/ |
121
|
|
|
function vipTicketsShouldNotCountForEventCapacity() |
|
|
|
|
122
|
|
|
{ |
123
|
|
|
/* @var $em \Doctrine\Common\Persistence\ObjectManager */ |
124
|
|
|
$client = static::createClient(); |
125
|
|
|
$container = $client->getContainer(); |
126
|
|
|
$em = $container |
127
|
|
|
->get('doctrine') |
128
|
|
|
->getManager(); |
129
|
|
|
|
130
|
|
|
$event = $em->getRepository('BCRMBackendBundle:Event\Event')->findAll()[0]; |
131
|
|
|
|
132
|
|
|
// Create two other normal registrations |
133
|
|
|
$joePays = new Payment(); |
134
|
|
|
$joePays->setTransactionId('joepay'); |
135
|
|
|
$joePays->setMethod('cash'); |
136
|
|
|
$em->persist($joePays); |
137
|
|
|
$joe = new Registration(); |
138
|
|
|
$joe->setName('Joe'); |
139
|
|
|
$joe->setUuid('Joe'); |
140
|
|
|
$joe->setEvent($event); |
141
|
|
|
$joe->setEmail('[email protected]'); |
142
|
|
|
$joe->setSaturday(true); |
143
|
|
|
$joe->setPayment($joePays); |
144
|
|
|
$em->persist($joe); |
145
|
|
|
$jillPays = new Payment(); |
146
|
|
|
$jillPays->setTransactionId('jillpays'); |
147
|
|
|
$jillPays->setMethod('cash'); |
148
|
|
|
$em->persist($jillPays); |
149
|
|
|
$jill = new Registration(); |
150
|
|
|
$jill->setName('Jill'); |
151
|
|
|
$jill->setUuid('Jill'); |
152
|
|
|
$jill->setEvent($event); |
153
|
|
|
$jill->setEmail('[email protected]'); |
154
|
|
|
$jill->setSaturday(true); |
155
|
|
|
$jill->setPayment($jillPays); |
156
|
|
|
$em->persist($jill); |
157
|
|
|
$em->flush(); |
158
|
|
|
$this->createTicketsCommand($container); |
|
|
|
|
159
|
|
|
$this->assertEquals(5, count($em->getRepository('BCRMBackendBundle:Event\Ticket')->findBy(array( |
160
|
|
|
'event' => $event, |
161
|
|
|
'day' => Ticket::DAY_SATURDAY, |
162
|
|
|
)))); |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* @test |
167
|
|
|
* @group functional |
168
|
|
|
* @group regression |
169
|
|
|
* @depends vipTicketsShouldNotCountForEventCapacity |
170
|
|
|
*/ |
171
|
|
|
public function vipTicketsShouldBeCreatedIfEventIsOverCapacity() |
172
|
|
|
{ |
173
|
|
|
/* @var $em \Doctrine\Common\Persistence\ObjectManager */ |
174
|
|
|
$client = static::createClient(); |
175
|
|
|
$container = $client->getContainer(); |
176
|
|
|
$em = $container |
177
|
|
|
->get('doctrine') |
178
|
|
|
->getManager(); |
179
|
|
|
|
180
|
|
|
$event = $em->getRepository('BCRMBackendBundle:Event\Event')->findAll()[0]; |
181
|
|
|
$event->setCapacity(1); |
182
|
|
|
$em->persist($event); |
183
|
|
|
$em->flush(); |
184
|
|
|
|
185
|
|
|
// Create Sponsor registration |
186
|
|
|
$sponsor2 = new Registration(); |
187
|
|
|
$sponsor2->setName('Sponsor 2'); |
188
|
|
|
$sponsor2->setUuid('Sponsor 2'); |
189
|
|
|
$sponsor2->setEvent($event); |
190
|
|
|
$sponsor2->setEmail('[email protected]'); |
191
|
|
|
$sponsor2->setSaturday(true); |
192
|
|
|
$sponsor2->setType(Registration::TYPE_SPONSOR); |
193
|
|
|
$em->persist($sponsor2); |
194
|
|
|
|
195
|
|
|
$em->flush(); |
196
|
|
|
|
197
|
|
|
$this->createTicketsCommand($container); |
|
|
|
|
198
|
|
|
|
199
|
|
|
$this->assertEquals(6, count($em->getRepository('BCRMBackendBundle:Event\Ticket')->findBy(array( |
200
|
|
|
'event' => $event, |
201
|
|
|
'day' => Ticket::DAY_SATURDAY, |
202
|
|
|
)))); |
203
|
|
|
} |
204
|
|
|
} |
205
|
|
|
|
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: