#293907 by rastatt@drupal.org: Updated German translation
[project/privatemsg.git] / privatemsg.test
1 <?php
2 // $Id$
3 /**
4 * @file
5 * Test file for privatemsg.module
6 *
7 */
8
9 class PrivatemsgTestCase extends DrupalWebTestCase {
10 /**
11 * Implementation of getInfo().
12 */
13 function getInfo() {
14 return array
15 (
16 // 'name' should start with what is being tested (menu item) followed by what about it
17 // is being tested (creation/deletion).
18 'name' => t('Privatemsg functionality.'),
19 // 'description' should be one or more complete sentences that provide more details on what
20 // exactly is being tested.
21 'description' => t('Test sending, receiving, listing, deleting messages and other features.'),
22 // 'group' should be a logical grouping of test cases, like a category. In most cases, that
23 // is the module the test case is for.
24 'group' => t('Privatemsg'),
25 );
26 }
27
28 /**
29 * Implementation of setUp().
30 */
31 function setUp() {
32 parent::setUp('privatemsg');
33 }
34
35 /**
36 * Test user access to /messages
37 * Create user with no 'read privatemsg' permission. Try to access mailbox and see if it gives access denied error
38 * Create user with 'read privatemsg' permission. Try to access mailbox and see if it gives allows access
39 */
40 function testPrivatemsgReadPrivatemsgPermission() {
41 $user_no_read_msg = $this->drupalCreateUser(); // set up user with default permissions (meaning: no read privatemsg permission
42 $this->drupalLogin($user_no_read_msg);
43 $this->drupalGet('messages');
44 $this->assertResponse(403, t('HTTP Response 403: Access to mailbox was blocked to user without "<em>read privatemsg</em>" permission'));
45
46 $user_read_msg = $this->drupalCreateUser(array('read privatemsg')); // set up user with default permissions (meaning: no read privatemsg permission
47 $this->drupalLogin($user_read_msg);
48 $this->drupalGet('messages');
49 $this->assertResponse(200, t('HTTP Response 200: Access to mailbox was authorized to user with "<em>read privatemsg</em>" permission'));
50 }
51 /**
52 * Test user access to /messages/new
53 * Create user with no 'write privatemsg' permission. Try to access Write New Message page and see if it gives access denied error
54 * Create user with 'write privatemsg' permission. Try to access Write New Message page and see if it gives allows access
55 */
56 function testPrivatemsgWritePrivatemsgPermission() {
57 $user_no_write_msg = $this->drupalCreateUser(); // set up user with default permissions (meaning: no read privatemsg permission
58 $this->drupalLogin($user_no_write_msg);
59 $this->drupalGet('messages/new');
60 $this->assertResponse(403, t('HTTP Response 403: Access to Write New Message page was blocked to user without "<em>write privatemsg</em>" permission'));
61
62 $user_write_msg = $this->drupalCreateUser(array('write privatemsg')); // set up user with default permissions (meaning: no read privatemsg permission
63 $this->drupalLogin($user_write_msg);
64 $this->drupalGet('messages/new');
65 $this->assertResponse(200, t('HTTP Response 200: Access to Write New Message page was authorized to user with "<em>write privatemsg</em>" permission'));
66 }
67
68 /**
69 * Test sending message from the /messages/new page between two people
70 */
71 function testPrivatemsgWriteNewPrivatemsgFormSubmit() {
72 /**
73 * create an author and recipient users
74 */
75 $author = $this->drupalCreateUser(array('write privatemsg'));
76 $recipient = $this->drupalCreateUser(array('read privatemsg'));
77
78 /**
79 * login using author
80 * Fill navigate to privatemsg/new form, fill it out and submit
81 */
82 $this->drupalLogin($author);
83 $this->drupalGet('messages/new');
84
85 //assert if form is present //submit the form only if we found it
86 $xpath = '//form[@id="privatemsg-new"]';
87 if ( $this->assertTrue($this->xpath($xpath), 'Write New Message form successfuly found.', 'privatemsg') ) {
88 $edit = array( //create new message
89 'recipient' => $recipient->name,
90 'subject' => $this->randomName(20),
91 'body' => $this->randomName(100),
92 );
93 //submit our message
94 $this->drupalPost('messages/new', $edit, t('Send message'));
95 //check if we got successful confirmation
96 if ( $this->assertText(t('A message has been sent to @recipients.', array('@recipients' => $recipient->name)), 'Message sent confirmation displayed', 'privatemsg') ) {
97 /**
98 * Login using recipient and try to read the message by going to inbox first
99 * We do the test inside this conditional block because sending messages test much pass before we proceed to reading messages
100 */
101 $this->drupalLogin($recipient);
102 $this->drupalGet('messages');
103
104 //assert if we see the subject of the message
105 if ( $this->assertText(t('@text', array('@text' => $edit['subject'])), 'Sent Message subject found.', 'privatemsg') ) {
106 $this->clickLink(t('@text', array('@text' => $edit['subject']))); //navigate into the message
107 $this->assertText($edit['body'], 'Found Message body.', 'privatemsg'); //confirm that we can read the message that was sent
108 }
109 }
110 }
111 }
112
113
114 /**
115 * Implementation of tearDown().
116 */
117 function tearDown() {
118 //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.
119 parent::tearDown();
120 }
121
122 }
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140