1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* Copyright 2014-2017 Arnaud Bienvenu |
4
|
|
|
* |
5
|
|
|
* This file is part of Kyela. |
6
|
|
|
|
7
|
|
|
* Kyela is free software: you can redistribute it and/or modify |
8
|
|
|
* it under the terms of the GNU Affero General Public License as published by |
9
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
10
|
|
|
* (at your option) any later version. |
11
|
|
|
|
12
|
|
|
* Kyela is distributed in the hope that it will be useful, |
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15
|
|
|
* GNU Affero General Public License for more details. |
16
|
|
|
|
17
|
|
|
* You should have received a copy of the GNU Affero General Public License |
18
|
|
|
* along with Kyela. If not, see <http://www.gnu.org/licenses/>. |
19
|
|
|
* |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
namespace Abienvenu\KyelaBundle\Tests\Controller; |
23
|
|
|
|
24
|
|
|
class ParticipationControllerTest extends PollWebTestCase |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* Creates, edits and deletes a participation |
28
|
|
|
*/ |
29
|
|
|
public function testCompleteScenario() |
30
|
|
|
{ |
31
|
|
|
// Create a poll to work with |
32
|
|
|
$crawler = self::createPollEntry(uniqid('Test Poll ')); |
33
|
|
|
|
34
|
|
|
// Create a participant |
35
|
|
|
$participant = uniqid('Test Participant '); |
36
|
|
|
$crawler = self::submitForm($crawler, 'add.a.participant', 'participant', ['name' => $participant]); |
37
|
|
|
|
38
|
|
|
// Create an event |
39
|
|
|
$event = uniqid('Test Event '); |
40
|
|
|
$crawler = self::clickLink($crawler, 'add.a.date'); |
41
|
|
|
$crawler = self::submitForm($crawler, 'create', 'event', |
|
|
|
|
42
|
|
|
['name' => $event, 'place' => 'Nowhere', 'date' => date('d-m-Y', strtotime("tomorrow")), 'time' => '20:30']); |
43
|
|
|
|
44
|
|
|
// Check "yes" is not selected |
45
|
|
|
$filter = 'button:contains("' . self::$translator->trans('yes') . '")'; |
46
|
|
|
self::checkElement($crawler, $filter, 1); |
|
|
|
|
47
|
|
|
|
48
|
|
|
// Choose "yes" |
49
|
|
|
$button = $crawler->selectButton(self::$translator->trans('yes')); |
50
|
|
|
$url = $button->extract(['data-url'])[0]; |
51
|
|
|
self::$client->request('GET', $url); |
52
|
|
|
self::$client->back(); |
53
|
|
|
$crawler = self::$client->reload(); |
54
|
|
|
|
55
|
|
|
// Check "yes is selected |
56
|
|
|
$filter = 'button:contains("' . self::$translator->trans('yes') . '")'; |
57
|
|
|
self::checkElement($crawler, $filter, 2); |
|
|
|
|
58
|
|
|
|
59
|
|
|
// Choose "no" |
60
|
|
|
$button = $crawler->selectButton(self::$translator->trans('no')); |
61
|
|
|
$url = $button->extract(['data-url'])[0]; |
62
|
|
|
self::$client->request('GET', $url); |
63
|
|
|
self::$client->back(); |
64
|
|
|
$crawler = self::$client->reload(); |
65
|
|
|
|
66
|
|
|
// Check "yes" is not selected anymore |
67
|
|
|
$filter = 'button:contains("' . self::$translator->trans('yes') . '")'; |
68
|
|
|
self::checkElement($crawler, $filter, 1); |
|
|
|
|
69
|
|
|
|
70
|
|
|
// Check "no" is selected |
71
|
|
|
$filter = 'button:contains("' . self::$translator->trans('no') . '")'; |
72
|
|
|
self::checkElement($crawler, $filter, 2); |
|
|
|
|
73
|
|
|
|
74
|
|
|
// Delete the poll |
75
|
|
|
self::deletePollEntry($crawler); |
|
|
|
|
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
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: