/[drupal]/contributions/modules/shoutbox/tests/shoutbox_user_access.test
ViewVC logotype

Diff of /contributions/modules/shoutbox/tests/shoutbox_user_access.test

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.1.4.3, Tue Jul 15 08:11:18 2008 UTC revision 1.1.4.4, Tue Jul 29 09:05:21 2008 UTC
# Line 1  Line 1 
1  <?php  <?php
2    
3  // $Id: shoutbox_user_access.test,v 1.1.4.2 2008/07/15 07:55:29 disterics Exp $  // $Id: shoutbox_user_access.test,v 1.1.4.3 2008/07/15 08:11:18 disterics Exp $
4    
5  /**  /**
6   * @file   * @file
# Line 10  Line 10 
10   */   */
11    
12  class ShoutboxUserAccessTest extends DrupalTestCase {  class ShoutboxUserAccessTest extends DrupalTestCase {
13    
14    /**    /**
15     * A global basic user who is subject to moderation.     * A global basic user who is subject to moderation.
16     */     */
# Line 35  class ShoutboxUserAccessTest extends Dru Line 35  class ShoutboxUserAccessTest extends Dru
35    
36    function get_info() {    function get_info() {
37      return array(      return array(
38        'name' => t('User access'),        'name' => t('User access'),
39        'desc' => t('Test the user permissions of the shoutbox module.'),        'desc' => t('Test the user permissions of the shoutbox module.'),
40        'group' => t('Shoutbox Tests'),        'group' => t('Shoutbox Tests'),
41      );      );
42    }    }
43    
44    function setUp() {    function setUp() {
45      // TODO: Put your code here.      // TODO: Put your code here.
46      // enable module      // enable module
47      $this->drupalModuleEnable('shoutbox');      $this->drupalModuleEnable('shoutbox');
48      // enable nickname field      // enable nickname field
49      $this->drupalVariableSet('shoutbox_shownamefield', 1);      $this->drupalVariableSet('shoutbox_shownamefield', 1);
50      $permissions = array('post shouts',      $permissions = array('post shouts',
51                           'delete own shouts',                           'delete own shouts',
52                           'edit own shouts',                           'edit own shouts',
53      );      );
54      $basic_user = $this->drupalCreateUserRolePerm($permissions);      $basic_user = $this->drupalCreateUserRolePerm($permissions);
55      // unmoderated permission      // unmoderated permission
56      $permissions[] = 'post shouts without approval';      $permissions[] = 'post shouts without approval';
57      $unmoderated_user = $this->drupalCreateUserRolePerm($permissions);      $unmoderated_user = $this->drupalCreateUserRolePerm($permissions);
58    
59      $permissions = array(      $permissions = array(
60        'administer shoutbox',        'administer shoutbox',
61      );      );
# Line 74  class ShoutboxUserAccessTest extends Dru Line 74  class ShoutboxUserAccessTest extends Dru
74    
75      // Always call the setUp() function from the parent class.      // Always call the setUp() function from the parent class.
76      parent::setUp();      parent::setUp();
77    }    }
78    
79    
80    /**    /**
81     * Helper function to get the shout id     * Helper function to get the shout id
82     *     *
83     */     */
84    function _get_shout_id($shout) {    function _get_shout_id($shout) {
85      $shout_id = db_result(db_query("SELECT shout_id FROM {shoutbox} WHERE nick = '%s' AND shout = '%s' ", $shout['nick'], $shout['message']));      $shout_id = db_result(db_query("SELECT shout_id FROM {shoutbox} WHERE nick = '%s' AND shout = '%s' ", $shout['nick'], $shout['message']));
86      return $shout_id;      return $shout_id;
87    }    }
88    
89    
90    function testUnmoderatedUserAccess() {    function testUnmoderatedUserAccess() {
91    
92      // test add, edit and delete for a regular unmoderated user      // test add, edit and delete for a regular unmoderated user
93    
94      // Login as basic user to perform initial content creation.      // Login as basic user to perform initial content creation.
95      $this->drupalLoginUser($this->unmoderated_user);      $this->drupalLoginUser($this->unmoderated_user);
96       // Create an  unmoderated piece of content.       // Create an  unmoderated piece of content.
# Line 102  class ShoutboxUserAccessTest extends Dru Line 102  class ShoutboxUserAccessTest extends Dru
102      $this->assertWantedRaw(t('Your shout has been submitted.'));      $this->assertWantedRaw(t('Your shout has been submitted.'));
103      $this->assertWantedRaw(t($shout['message']));      $this->assertWantedRaw(t($shout['message']));
104    
105      // get the shout id      // get the shout id
106      $sid = $this->_get_shout_id($shout);      $sid = $this->_get_shout_id($shout);
107    
108      // edit the shout      // edit the shout
109      $edited_shout = array();      $edited_shout = array();
110      $edited_shout['shout']  = $this->randomName(10, 'shout');      $edited_shout['shout']  = $this->randomName(10, 'shout');
111      $url = 'shoutbox/'. $sid .'/edit';      $url = 'shoutbox/'. $sid .'/edit';
112      $this->drupalPost($url, $edited_shout, 'Update');      $this->drupalPost($url, $edited_shout, 'Update');
113      $this->assertWantedRaw(t('Your shout has been saved.'));      $this->assertWantedRaw(t('Your shout has been saved.'));
114      $this->assertWantedRaw(t($edited_shout['shout']));      $this->assertWantedRaw(t($edited_shout['shout']));
115    
116      // delete the shout      // delete the shout
117      $url = 'shoutbox/'. $sid .'/delete';      $url = 'shoutbox/'. $sid .'/delete';
118      $this->drupalPost($url, NULL, 'Confirm');      $this->drupalPost($url, NULL, 'Confirm');
119      $this->assertWantedRaw(t('Your shout was deleted.'));      $this->assertWantedRaw(t('Your shout was deleted.'));
120      $this->assertNoText(t($edited_shout['shout']));      $this->assertNoText(t($edited_shout['shout']));
121    
122      $url = url('logout', array('absolute' => TRUE));      $url = url('logout', array('absolute' => TRUE));
123      $this->get($url);      $this->get($url);
# Line 134  class ShoutboxUserAccessTest extends Dru Line 134  class ShoutboxUserAccessTest extends Dru
134      $this->drupalPost('node', $shout, 'Shout');      $this->drupalPost('node', $shout, 'Shout');
135      $this->assertWantedRaw(t('Your shout has been submitted for approval by a moderator. Others will not see this shout until it is approved.'));      $this->assertWantedRaw(t('Your shout has been submitted for approval by a moderator. Others will not see this shout until it is approved.'));
136    
137      // get the shout id      // get the shout id
138      $sid = $this->_get_shout_id($shout);      $sid = $this->_get_shout_id($shout);
139    
140      // edit the shout      // edit the shout
141      $edited_shout = array();      $edited_shout = array();
142      $edited_shout['shout']  = $this->randomName(10, 'shout');      $edited_shout['shout']  = $this->randomName(10, 'shout');
143      $url = 'shoutbox/'. $sid .'/edit';      $url = 'shoutbox/'. $sid .'/edit';
144      $this->drupalPost($url, $edited_shout, 'Update');      $this->drupalPost($url, $edited_shout, 'Update');
145      $this->assertWantedRaw(t('Your shout has been saved.'));      $this->assertWantedRaw(t('Your shout has been saved.'));
146      $this->assertWantedRaw(t($edited_shout['shout']));      $this->assertWantedRaw(t($edited_shout['shout']));
147    
148      // delete the shout      // delete the shout
149      $url = 'shoutbox/'. $sid .'/delete';      $url = 'shoutbox/'. $sid .'/delete';
150      $this->drupalPost($url, NULL, 'Confirm');      $this->drupalPost($url, NULL, 'Confirm');
151      $this->assertWantedRaw(t('Your shout was deleted.'));      $this->assertWantedRaw(t('Your shout was deleted.'));
152      $this->assertNoText(t($edited_shout['shout']));      $this->assertNoText(t($edited_shout['shout']));
153    
154      $url = url('logout', array('absolute' => TRUE));      $url = url('logout', array('absolute' => TRUE));
155      $this->get($url);      $this->get($url);
156    
157    }    }
158    
159    function testModerationUserAccess() {    function testModerationUserAccess() {
160      // now test moderation      // now test moderation
161      // create a moderated shout      // create a moderated shout
162    
163      $this->drupalLoginUser($this->basic_user);      $this->drupalLoginUser($this->basic_user);
164    
165      // Create an  unmoderated piece of content.      // Create an  unmoderated piece of content.
166      $shout = array();      $shout = array();
167      $shout['nick'] = $this->randomName(2, 'shout');      $shout['nick'] = $this->randomName(2, 'shout');
# Line 170  class ShoutboxUserAccessTest extends Dru Line 170  class ShoutboxUserAccessTest extends Dru
170      $this->drupalPost('node', $shout, 'Shout');      $this->drupalPost('node', $shout, 'Shout');
171      $this->assertWantedRaw(t('Your shout has been submitted for approval by a moderator. Others will not see this shout until it is approved.'));      $this->assertWantedRaw(t('Your shout has been submitted for approval by a moderator. Others will not see this shout until it is approved.'));
172    
173      // get the shout id      // get the shout id
174      $sid = $this->_get_shout_id($shout);      $sid = $this->_get_shout_id($shout);
175      // Try to moderate  it      // Try to moderate  it
176      $path = 'shoutbox/'. $sid .'/publish';      $path = 'shoutbox/'. $sid .'/publish';
177      $url = url($path, array('absolute' => TRUE));      $url = url($path, array('absolute' => TRUE));
178      $this->get($url);      $this->get($url);
179      $this->assertResponse(403);      $this->assertResponse(403);
180      // logout      // logout
181      $url = url('logout', array('absolute' => TRUE));      $url = url('logout', array('absolute' => TRUE));
182      $this->get($url);      $this->get($url);
183    
184      // login as moderator      // login as moderator
185      $this->drupalLoginUser($this->moderator);      $this->drupalLoginUser($this->moderator);
186      // moderate content      // moderate content
187      $path = 'shoutbox/'. $sid .'/publish';      $path = 'shoutbox/'. $sid .'/publish';
188      $url = url($path, array('absolute' => TRUE));      $url = url($path, array('absolute' => TRUE));
189      // verify confirmation page      // verify confirmation page
190      $this->get($url);      $this->get($url);
191      $this->assertText(t('Are you sure you want to publish this shout?'));      $this->assertText(t('Are you sure you want to publish this shout?'));
192      $this->drupalPost($path, NULL, 'Confirm');      $this->drupalPost($path, NULL, 'Confirm');
193      $this->assertText(t('The shout was published.'));      $this->assertText(t('The shout was published.'));
194    
195      // now unpublish it      // now unpublish it
196      $path = 'shoutbox/'. $sid .'/unpublish';      $path = 'shoutbox/'. $sid .'/unpublish';
197      $url = url($path, array('absolute' => TRUE));      $url = url($path, array('absolute' => TRUE));
198      // verify confirmation page      // verify confirmation page
199      $this->get($url);      $this->get($url);
200      $this->assertText(t('Are you sure you want to unpublish this shout?'));      $this->assertText(t('Are you sure you want to unpublish this shout?'));
201      $this->drupalPost($path, NULL, 'Confirm');      $this->drupalPost($path, NULL, 'Confirm');
202      $this->assertText(t('The shout was unpublished.'));      $this->assertText(t('The shout was unpublished.'));
203    
204      // try and edit it      // try and edit it
205      $path = 'shoutbox/'. $sid .'/edit';      $path = 'shoutbox/'. $sid .'/edit';
206      $url = url($path, array('absolute' => TRUE));      $url = url($path, array('absolute' => TRUE));
207      $this->get($url);      $this->get($url);
208      $this->assertResponse(403);      $this->assertResponse(403);
209    
210      // try and delete it      // try and delete it
211      $path = 'shoutbox/'. $sid .'/delete';      $path = 'shoutbox/'. $sid .'/delete';
212      $url = url($path, array('absolute' => TRUE));      $url = url($path, array('absolute' => TRUE));
213      $this->get($url);      $this->get($url);
214      $this->assertResponse(403);      $this->assertResponse(403);
215    
216        // delete shout
217        $this->cleanup($sid);
218    
219    
220      }
221    
222      function testAdminUserAccess() {
223        // test admin access
224        $this->drupalLoginUser($this->admin_user);
225    
226        // Create an unmoderated piece of content.
227        $shout = array();
228        $shout['nick'] = $this->randomName(2, 'shout');
229        $shout['message']  = $this->randomName(10, 'shout');
230        $shout['url'] = 'http://ghanaweb.com';
231        $this->drupalPost('node', $shout, 'Shout');
232        $this->assertWantedRaw(t('Your shout has been submitted.'));
233        $this->assertWantedRaw(t($shout['message']));
234    
235        // get the shout id
236        $sid = $this->_get_shout_id($shout);
237    
238        // moderate content
239        $path = 'shoutbox/'. $sid .'/unpublish';
240        // verify confirmation page
241        $this->drupalGet($path);
242        $this->assertWantedRaw(t('Are you sure you want to unpublish this shout?'));
243        $this->drupalPost($path, NULL, 'Confirm');
244        $this->assertText(t('The shout was unpublished.'));
245    
246        // un moderate it
247        $path = 'shoutbox/'. $sid .'/publish';
248        // verify confirmation page
249        $this->drupalGet($path);
250        $this->assertText(t('Are you sure you want to publish this shout?'));
251        $this->drupalPost($path, NULL, 'Confirm');
252        $this->assertText(t('The shout was published.'));
253    
254        // try and edit it
255        // edit the shout
256        $edited_shout = array();
257        $edited_shout['shout']  = $this->randomName(10, 'shout');
258        $url = 'shoutbox/'. $sid .'/edit';
259        $this->drupalPost($url, $edited_shout, 'Update');
260        $this->assertWantedRaw(t('The shout has been saved.'));
261        $this->assertWantedRaw(t($edited_shout['shout']));
262    
263        //delete it
264        // delete the shout
265        $url = 'shoutbox/'. $sid .'/delete';
266        $this->drupalPost($url, NULL, 'Confirm');
267        $this->assertWantedRaw(t('Your shout was deleted.'));
268        $this->assertNoText(t($edited_shout['shout']));
269    
270        // logout
271    
272        $this->drupalGet('logout');
273    
274        $this->cleanup($sid);
275    
276        // create a regular user content
277        // Login as basic user to perform initial content creation.
278        $this->drupalLoginUser($this->unmoderated_user);
279         // Create an  unmoderated piece of content.
280        $shout = array();
281        $shout['nick'] = $this->randomName(2, 'shout');
282        $shout['message']  = $this->randomName(10, 'shout');
283        $shout['url'] = 'http://slashdot.org';
284        $this->drupalPost('node', $shout, 'Shout');
285        $this->assertWantedRaw(t('Your shout has been submitted.'));
286        $this->assertWantedRaw(t($shout['message']));
287    
288        // get the shout id
289        $sid = $this->_get_shout_id($shout);
290    
291        // logout
292        $url = url('logout', array('absolute' => TRUE));
293        $this->get($url);
294    
295        // login as admin
296        $this->drupalLoginUser($this->admin_user);
297    
298      // delete shout      // moderate content
299        $path = 'shoutbox/'. $sid .'/unpublish';
300        // verify confirmation page
301        $this->drupalGet($path);
302        $this->assertText(t('Are you sure you want to unpublish this shout?'));
303        $this->drupalPost($path, NULL, 'Confirm');
304        $this->assertText(t('The shout was unpublished.'));
305    
306        // un moderate it
307        $path = 'shoutbox/'. $sid .'/publish';
308        // verify confirmation page
309        $this->drupalGet($path);
310        $this->assertText(t('Are you sure you want to publish this shout?'));
311        $this->drupalPost($path, NULL, 'Confirm');
312        $this->assertText(t('The shout was published.'));
313    
314        // try and edit it
315        // edit the shout
316        $edited_shout = array();
317        $edited_shout['shout']  = $this->randomName(10, 'shout');
318        $url = 'shoutbox/'. $sid .'/edit';
319        $this->drupalPost($url, $edited_shout, 'Update');
320        $this->assertWantedRaw(t('The shout has been saved.'));
321        $this->assertWantedRaw(t($edited_shout['shout']));
322    
323        //delete it
324        // delete the shout
325        $url = 'shoutbox/'. $sid .'/delete';
326        $this->drupalPost($url, NULL, 'Confirm');
327        $this->assertWantedRaw(t('Your shout was deleted.'));
328        $this->assertNoText(t($edited_shout['shout']));
329    
330    
331        // delete shout
332      $this->cleanup($sid);      $this->cleanup($sid);
333    
334    
335    }    }
336    
337    
338    function cleanup($shout_id) {    function cleanup($shout_id) {
339      db_query("DELETE FROM {shoutbox} WHERE shout_id = %d", $shout_id);      db_query("DELETE FROM {shoutbox} WHERE shout_id = %d", $shout_id);
340    }    }
341    
342    
343  }  }

Legend:
Removed from v.1.1.4.3  
changed lines
  Added in v.1.1.4.4

  ViewVC Help
Powered by ViewVC 1.1.2