Newer
Older
The Great Git Migration
committed
<?php
// $Id$
/**
* @file
* Test file for privatemsg.module
*
*/
The Great Git Migration
committed
class PrivatemsgTestCase extends DrupalWebTestCase {
/**
* Implementation of getInfo().
*/
function getInfo() {
The Great Git Migration
committed
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
// 'name' should start with what is being tested (menu item) followed by what about it
// is being tested (creation/deletion).
'name' => t('Privatemsg functionality.'),
// 'description' should be one or more complete sentences that provide more details on what
// exactly is being tested.
'description' => t('Test sending, receiving, listing, deleting messages and other features.'),
// 'group' should be a logical grouping of test cases, like a category. In most cases, that
// is the module the test case is for.
'group' => t('Privatemsg'),
);
}
/**
* Implementation of setUp().
*/
function setUp() {
parent::setUp('privatemsg');
}
/**
* Test user access to /messages
* Create user with no 'read privatemsg' permission. Try to access mailbox and see if it gives access denied error
* Create user with 'read privatemsg' permission. Try to access mailbox and see if it gives allows access
*/
function testPrivatemsgReadPrivatemsgPermission() {
$user_no_read_msg = $this->drupalCreateUser(); // set up user with default permissions (meaning: no read privatemsg permission
$this->drupalLogin($user_no_read_msg);
$this->drupalGet('messages');
$this->assertResponse(403, t('HTTP Response 403: Access to mailbox was blocked to user without "<em>read privatemsg</em>" permission'));
$user_read_msg = $this->drupalCreateUser(array('read privatemsg')); // set up user with default permissions (meaning: no read privatemsg permission
$this->drupalLogin($user_read_msg);
$this->drupalGet('messages');
$this->assertResponse(200, t('HTTP Response 200: Access to mailbox was authorized to user with "<em>read privatemsg</em>" permission'));
}
/**
* Test user access to /messages/new
* Create user with no 'write privatemsg' permission. Try to access Write New Message page and see if it gives access denied error
* Create user with 'write privatemsg' permission. Try to access Write New Message page and see if it gives allows access
*/
function testPrivatemsgWritePrivatemsgPermission() {
$user_no_write_msg = $this->drupalCreateUser(); // set up user with default permissions (meaning: no read privatemsg permission
$this->drupalLogin($user_no_write_msg);
$this->drupalGet('messages/new');
$this->assertResponse(403, t('HTTP Response 403: Access to Write New Message page was blocked to user without "<em>write privatemsg</em>" permission'));
$user_write_msg = $this->drupalCreateUser(array('write privatemsg')); // set up user with default permissions (meaning: no read privatemsg permission
$this->drupalLogin($user_write_msg);
$this->drupalGet('messages/new');
$this->assertResponse(200, t('HTTP Response 200: Access to Write New Message page was authorized to user with "<em>write privatemsg</em>" permission'));
}
/**
* Test sending message from the /messages/new page between two people
*/
function testPrivatemsgWriteNewPrivatemsgFormSubmit() {
/**
* create an author and recipient users
*/
$author = $this->drupalCreateUser(array('write privatemsg'));
$recipient = $this->drupalCreateUser(array('read privatemsg'));
/**
* login using author
* Fill navigate to privatemsg/new form, fill it out and submit
*/
$this->drupalLogin($author);
$this->drupalGet('messages/new');
//assert if form is present //submit the form only if we found it
$xpath = '//form[@id="privatemsg-new"]';
if ( $this->assertTrue($this->xpath($xpath), 'Write New Message form successfuly found.', 'privatemsg') ) {
$edit = array( //create new message
'recipient' => $recipient->name,
'subject' => $this->randomName(20),
'body' => $this->randomName(100),
);
//submit our message
$this->drupalPost('messages/new', $edit, t('Send message'));
//check if we got successful confirmation
if ( $this->assertText(t('A message has been sent to @recipients.', array('@recipients' => $recipient->name)), 'Message sent confirmation displayed', 'privatemsg') ) {
/**
* Login using recipient and try to read the message by going to inbox first
* We do the test inside this conditional block because sending messages test much pass before we proceed to reading messages
*/
$this->drupalLogin($recipient);
$this->drupalGet('messages');
//assert if we see the subject of the message
if ( $this->assertText(t('@text', array('@text' => $edit['subject'])), 'Sent Message subject found.', 'privatemsg') ) {
$this->clickLink(t('@text', array('@text' => $edit['subject']))); //navigate into the message
$this->assertText($edit['body'], 'Found Message body.', 'privatemsg'); //confirm that we can read the message that was sent
}
}
}
}
/**
* Implementation of tearDown().
*/
function tearDown() {
//we dont really need to do this. i'm adding it just to keep it in front of my eyes so i can memorize it.
parent::tearDown();
}
}