Skip to content

Commit 80023e3

Browse files
committed
create user test
1 parent b16fa4f commit 80023e3

File tree

3 files changed

+81
-1
lines changed

3 files changed

+81
-1
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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+
}

tests/codeception/acceptance/UserShowPageCest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ public function _after()
1919
$this->user->delete();
2020
}
2121

22+
public function see_a_link_to_the_users_list(AcceptanceTester $I)
23+
{
24+
$I->wantTo('see a link for the servers list');
25+
$I->loginAsTheTestUser();
26+
$I->amOnPage($this->page);
27+
$I->seeCurrentUrlEquals($this->page);
28+
$I->seeLink('Users', route('users', [], false));
29+
}
30+
2231
public function see_user_details(AcceptanceTester $I)
2332
{
2433
$I->wantTo('see the users');

todo.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
## to do:-
2-
- codeception test user creation,edit,delete
2+
- codeception test user edit,delete <<-- selenium may be needed for meaningful tests here, as it relies on js
33
- setup psr2 sniffer and do sniffing
44
- git diff between last and new deployment
55
- add api to allow deployment via a github commit

0 commit comments

Comments
 (0)