angelov /
donut
| 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 Behat\Behat\Context\Context; |
||
| 31 | use Angelov\Donut\Behat\Pages\Users\UserCard; |
||
| 32 | use Angelov\Donut\Behat\Pages\Users\BrowsingUsersPage; |
||
| 33 | use Angelov\Donut\Behat\Service\AlertsChecker\AlertsCheckerInterface; |
||
| 34 | use Angelov\Donut\Behat\Service\Storage\StorageInterface; |
||
| 35 | use Webmozart\Assert\Assert; |
||
| 36 | |||
| 37 | class BrowsingUsersContext implements Context |
||
| 38 | { |
||
| 39 | private $storage; |
||
| 40 | private $browsingUsersPage; |
||
| 41 | private $alertsChecker; |
||
| 42 | |||
| 43 | public function __construct(StorageInterface $storage, BrowsingUsersPage $browsingUsersPage, AlertsCheckerInterface $alertsChecker) |
||
| 44 | { |
||
| 45 | $this->storage = $storage; |
||
| 46 | $this->browsingUsersPage = $browsingUsersPage; |
||
| 47 | $this->alertsChecker = $alertsChecker; |
||
| 48 | } |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @When I want to browse the users |
||
| 52 | * @Given I am browsing the users |
||
| 53 | */ |
||
| 54 | public function iWantToBrowseTheUsers() : void |
||
| 55 | { |
||
| 56 | $this->browsingUsersPage->open(); |
||
| 57 | } |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @Then I should see :count users in the list |
||
| 61 | */ |
||
| 62 | public function iShouldSeeUsersInTheList(int $count) : void |
||
| 63 | { |
||
| 64 | $found = $this->browsingUsersPage->countDisplayedUsers(); |
||
| 65 | |||
| 66 | Assert::same($count, $found, 'Expected to find %s listed users, found %s'); |
||
| 67 | } |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @Then those users should be :first, :second, :third and :fourth |
||
| 71 | */ |
||
| 72 | public function thoseUsersShouldBe(string ...$names) : void |
||
| 73 | { |
||
| 74 | $found = $this->browsingUsersPage->getDisplayedUserNames(); |
||
| 75 | |||
| 76 | sort($names); |
||
| 77 | sort($found); |
||
| 78 | |||
| 79 | $names = implode(', ', $names); |
||
| 80 | $found = implode(', ', $found); |
||
| 81 | |||
| 82 | Assert::same($names, $found, 'Expected users: %s. Found: %s'); |
||
| 83 | } |
||
| 84 | |||
| 85 | /** |
||
| 86 | * @Then I should see that :name has shared :count thoughts |
||
| 87 | */ |
||
| 88 | public function iShouldSeeThatUserHasSharedThoughts(string $name, int $count) : void |
||
| 89 | { |
||
| 90 | $found = $this->browsingUsersPage->getUserCard($name)->getNumberOfThoughts(); |
||
| 91 | |||
| 92 | Assert::eq($count, $found, 'Expected number of thoughts for user to be %s, but it is %s'); |
||
| 93 | |||
| 94 | $this->storage->set('current_user_name', $name); |
||
| 95 | } |
||
| 96 | |||
| 97 | /** |
||
| 98 | * @Given I should see that his email is :email |
||
| 99 | */ |
||
| 100 | public function iShouldSeeThatHisEmailIs(string $email) : void |
||
| 101 | { |
||
| 102 | $name = $this->storage->get('current_user_name'); |
||
|
0 ignored issues
–
show
Unused Code
introduced
by
Loading history...
|
|||
| 103 | |||
| 104 | $found = $this->getCurrentUserCard()->getEmail(); |
||
| 105 | |||
| 106 | Assert::same($email, $found, 'Expected displayed e-mail for user to be %s, but it is %s'); |
||
| 107 | } |
||
| 108 | |||
| 109 | /** |
||
| 110 | * @Then I should see that (s)he has :count friend(s) |
||
| 111 | */ |
||
| 112 | public function iShouldSeeThatHeHasFriends(int $count) : void |
||
| 113 | { |
||
| 114 | $found = $this->getCurrentUserCard()->getNumberOfFriends(); |
||
| 115 | |||
| 116 | Assert::eq($count, $found, 'Expected number of user\'s friends to be %s, but it is %s'); |
||
| 117 | } |
||
| 118 | |||
| 119 | /** |
||
| 120 | * @Then I should see that we have :count mutual friend(s) |
||
| 121 | */ |
||
| 122 | public function iShouldSeeThatWeHaveMutualFriends(int $count) : void |
||
| 123 | { |
||
| 124 | $found = $this->getCurrentUserCard()->getNumberOfMutualFriends(); |
||
| 125 | |||
| 126 | Assert::eq($count, $found, 'Expected number of mutual friends to be %s, but it is %s'); |
||
| 127 | } |
||
| 128 | |||
| 129 | /** |
||
| 130 | * @Then that friend should be :name |
||
| 131 | */ |
||
| 132 | public function thatFriendShouldBe(string $name) : void |
||
| 133 | { |
||
| 134 | $names = $this->getCurrentUserCard()->getMutualFriendsNames(); |
||
| 135 | $mutualFriend = $names[0]; |
||
| 136 | |||
| 137 | Assert::same($mutualFriend, $name); |
||
| 138 | } |
||
| 139 | |||
| 140 | /** |
||
| 141 | * @When I want to be friends with :name |
||
| 142 | */ |
||
| 143 | public function iWantToBeFriendsWith(string $name) : void |
||
| 144 | { |
||
| 145 | $this->browsingUsersPage->getUserCard($name)->addAsFriend(); |
||
| 146 | } |
||
| 147 | |||
| 148 | /** |
||
| 149 | * @Then I should be notified that a friendship request is sent |
||
| 150 | */ |
||
| 151 | public function iShouldBeNotifiedThatAFriendshipRequestIsSent() : void |
||
| 152 | { |
||
| 153 | Assert::true( |
||
| 154 | $this->alertsChecker->hasAlert('Friendship request successfully sent!', AlertsCheckerInterface::TYPE_SUCCESS) |
||
| 155 | ); |
||
| 156 | } |
||
| 157 | |||
| 158 | private function getCurrentUserCard(): UserCard |
||
| 159 | { |
||
| 160 | $name = $this->storage->get('current_user_name'); |
||
| 161 | |||
| 162 | return $this->browsingUsersPage->getUserCard($name); |
||
| 163 | } |
||
| 164 | } |
||
| 165 |