iShouldNotSeeSuggestionToAddAsAFriend()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Donut Social Network - Yet another experimental social network.
5
 * Copyright (C) 2016-2017, Dejan Angelov <[email protected]>
6
 *
7
 * This file is part of Donut Social Network.
8
 *
9
 * Donut Social Network is free software: you can redistribute it and/or modify
10
 * it under the terms of the GNU General Public License as published by
11
 * the Free Software Foundation, either version 3 of the License, or
12
 * (at your option) any later version.
13
 *
14
 * Donut Social Network is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with Donut Social Network.  If not, see <http://www.gnu.org/licenses/>.
21
 *
22
 * @package Donut Social Network
23
 * @copyright Copyright (C) 2016-2017, Dejan Angelov <[email protected]>
24
 * @license https://github.com/angelov/donut/blob/master/LICENSE
25
 * @author Dejan Angelov <[email protected]>
26
 */
27
28
namespace AppBundle\FeatureContexts;
29
30
use Angelov\Donut\Behat\Pages\Friendships\FriendshipsManagementPage;
31
use Angelov\Donut\Behat\Service\AlertsChecker\AlertsCheckerInterface;
32
use Angelov\Donut\Behat\Service\Storage\StorageInterface;
33
use Angelov\Donut\Friendships\FriendshipRequests\FriendshipRequest;
34
use Behat\Behat\Context\Context;
35
use Angelov\Donut\Users\User;
36
use Webmozart\Assert\Assert;
37
38
class ManagingFriendshipsContext implements Context
39
{
40
    private $storage;
41
    private $friendshipsManagementPage;
42
    private $alertsChecker;
43
44
    public function __construct(
45
        StorageInterface $storage,
46
        FriendshipsManagementPage $friendshipsManagementPage,
47
        AlertsCheckerInterface $alertsChecker
48
    ) {
49
        $this->storage = $storage;
50
        $this->friendshipsManagementPage = $friendshipsManagementPage;
51
        $this->alertsChecker = $alertsChecker;
52
    }
53
54
    /**
55
     * @When I want to manage my friendships
56
     */
57
    public function iWantToManageMyFriendships() : void
58
    {
59
        $this->friendshipsManagementPage->open();
60
    }
61
62
    /**
63
     * @Then I should see that I have :count friends
64
     */
65
    public function iShouldSeeThatIHaveFriends(int $count) : void
66
    {
67
        $found = $this->friendshipsManagementPage->countFriends();
68
69
        Assert::eq($count, $found, 'Expected to find %s friends, found %s.');
70
    }
71
72
    /**
73
     * @Then I should see that I am friend with :first and :second
74
     */
75
    public function iShouldSeeThatIAmFriendWith(string ...$names) : void
76
    {
77
        $foundNames = $this->friendshipsManagementPage->getDisplayedFriends();
78
79
        sort($names);
80
        sort($foundNames);
81
82
        $names = implode(', ', $names);
83
        $foundNames = implode(', ', $foundNames);
84
85
        Assert::same($names, $foundNames, 'Expected friends: %s. Found friends: %s.');
86
    }
87
88
    /**
89
     * @Then I should see that I have :count friendship request(s)
90
     */
91
    public function iShouldSeeThatIHaveFriendRequest(int $count) : void
92
    {
93
        $found = $this->friendshipsManagementPage->countReceivedFriendshipRequests();
94
95
        Assert::same($count, $found, 'Expected to find %s received friendship requests, found %s instead.');
96
    }
97
98
    /**
99
     * @Then it should be from :name
100
     */
101
    public function itShouldBeFrom(string $name) : void
102
    {
103
        Assert::true(
104
            $this->friendshipsManagementPage->hasReceivedFriendshipRequestFrom($name),
105
            'Could not find a friendship request from ' . $name
106
        );
107
    }
108
109
    /**
110
     * @Then I should see that I have :count sent friendship request(s)
111
     */
112
    public function iShouldSeeThatIHaveSentFriendshipRequest(int $count) : void
113
    {
114
        $found = $this->friendshipsManagementPage->countSentFriendshipRequests();
115
116
        Assert::same($count, $found, 'Expected to find %s sent friendship requests, found %s instead.');
117
    }
118
119
    /**
120
     * @Then it should be for :name
121
     */
122
    public function itShouldBeFor(string $name) : void
123
    {
124
        Assert::true(
125
            $this->friendshipsManagementPage->hasSentFriendshipRequestTo($name),
126
            'Could not find a friendship request sent to ' . $name
127
        );
128
    }
129
130
    /**
131
     * @Then I should see that I haven't got any received friendship requests
132
     */
133
    public function iShouldSeeThatIHavenTGotAnyReceivedFriendshipRequests() : void
134
    {
135
        Assert::true(
136
            $this->friendshipsManagementPage->hasNoReceivedFriendshipRequestsMessage()
137
        );
138
    }
139
140
    /**
141
     * @Then I should see that I haven't got any sent friendship requests
142
     */
143
    public function iShouldSeeThatIHavenTGotAnySentFriendshipRequests() : void
144
    {
145
        Assert::true(
146
            $this->friendshipsManagementPage->hasNoSentFriendshipRequestsMessage()
147
        );
148
    }
149
150
    /**
151
     * @When I accept her friendship request
152
     * @When I accept his friendship request
153
     */
154
    public function iAcceptHerFriendshipRequest() : void
155
    {
156
        /** @var FriendshipRequest $request */
157
        $request = $this->storage->get('current_friendship_request');
158
        $toFind = $request->getFromUser()->getName();
159
160
        $this->friendshipsManagementPage->getFriendshipRequestFrom($toFind)->accept();
161
    }
162
163
    /**
164
     * @Then I should be notified that we've became friends
165
     */
166
    public function iShouldBeNotifiedThatWeVeBecameFriends() : void
167
    {
168
        Assert::true(
169
            $this->alertsChecker->hasAlert('Friendship request successfully accepted!', AlertsCheckerInterface::TYPE_SUCCESS)
170
        );
171
    }
172
173
    /**
174
     * @Given I shouldn't see the request anymore
175
     */
176
    public function iShouldnTSeeTheRequestAnymore() : void
177
    {
178
        $this->iShouldSeeThatIHaveFriendRequest(0);
179
    }
180
181
    /**
182
     * @When I decline her friendship request
183
     * @When I decline his friendship request
184
     */
185
    public function iDeclineHerFriendshipRequest() : void
186
    {
187
        /** @var FriendshipRequest $request */
188
        $request = $this->storage->get('current_friendship_request');
189
        $toFind = $request->getFromUser()->getName();
190
191
        $this->friendshipsManagementPage->getFriendshipRequestFrom($toFind)->decline();
192
    }
193
194
    /**
195
     * @Then I should be notified that the request is removed
196
     */
197
    public function iShouldBeNotifiedThatTheRequestIsRemoved() : void
198
    {
199
        Assert::true(
200
            $this->alertsChecker->hasAlert('Friendship request successfully declined!', AlertsCheckerInterface::TYPE_SUCCESS)
201
        );
202
    }
203
204
    /**
205
     * @Given I delete my friendship with :name
206
     * @Given I want to stop being a friend with :name
207
     */
208
    public function iDeleteMyFriendshipWith(string $name) : void
209
    {
210
        /** @var User $friend */
211
        $friend = $this->storage->get('created_user_' . $name);
212
        $toFind = $friend->getName();
213
214
        $this->friendshipsManagementPage->getFriendship($toFind)->delete();
215
    }
216
217
    /**
218
     * @Then I should be notified that the friendship is deleted
219
     */
220
    public function iShouldBeNotifiedThatTheFriendshipIsDeleted() : void
221
    {
222
        Assert::true(
223
            $this->alertsChecker->hasAlert('Sorry to see broken friendships.', AlertsCheckerInterface::TYPE_SUCCESS),
224
            'Could not find a notification about deleted friendship.'
225
        );
226
    }
227
228
    /**
229
     * @Then I shouldn't see :name in the list of friends anymore
230
     */
231
    public function iShouldnTSeeInTheListOfFriendsAnymore(string $name) : void
232
    {
233
        Assert::false(
234
            $this->friendshipsManagementPage->isFriendWith($name)
235
        );
236
    }
237
238
    /**
239
     * @When I want to cancel the friendship request
240
     */
241
    public function iWantToCancelTheFriendshipRequest() : void
242
    {
243
        /** @var FriendshipRequest $request */
244
        $request = $this->storage->get('current_friendship_request');
245
        $toFind = $request->getToUser()->getName();
246
247
        $this->friendshipsManagementPage->getFriendshipRequestTo($toFind)->cancel();
248
    }
249
250
    /**
251
     * @Then I should be notified that the request is cancelled
252
     */
253
    public function iShouldBeNotifiedThatTheRequestIsCancelled() : void
254
    {
255
        Assert::true(
256
            $this->alertsChecker->hasAlert('Friendship request successfully cancelled!', AlertsCheckerInterface::TYPE_SUCCESS)
257
        );
258
    }
259
260
    /**
261
     * @Then I should see a message that I still don't have any friends
262
     */
263
    public function iShouldSeeAMessageThatIStillDonTHaveAnyFriends() : void
264
    {
265
        Assert::true(
266
            $this->friendshipsManagementPage->hasNoFriendsMessage()
267
        );
268
    }
269
270
    /**
271
     * @Then I should see suggestion to add :name as a friend
272
     */
273
    public function iShouldSeeSuggestionToAddAsAFriend(string $name) : void
274
    {
275
        Assert::true(
276
            $this->friendshipsManagementPage->hasSuggestionToAddAsFriend($name)
277
        );
278
    }
279
280
    /**
281
     * @Then I should not see suggestion to add :name as a friend
282
     */
283
    public function iShouldNotSeeSuggestionToAddAsAFriend(string $name) : void
284
    {
285
        Assert::false(
286
            $this->friendshipsManagementPage->hasSuggestionToAddAsFriend($name)
287
        );
288
    }
289
290
    /**
291
     * @Then I should see a message that there are no friends suggested for me
292
     */
293
    public function iShouldSeeAMessageThatThereAreNoFriendsSuggestedForMe() : void
294
    {
295
        Assert::true(
296
            $this->friendshipsManagementPage->hasNoFriendshipSuggestionsMessage()
297
        );
298
    }
299
300
    /**
301
     * @When I choose to ignore the suggestion to add :name as a friend
302
     */
303
    public function iChooseToIgnoreTheSuggestionToAddAsAFriend(string $name) : void
304
    {
305
        $this->friendshipsManagementPage->getFriendshipSuggestion($name)->ignore();
306
    }
307
}
308