| Commit | Line | Data |
|---|---|---|
| 999a3158 | 1 | <?php |
| 999a3158 SG |
2 | /** |
| 3 | * @file | |
| 4 | * Test file for privatemsg_forward.module | |
| 5 | */ | |
| 6 | ||
| 7 | class PrivatemsgForwardTestCase extends DrupalWebTestCase { | |
| 8 | ||
| 9 | private $author; | |
| 10 | private $recipient1; | |
| 11 | private $recipient2; | |
| 12 | ||
| 13 | private $firstMessage; | |
| 14 | ||
| 15 | /** | |
| 16 | * Implements getInfo(). | |
| 17 | */ | |
| 18 | function getInfo() { | |
| 19 | return array( | |
| 20 | 'name' => t('Privatemsg forward functionality.'), | |
| 21 | 'description' => t('Test forward/remove myself features of the module.'), | |
| 22 | 'group' => t('Privatemsg'), | |
| 23 | ); | |
| 24 | } | |
| 25 | ||
| 26 | /** | |
| 27 | * Implements setUp(). | |
| 28 | */ | |
| 29 | function setUp() { | |
| 30 | parent::setUp('privatemsg', 'privatemsg_forward'); | |
| 31 | } | |
| 32 | ||
| 33 | /** | |
| 34 | * Test forwarding a thread. | |
| 35 | * | |
| 36 | * Including with/without sending a message and/or removing from the thread. | |
| 37 | */ | |
| 38 | function testForward() { | |
| 39 | $this->author = $this->drupalCreateUser(array('write privatemsg', 'read privatemsg')); | |
| 40 | $this->recipient1 = $this->drupalCreateUser(array('write privatemsg', 'read privatemsg', 'forward a privatemsg thread', 'remove from a privatemsg thread')); | |
| 41 | $this->recipient2 = $this->drupalCreateUser(array('write privatemsg', 'read privatemsg', 'forward a privatemsg thread')); | |
| 42 | ||
| 43 | // Just forward. | |
| 44 | $this->createThread(); | |
| 45 | $justForward = array('to' => $this->recipient2->name); | |
| 46 | $this->drupalPost(NULL, $justForward, t('Forward this conversation')); | |
| 47 | ||
| 48 | // Validate forwarding. | |
| 49 | $this->assertText($this->firstMessage['body'], t('Thread is still displayed')); | |
| 50 | $this->goToThread($this->recipient2); | |
| 51 | ||
| 52 | // Forward and remove myself. | |
| 53 | $this->createThread(); | |
| 54 | $forwardDelete = array( | |
| 55 | 'to' => $this->recipient2->name, | |
| 56 | 'remove' => TRUE, | |
| 57 | ); | |
| 58 | $this->drupalPost(NULL, $forwardDelete, t('Forward this conversation')); | |
| 59 | $this->assertNoText($this->firstMessage['subject'], t('User has been removed from thread')); | |
| 60 | $this->goToThread($this->recipient2); | |
| 61 | ||
| 62 | // Check that after sending a response, the thread is still hidden. | |
| 63 | $reply = array( | |
| 64 | 'body' => $this->randomName(100), | |
| 65 | ); | |
| 66 | $this->drupalPost(NULL, $reply, t('Send message')); | |
| 67 | $this->assertText($reply['body'], t('New reply is displayed')); | |
| 68 | $this->drupalLogin($this->recipient1); | |
| 69 | $this->drupalGet('messages'); | |
| 70 | $this->assertNoText($this->firstMessage['subject'], t('Forwarded has not recieved the reply')); | |
| 71 | ||
| 72 | //Forward and reply. | |
| 73 | $this->createThread(); | |
| 74 | $forwardReply = array( | |
| 75 | 'to' => $this->recipient2->name, | |
| 76 | 'body' => $this->randomName(200), | |
| 77 | ); | |
| 78 | // It is also possible to use the Send message button when there is a reply. | |
| 79 | $this->drupalPost(NULL, $forwardReply, t('Send message')); | |
| 80 | ||
| 81 | $this->assertText($forwardReply['body'], t('New reply is displayed')); | |
| 82 | $this->goToThread($this->recipient2, $forwardReply['body']); | |
| 83 | ||
| 84 | // Forward, reply and remove myself. | |
| 85 | $this->createThread(); | |
| 86 | $forwardReplyDelete = array( | |
| 87 | 'to' => $this->recipient2->name, | |
| 88 | 'remove' => TRUE, | |
| 89 | 'body' => $this->randomName(200), | |
| 90 | ); | |
| 91 | $this->drupalPost(NULL, $forwardReplyDelete, t('Forward this conversation')); | |
| 92 | ||
| 93 | // Additional forward because thread name is displayed as a info message. | |
| 94 | $this->assertNoText($this->firstMessage['subject'], t('User has been removed from thread')); | |
| 95 | $this->goToThread($this->recipient2, $forwardReplyDelete['body']); | |
| 96 | ||
| 97 | // Verify that the second recipient can see the forward fieldset but not | |
| 98 | // the remove myself button. | |
| 99 | $this->assertText(t('Forward conversation to others')); | |
| 100 | $this->assertNoText(t('Remove myself as a conversation participant')); | |
| 101 | ||
| 102 | // Remove only. | |
| 103 | $this->createThread(); | |
| 104 | $removeOnly = array( | |
| 105 | 'remove' => TRUE, | |
| 106 | ); | |
| 107 | $this->drupalPost(NULL, $removeOnly, t('Forward this conversation')); | |
| 108 | $this->assertText(t('You have been removed as a participant in the conversation.'), t('Confirmation message displayed.')); | |
| 109 | $this->assertNoText($this->firstMessage['subject'], t('User has been removed from thread')); | |
| 110 | ||
| 111 | // Remove and reply. | |
| 112 | $this->createThread(); | |
| 113 | $removeReply = array( | |
| 114 | 'remove' => TRUE, | |
| 115 | 'body' => $this->randomName(100), | |
| 116 | ); | |
| 117 | $this->drupalPost(NULL, $removeReply, t('Forward this conversation')); | |
| 118 | $this->assertText(t('You have been removed as a participant in the conversation.'), t('Confirmation message displayed.')); | |
| 119 | $this->assertNoText($this->firstMessage['subject'], t('User has been removed from thread')); | |
| 120 | $this->goToThread($this->author, $removeReply['body']); | |
| 121 | ||
| 122 | // Verify that the author can't see the forward fieldset. | |
| 123 | $this->assertNoText(t('Forward conversation to others')); | |
| 124 | } | |
| 125 | ||
| 126 | /** | |
| 127 | * Create the first message of a thread. | |
| 128 | */ | |
| 129 | function createThread() { | |
| 130 | $this->firstMessage = array( | |
| 131 | 'recipient' => $this->recipient1->name, | |
| 132 | 'subject' => $this->randomName(20), | |
| 133 | 'body' => $this->randomName(100), | |
| 134 | ); | |
| 135 | ||
| 136 | // Login author. | |
| 137 | $this->drupalLogin($this->author); | |
| 138 | ||
| 139 | // Submit the message. | |
| 140 | $this->drupalPost('messages/new', $this->firstMessage, t('Send message')); | |
| 141 | $this->assertText(t('A message has been sent to @recipients.', array('@recipients' => $this->recipient1->name)), 'Message sent confirmation displayed.'); | |
| 142 | ||
| 143 | // Login as recipient. | |
| 144 | $this->drupalLogin($this->recipient1); | |
| 145 | $this->drupalGet('messages'); | |
| 146 | $this->clickLink($this->firstMessage['subject']); | |
| 147 | } | |
| 148 | ||
| 149 | /** | |
| 150 | * Go to the currently active thread and check if the user can see it. | |
| 151 | */ | |
| 152 | function goToThread($user, $reply = NULL) { | |
| 153 | $this->drupalLogin($user); | |
| 154 | $this->drupalGet('messages'); | |
| 155 | $this->clickLink($this->firstMessage['subject']); | |
| 156 | $this->assertText($this->firstMessage['body'], t('Thread is displayed for user @username', array('@username' => $user->name))); | |
| 157 | ||
| 158 | // Check additional message if passed. | |
| 159 | if ($reply) { | |
| 160 | $this->assertText($reply, t('Reply is displayed.')); | |
| 161 | } | |
| 162 | } | |
| 163 | } |