-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnotices.test
More file actions
239 lines (197 loc) · 5.51 KB
/
notices.test
File metadata and controls
239 lines (197 loc) · 5.51 KB
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
<?php
/**
* @file
* Tests for notices module.
*/
/**
* Testing accesses to the notifications.
*/
class NoticesAccessTestCase extends DrupalWebTestCase {
/**
* A user with permission the access to page module.
*
* @var object
*/
protected $web_user;
public static function getInfo() {
return array(
'name' => 'Access notices',
'description' => 'Testing accesses to the notifications.',
'group' => 'Notices',
);
}
public function setUp() {
parent::setUp(array('notices'));
$this->web_user = $this->drupalCreateUser(array('read notices', 'delete notices'));
$this->drupalLogin($this->web_user);
$this->noticeMessage = $this->randomName();
// Create one notice for tests without running the hooks module.
$notice = new stdClass();
$notice->uid = $this->web_user->uid;
// Defunct provider.
$notice->provider = $this->randomName();
$notice->subject = $this->randomName();
$notice->message = $this->noticeMessage;
$notice->format = filter_default_format();
notices_save($notice);
$this->noticeId = $this->noticeId();
}
/**
* Test access to page list notices.
*/
public function testNoticesListAccess() {
$this->drupalGet('notices/list');
$this->assertText($this->noticeMessage);
}
/**
* Test access to page view one notice.
*/
public function testNoticesViewAccess() {
$this->drupalGet('notices/view/' . $this->noticeId);
$this->assertText($this->noticeMessage);
}
/**
* Test access to delete notice.
*/
public function testNoticesDeleteAccess() {
$this->drupalGet('notices/delete/' . $this->noticeId);
$this->assertText(t('Do you want to delete this message?'));
}
/**
* ID last notice for user.
*/
protected function noticeId() {
$notice = db_select('notices', 'n')
->fields('n', array('noticeid'))
->range(0, 1)
->orderBy('noticeid', 'DESC')
->execute()
->fetchObject();
if ($notice) {
return $notice->noticeid;
}
}
}
/**
* Testing main functions of the module.
*/
class NoticesTestCase extends DrupalWebTestCase {
/**
* A user with permission the access to page module.
*
* @var object
*/
protected $web_user;
public static function getInfo() {
return array(
'name' => 'Module Notices',
'description' => 'Testing main functions of the module.',
'group' => 'Notices',
);
}
public function setUp() {
parent::setUp(array('notices'));
$this->web_user = $this->drupalCreateUser(array('read notices', 'delete notices', 'read all notices', 'administer notice settings'));
$this->drupalLogin($this->web_user);
}
/**
* Test add notice.
*/
public function testNoticesAdd() {
$edit = array(
'uid' => $this->web_user->uid,
'provider' => $this->randomName(),
'message[value]' => $this->randomName(),
'message[format]' => filter_default_format(),
);
$this->drupalPost('admin/config/notices/add', $edit, t('Update status of payment gateways'));
$count = db_select('notices', 'n')
->condition('n.uid', $this->web_user->uid)
->countQuery()
->execute()
->fetchField();
$this->assertEqual(1, $count);
}
/**
* Test view notice.
*/
public function testNoticesView() {
$this->createNotice();
$notice = db_select('notices', 'n')
->fields('n', array('message'))
->condition('n.noticeid', 1)
->execute()
->fetchObject();
$this->drupalGet('notices/view/1');
$this->assertText($notice->message);
}
/**
* Test mark all notices as read, no ajax.
*/
public function testNoticesMarkAsReadAll() {
$this->createNotice();
$this->drupalGet('notices/mark-as-read');
$count = db_select('notices', 'n')
->condition('n.uid', $this->web_user->uid)
->condition('n.new', 1)
->countQuery()
->execute()
->fetchField();
$this->assertEqual(0, $count);
}
/**
* Test mark all notices as read, use ajax.
*/
public function testNoticesMarkAsReadAllAjax() {
$this->createNotice();
$this->drupalGet('ajax/notices/notices-mark-as-read');
$count = db_select('notices', 'n')
->condition('n.uid', $this->web_user->uid)
->condition('n.new', 1)
->countQuery()
->execute()
->fetchField();
$this->assertEqual(0, $count);
}
/**
* Test delete notice.
*/
public function testNoticesDelete() {
$this->createNotice();
$this->drupalPost('notices/delete/1', array(), t('Delete'));
$count = db_select('notices', 'n')
->condition('n.uid', $this->web_user->uid)
->countQuery()
->execute()
->fetchField();
$this->assertEqual(0, $count);
}
/**
* Test page with all user notices.
*/
public function testNoticesUserNotices() {
$node1 = $this->createNotice();
$node2 = $this->createNotice(1);
$node3 = $this->createNotice();
$this->drupalGet('user/' . $this->web_user->uid . '/notices');
$this->assertText($node1->message);
$this->assertNoText($node2->message);
$this->assertText($node3->message);
}
/**
* Create notice programmatically.
*/
protected function createNotice($uid = FALSE) {
if (!$uid) {
$uid = $this->web_user->uid;
}
$notice = new stdClass();
$notice->uid = $uid;
$notice->provider = $this->randomName();
$notice->subject = $this->randomName();
$notice->message = $this->randomName();
$notice->format = filter_default_format();
notices_save($notice);
return $notice;
}
}