|
| 1 | +<?php |
| 2 | + |
| 3 | +use App\Server; |
| 4 | +use App\User; |
| 5 | +use tests\codeception\acceptance\standardPageTests; |
| 6 | + |
| 7 | +class UserCreatePageCest extends standardPageTests |
| 8 | +{ |
| 9 | + |
| 10 | + protected $page; |
| 11 | + protected $user; |
| 12 | + |
| 13 | + public function _before(AcceptanceTester $I) |
| 14 | + { |
| 15 | + $this->user = factory('App\User')->make(); |
| 16 | + $this->page = route('users.create', [], false); |
| 17 | + } |
| 18 | + |
| 19 | + public function _after(AcceptanceTester $I) |
| 20 | + { |
| 21 | + $this->user->delete(); |
| 22 | + } |
| 23 | + |
| 24 | + public function see_a_link_to_the_users_list(AcceptanceTester $I) |
| 25 | + { |
| 26 | + $I->wantTo('see a link for the users list'); |
| 27 | + $I->loginAsTheTestUser(); |
| 28 | + $I->amOnPage($this->page); |
| 29 | + $I->seeCurrentUrlEquals($this->page); |
| 30 | + $I->seeLink( |
| 31 | + 'users', |
| 32 | + route('users', [], false) |
| 33 | + ); |
| 34 | + } |
| 35 | + |
| 36 | + protected function removeFieldsNotOnForm($data){ |
| 37 | + unset( |
| 38 | + $data['id'], |
| 39 | + $data['password'], |
| 40 | + $data['remember_token'], |
| 41 | + $data['created_at'], |
| 42 | + $data['updated_at'] |
| 43 | + ); |
| 44 | + return $data; |
| 45 | + } |
| 46 | + |
| 47 | + public function create_a_user(AcceptanceTester $I) |
| 48 | + { |
| 49 | + $I->wantTo('create a user'); |
| 50 | + $I->loginAsTheTestUser(); |
| 51 | + $I->amOnPage($this->page); |
| 52 | + $I->seeCurrentUrlEquals($this->page); |
| 53 | + $data = $this->removeFieldsNotOnForm($this->user->toArray()); |
| 54 | + foreach($data as $key => $value){ |
| 55 | + $I->fillField("[name={$key}]", $value); |
| 56 | + } |
| 57 | + $I->fillField("[name=password]", 'password'); |
| 58 | + $I->fillField("[name=password_confirmation]", 'password'); |
| 59 | + $I->click('button[type=submit]'); |
| 60 | + $I->seeCurrentUrlEquals( |
| 61 | + route('users', [], false) |
| 62 | + ); |
| 63 | + $loadedUser = User::select() |
| 64 | + ->orderBy('created_at', 'desc') |
| 65 | + ->first() |
| 66 | + ->toArray(); |
| 67 | + $I->assertEmpty( |
| 68 | + array_diff_assoc($data, $this->removeFieldsNotOnForm($loadedUser)) |
| 69 | + ); |
| 70 | + } |
| 71 | +} |
0 commit comments