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\Entity\Event\Registration; |
11
|
|
|
use BCRM\BackendBundle\Entity\Event\Ticket; |
12
|
|
|
use BCRM\BackendBundle\Entity\Payment; |
13
|
|
|
use Symfony\Component\BrowserKit\Cookie; |
14
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
15
|
|
|
|
16
|
|
|
class StatsControllerTest extends Base |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* The setUpBeforeClass() and tearDownAfterClass() template methods are called before the first test of the test |
20
|
|
|
* case class is run and after the last test of the test case class is run, respectively. |
21
|
|
|
*/ |
22
|
|
|
public static function setUpBeforeClass() |
23
|
|
|
{ |
24
|
|
|
static::resetDatabase(); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @test |
29
|
|
|
* @group functional |
30
|
|
|
*/ |
31
|
|
|
public function stats() |
32
|
|
|
{ |
33
|
|
|
$email = $this->createTicket(Ticket::DAY_SATURDAY); |
34
|
|
|
$this->createTicket(Ticket::DAY_SATURDAY); |
35
|
|
|
$this->createTicket(Ticket::DAY_SATURDAY, false); |
36
|
|
|
$this->createTicket(Ticket::DAY_SATURDAY, false); |
37
|
|
|
$this->createTicket(Ticket::DAY_SUNDAY, null, $email); |
38
|
|
|
$this->createTicket(Ticket::DAY_SUNDAY); |
39
|
|
|
$this->createTicket(Ticket::DAY_SUNDAY); |
40
|
|
|
$this->createTicket(Ticket::DAY_SUNDAY, false); |
41
|
|
|
|
42
|
|
|
$client = static::createClient(); |
43
|
|
|
$client->request('GET', '/stats.json'); |
44
|
|
|
$response = $client->getResponse(); |
45
|
|
|
$this->assertEquals(200, $response->getStatusCode()); |
46
|
|
|
$this->assertEquals("application/json", $response->headers->get('Content-Type')); |
47
|
|
|
$this->assertEquals("utf-8", $response->getCharset()); |
48
|
|
|
$response = json_decode($response->getContent()); |
49
|
|
|
$this->assertObjectHasAttribute('stats', $response); |
50
|
|
|
$stats = $response->stats; |
51
|
|
|
$this->assertObjectHasAttribute('checkins', $stats); |
52
|
|
|
$checkins = $stats->checkins; |
53
|
|
|
|
54
|
|
|
$this->assertEquals(2, $checkins->sa); |
55
|
|
|
$this->assertEquals(3, $checkins->su); |
56
|
|
|
$this->assertEquals(1, $checkins->unique->sa); |
57
|
|
|
$this->assertEquals(2, $checkins->unique->su); |
58
|
|
|
$this->assertEquals(1, $checkins->unique->both); |
59
|
|
|
$this->assertEquals(2, $checkins->noshows->sa); |
60
|
|
|
$this->assertEquals(1, $checkins->noshows->su); |
61
|
|
|
$this->assertEquals($checkins->sa, $checkins->unique->sa + $checkins->unique->both); |
62
|
|
|
$this->assertEquals($checkins->su, $checkins->unique->su + $checkins->unique->both); |
63
|
|
|
|
64
|
|
|
|
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
protected $ticketCounter = 1; |
68
|
|
|
|
69
|
|
|
protected function createTicket($day, $checkedIn = null, $email = null) |
70
|
|
|
{ |
71
|
|
|
if ($email === null) $email = sprintf('stats.doe.198%[email protected]', $this->ticketCounter); |
72
|
|
|
if ($checkedIn === null) $checkedIn = true; |
73
|
|
|
$client = static::createClient(); |
74
|
|
|
$container = $client->getContainer(); |
75
|
|
|
|
76
|
|
|
/* @var $em \Doctrine\Common\Persistence\ObjectManager */ |
77
|
|
|
$em = $container |
78
|
|
|
->get('doctrine') |
79
|
|
|
->getManager(); |
80
|
|
|
|
81
|
|
|
// Create a payment |
82
|
|
|
$txId = sha1('someid' . $email); |
83
|
|
|
$payment = $em->getRepository('BCRMBackendBundle:Payment')->findOneByTxId($txId); |
|
|
|
|
84
|
|
|
if (!$payment) { |
85
|
|
|
$payment = new Payment(); |
86
|
|
|
$payment->setTransactionId($txId); |
87
|
|
|
$payment->setMethod('somemethod'); |
88
|
|
|
$em->persist($payment); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
// Create a ticket |
92
|
|
|
$event = $em->getRepository('BCRMBackendBundle:Event\Event')->findAll()[0]; |
93
|
|
|
$ticket = new Ticket(); |
94
|
|
|
$ticket->setEmail($email); |
95
|
|
|
$ticket->setName('John Doe'); |
96
|
|
|
$ticket->setEvent($event); |
97
|
|
|
$ticket->setDay($day); |
98
|
|
|
$ticket->setCode(sprintf('STATS%d', $this->ticketCounter++)); |
99
|
|
|
$ticket->setCheckedIn($checkedIn); |
100
|
|
|
$ticket->setPayment($payment); |
101
|
|
|
$em->persist($ticket); |
102
|
|
|
$em->flush(); |
103
|
|
|
return $email; |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.