/
CreateUserTest.php
100 lines (75 loc) · 3.95 KB
/
CreateUserTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
namespace spec\rtens\lacarte\specs\user;
use spec\rtens\lacarte\fixtures\resource\user\ListResourceFixture;
use spec\rtens\lacarte\fixtures\model\UserFixture;
use spec\rtens\lacarte\fixtures\service\KeyGeneratorFixture;
use spec\rtens\lacarte\fixtures\service\SessionFixture;
use spec\rtens\lacarte\Specification;
/**
* @property SessionFixture session <-
* @property KeyGeneratorFixture key <-
* @property UserFixture user <-
* @property ListResourceFixture component <-
*/
class CreateUserTest extends Specification {
function testCreateUserSuccessfully() {
$this->session->givenIAmLoggedInAsAdmin();
$this->component->givenIHaveEnteredTheName('Bart Simpson');
$this->component->givenIHaveEnteredTheEmail('bart@simpson.com');
$this->key->givenTheNextGeneratedKeyIs('key');
$this->component->whenICreateANewUser();
$this->component->thenTheSuccessMessageShouldBe('The user Bart Simpson was created.');
$this->user->thenThereShouldBe_Users(1);
$this->user->thenThereShouldBeAUserWithTheName_TheEmailAndTheKey('Bart Simpson', 'bart@simpson.com', 'key');
}
function testNotLoggedIn() {
$this->component->givenIHaveEnteredTheName('Lisa Simpson');
$this->component->givenIHaveEnteredTheEmail('lisa@simpson.com');
$this->component->whenICreateANewUser();
$this->component->thenIShouldBeRedirectedTo('login.html');
}
function testNotAdmin() {
$this->session->givenIAmLoggedAsTheUser('Homer');
$this->component->givenIHaveEnteredTheName('Lisa Simpson');
$this->component->givenIHaveEnteredTheEmail('lisa@simpson.com');
$this->component->whenICreateANewUser();
$this->component->thenTheErrorMessageShouldBe('Access denied. Must be administrator.');
$this->component->thenTheNewNameFieldShouldContain('Lisa Simpson');
$this->component->thenTheEmailFieldShouldContain('lisa@simpson.com');
}
function testEmptyName() {
$this->session->givenIAmLoggedInAsAdmin();
$this->component->givenIHaveEnteredTheEmail('bart@simpson.com');
$this->component->whenICreateANewUser();
$this->component->thenTheErrorMessageShouldBe('Please provide name and email.');
$this->component->thenTheEmailFieldShouldContain('bart@simpson.com');
}
function testEmptyEmail() {
$this->session->givenIAmLoggedInAsAdmin();
$this->component->givenIHaveEnteredTheName('Bart Simpson');
$this->component->whenICreateANewUser();
$this->component->thenTheErrorMessageShouldBe('Please provide name and email.');
$this->component->thenTheNewNameFieldShouldContain('Bart Simpson');
}
function testAlreadyExistingEmail() {
$this->session->givenIAmLoggedInAsAdmin();
$this->user->givenTheUser_WithTheEmail('El Barto', 'bart@simpson.com');
$this->component->givenIHaveEnteredTheName('Bart Simpson');
$this->component->givenIHaveEnteredTheEmail('Bart@Simpson.com');
$this->component->whenICreateANewUser();
$this->component->thenTheErrorMessageShouldBe('Error while creating user. The email probably already exists.');
$this->component->thenTheNewNameFieldShouldContain('Bart Simpson');
$this->component->thenTheEmailFieldShouldContain('Bart@Simpson.com');
}
function testAlreadyExistingKey() {
$this->session->givenIAmLoggedInAsAdmin();
$this->user->givenTheUser_WithTheEmail_AndKey('Bart Simpson', 'bart@simpson.com', 'abc');
$this->component->givenIHaveEnteredTheName('Lisa Simpson');
$this->component->givenIHaveEnteredTheEmail('lisa@simpson.com');
$this->key->givenTheNextGeneratedKeyIs('def');
$this->key->givenTheNextGeneratedKeyIs('abc');
$this->component->whenICreateANewUser();
$this->user->thenThereShouldBe_Users(2);
$this->user->thenThereShouldBeAUserWithTheName_TheEmailAndTheKey('Lisa Simpson', 'lisa@simpson.com', 'def');
}
}