class ShoutboxUserAccessTest in Shoutbox 5
Same name and namespace in other branches
- 6 tests/shoutbox_user_access.test \ShoutboxUserAccessTest
@file shoutbox unit test for shoutbox_user_access and shoutbox_is_user_owned
Hierarchy
- class \DrupalTestCase extends \WebTestCase
- class \ShoutboxUserAccessTest
Expanded class hierarchy of ShoutboxUserAccessTest
File
- tests/
shoutbox_user_access.test, line 11 - shoutbox unit test for shoutbox_user_access and shoutbox_is_user_owned
View source
class ShoutboxUserAccessTest extends DrupalTestCase {
/**
* A global basic user who is subject to moderation.
*/
var $basic_user;
/**
* A global basic user who is not subject to moderation.
*/
var $unmoderated_user;
/**
* A global administrative user who may bypass all restrictions.
*/
var $admin_user;
/**
* A global administrative user who may bypass all restrictions.
*/
var $moderator;
/**
* A global variable to hold the shout id of the shout created.
* This enables deletion of the shout during tear down.
*/
var $shout_id;
function get_info() {
return array(
'name' => t('User access'),
'desc' => t('Verify that the correct user access blah'),
'group' => t('Shoutbox Tests'),
);
}
function setUp() {
// TODO: Put your code here.
// enable module
$this
->drupalModuleEnable('shoutbox');
// enable nickname field
$this
->drupalVariableSet('shoutbox_shownamefield', 1);
$permissions = array(
'post shouts',
'delete own shouts',
'edit own shouts',
);
$basic_user = $this
->drupalCreateUserRolePerm($permissions);
// unmoderated permission
$permissions[] = 'post shouts without approval';
$unmoderated_user = $this
->drupalCreateUserRolePerm($permissions);
$permissions = array(
'administer shoutbox',
);
$admin_user = $this
->drupalCreateUserRolePerm($permissions);
$permissions = array(
'moderate shoutbox',
);
$moderator = $this
->drupalCreateUserRolePerm($permissions);
// Assign users to their test suite-wide properties.
$this->basic_user = $basic_user;
$this->unmoderated_user = $unmoderated_user;
$this->admin_user = $admin_user;
$this->moderator = $moderator;
// Always call the setUp() function from the parent class.
parent::setUp();
}
/**
* Helper function to get the shout id
*
*/
function _get_shout_id($shout) {
$shout_id = db_result(db_query("SELECT shout_id FROM {shoutbox} WHERE nick = '%s' AND shout = '%s' ", $shout['nick'], $shout['message']));
return $shout_id;
}
function testShoutboxUserAccess() {
// test add, edit and delete for a regular unmoderated user
// Login as basic user to perform initial content creation.
$this
->drupalLoginUser($this->unmoderated_user);
// Create an unmoderated piece of content.
$shout = array();
$shout['nick'] = $this
->randomName(2, 'shout');
$shout['message'] = $this
->randomName(10, 'shout');
$shout['url'] = 'http://slashdot.org';
$this
->drupalPostRequest('node', $shout, 'Shout');
$this
->assertWantedRaw(t('Your shout has been submitted.'));
$this
->assertWantedRaw(t($shout['message']));
// get the shout id
$sid = $this
->_get_shout_id($shout);
// edit the shout
$edited_shout = array();
$edited_shout['shout'] = $this
->randomName(10, 'shout');
$url = 'shoutbox/' . $sid . '/edit';
$this
->drupalPostRequest($url, $edited_shout, 'Update');
$this
->assertWantedRaw(t('Your shout has been saved.'));
$this
->assertWantedRaw(t($edited_shout['shout']));
// delete the shout
$url = 'shoutbox/' . $sid . '/delete';
$this
->drupalPostRequest($url, NULL, 'Confirm');
$this
->assertWantedRaw(t('Your shout was deleted.'));
$this
->assertNoText(t($edited_shout['shout']));
$url = url('logout', NULL, NULL, TRUE);
$this
->get($url);
$this
->cleanup($sid);
// test add, edit and delete for a regular moderated user
$this
->drupalLoginUser($this->basic_user);
// Create an unmoderated piece of content.
$shout = array();
$shout['nick'] = $this
->randomName(2, 'shout');
$shout['message'] = $this
->randomName(10, 'shout');
$shout['url'] = 'http://slashdot.org';
$this
->drupalPostRequest('node', $shout, 'Shout');
$this
->assertWantedRaw(t('Your shout has been submitted for approval by a moderator. Others will not see this shout until it is approved.'));
// get the shout id
$sid = $this
->_get_shout_id($shout);
// edit the shout
$edited_shout = array();
$edited_shout['shout'] = $this
->randomName(10, 'shout');
$url = 'shoutbox/' . $sid . '/edit';
$this
->drupalPostRequest($url, $edited_shout, 'Update');
$this
->assertWantedRaw(t('Your shout has been saved.'));
$this
->assertWantedRaw(t($edited_shout['shout']));
// delete the shout
$url = 'shoutbox/' . $sid . '/delete';
$this
->drupalPostRequest($url, NULL, 'Confirm');
$this
->assertWantedRaw(t('Your shout was deleted.'));
$this
->assertNoText(t($edited_shout['shout']));
$url = url('logout', NULL, NULL, TRUE);
$this
->get($url);
$this
->cleanup($sid);
// now test moderation
// create a moderated shout
$this
->drupalLoginUser($this->basic_user);
// Create an unmoderated piece of content.
$shout = array();
$shout['nick'] = $this
->randomName(2, 'shout');
$shout['message'] = $this
->randomName(10, 'shout');
$shout['url'] = 'http://slashdot.org';
$this
->drupalPostRequest('node', $shout, 'Shout');
$this
->assertWantedRaw(t('Your shout has been submitted for approval by a moderator. Others will not see this shout until it is approved.'));
// get the shout id
$sid = $this
->_get_shout_id($shout);
// Try to moderate it
$path = 'shoutbox/' . $sid . '/publish';
$url = url($path, NULL, NULL, TRUE);
$this
->get($url);
$this
->assertResponse(403);
// logout
$url = url('logout', NULL, NULL, TRUE);
$this
->get($url);
// login as moderator
$this
->drupalLoginUser($this->moderator);
// moderate content
$path = 'shoutbox/' . $sid . '/publish';
$url = url($path, NULL, NULL, TRUE);
// verify confirmation page
$this
->get($url);
$this
->assertText(t('Are you sure you want to publish this shout?'));
$this
->drupalPostRequest($path, NULL, 'Confirm');
$this
->assertText(t('The shout was published.'));
// now unpublish it
$path = 'shoutbox/' . $sid . '/unpublish';
$url = url($path, NULL, NULL, TRUE);
// verify confirmation page
$this
->get($url);
$this
->assertText(t('Are you sure you want to unpublish this shout?'));
$this
->drupalPostRequest($path, NULL, 'Confirm');
$this
->assertText(t('The shout was unpublished.'));
// try and edit it
$path = 'shoutbox/' . $sid . '/edit';
$url = url($path, NULL, NULL, TRUE);
$this
->get($url);
$this
->assertResponse(403);
// try and delete it
$path = 'shoutbox/' . $sid . '/delete';
$url = url($path, NULL, NULL, TRUE);
$this
->get($url);
$this
->assertResponse(403);
$this
->cleanup($sid);
}
function testAdminUserAccess() {
// test admin access
$this
->drupalLoginUser($this->admin_user);
// Create an unmoderated piece of content.
$shout = array();
$shout['nick'] = $this
->randomName(2, 'shout');
$shout['message'] = $this
->randomName(10, 'shout');
$shout['url'] = 'http://ghanaweb.com';
$this
->drupalPostRequest('node', $shout, 'Shout');
$this
->assertWantedRaw(t('Your shout has been submitted.'));
$this
->assertWantedRaw(t($shout['message']));
// get the shout id
$sid = $this
->_get_shout_id($shout);
// moderate content
$path = 'shoutbox/' . $sid . '/unpublish';
// verify confirmation page
$url = url($path, NULL, NULL, TRUE);
$this
->get($url);
$this
->assertWantedRaw(t('Are you sure you want to unpublish this shout?'));
$this
->drupalPostRequest($path, NULL, 'Confirm');
$this
->assertText(t('The shout was unpublished.'));
// un moderate it
$path = 'shoutbox/' . $sid . '/publish';
// verify confirmation page
$url = url($path, NULL, NULL, TRUE);
$this
->get($url);
$this
->assertText(t('Are you sure you want to publish this shout?'));
$this
->drupalPostRequest($path, NULL, 'Confirm');
$this
->assertText(t('The shout was published.'));
// try and edit it
// edit the shout
$edited_shout = array();
$edited_shout['shout'] = $this
->randomName(10, 'shout');
$path = 'shoutbox/' . $sid . '/edit';
$this
->drupalPostRequest($path, $edited_shout, 'Update');
$this
->assertWantedRaw(t('The shout has been saved.'));
$this
->assertWantedRaw(t($edited_shout['shout']));
//delete it
// delete the shout
$path = 'shoutbox/' . $sid . '/delete';
$this
->drupalPostRequest($path, NULL, 'Confirm');
$this
->assertWantedRaw(t('Your shout was deleted.'));
$this
->assertNoText(t($edited_shout['shout']));
// logout
$url = url('logout', NULL, NULL, TRUE);
$this
->get($url);
$this
->cleanup($sid);
// create a regular user content
// Login as basic user to perform initial content creation.
$this
->drupalLoginUser($this->unmoderated_user);
// Create an unmoderated piece of content.
$shout = array();
$shout['nick'] = $this
->randomName(2, 'shout');
$shout['message'] = $this
->randomName(10, 'shout');
$shout['url'] = 'http://slashdot.org';
$this
->drupalPostRequest('node', $shout, 'Shout');
$this
->assertWantedRaw(t('Your shout has been submitted.'));
$this
->assertWantedRaw(t($shout['message']));
// get the shout id
$sid = $this
->_get_shout_id($shout);
// logout
$url = url('logout', NULL, NULL, TRUE);
$this
->get($url);
// login as admin
$this
->drupalLoginUser($this->admin_user);
// moderate content
$path = 'shoutbox/' . $sid . '/unpublish';
// verify confirmation page
$url = url($path, NULL, NULL, TRUE);
$this
->get($url);
$this
->assertText(t('Are you sure you want to unpublish this shout?'));
$this
->drupalPostRequest($path, NULL, 'Confirm');
$this
->assertText(t('The shout was unpublished.'));
// un moderate it
$path = 'shoutbox/' . $sid . '/publish';
// verify confirmation page
$url = url($path, NULL, NULL, TRUE);
$this
->get($url);
$this
->assertText(t('Are you sure you want to publish this shout?'));
$this
->drupalPostRequest($path, NULL, 'Confirm');
$this
->assertText(t('The shout was published.'));
// try and edit it
// edit the shout
$edited_shout = array();
$edited_shout['shout'] = $this
->randomName(10, 'shout');
$path = 'shoutbox/' . $sid . '/edit';
$this
->drupalPostRequest($path, $edited_shout, 'Update');
$this
->assertWantedRaw(t('The shout has been saved.'));
$this
->assertWantedRaw(t($edited_shout['shout']));
//delete it
// delete the shout
$path = 'shoutbox/' . $sid . '/delete';
$this
->drupalPostRequest($path, NULL, 'Confirm');
$this
->assertWantedRaw(t('Your shout was deleted.'));
$this
->assertNoText(t($edited_shout['shout']));
// delete shout
$this
->cleanup($sid);
}
function cleanup($shout_id) {
db_query("DELETE FROM {shoutbox} WHERE shout_id = %d", $shout_id);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DrupalTestCase:: |
property | |||
DrupalTestCase:: |
property | |||
DrupalTestCase:: |
property | |||
DrupalTestCase:: |
property | |||
DrupalTestCase:: |
property | |||
DrupalTestCase:: |
function | Will trigger a pass if both parameters refer to different objects. Fail otherwise. | ||
DrupalTestCase:: |
function | Will trigger a pass if the two parameters have the same value only. Otherwise a fail. | ||
DrupalTestCase:: |
function | Confirms that an error has occurred and optionally that the error text matches exactly. | ||
DrupalTestCase:: |
function | Confirms that an error has occurred and that the error text matches a Perl regular expression. | ||
DrupalTestCase:: |
function | Will trigger a pass if the two parameters have the same value and same type. Otherwise a fail. | ||
DrupalTestCase:: |
function | Type and class test. Will pass if class matches the type name or is a subclass or if not an object, but the type is correct. | ||
DrupalTestCase:: |
function | Confirms that no errors have occurred so far in the test method. | ||
DrupalTestCase:: |
function | Type and class mismatch test. Will pass if class name or underling type does not match the one specified. | ||
DrupalTestCase:: |
function | Will trigger a pass if the two parameters have a different value. Otherwise a fail. | ||
DrupalTestCase:: |
function | Will trigger a pass if the two parameters have the different value or different type. | ||
DrupalTestCase:: |
function | Will be true if the value is set. | ||
DrupalTestCase:: |
function | Will trigger a pass if the Perl regex pattern is not present in subject. Fail if found. | ||
DrupalTestCase:: |
function | Will trigger a pass if the raw text is NOT found on the loaded page Fail otherwise. | ||
DrupalTestCase:: |
function | Will be true if the value is null. | ||
DrupalTestCase:: |
function | Will trigger a pass if both parameters refer to the same object. Fail otherwise. | ||
DrupalTestCase:: |
function | Will trigger a pass if the Perl regex pattern is found in the subject. Fail otherwise. | ||
DrupalTestCase:: |
function | Will trigger a pass if the raw text is found on the loaded page Fail otherwise. | ||
DrupalTestCase:: |
function | Follows a link by name. Will click the first link found with this link text by default, or a later one if an index is given. Match is case insensitive with normalised space. Does make assertations if the click was sucessful or not and it does… | ||
DrupalTestCase:: |
function | @abstract Checks to see if we need to send a http-auth header to authenticate when browsing a site. | ||
DrupalTestCase:: |
function | Create a role / perm combination specified by permissions | ||
DrupalTestCase:: |
function | Creates a user / role / permissions combination specified by permissions | ||
DrupalTestCase:: |
function | @abstract Brokder for the get function adds the authentication headers if necessary @author Earnest Berry III <earnest.berry@gmail.com> | ||
DrupalTestCase:: |
function | @TODO: needs documentation | ||
DrupalTestCase:: |
function | Logs in a user with the internal browser | ||
DrupalTestCase:: |
function | Disables a drupal module | ||
DrupalTestCase:: |
function | Enables a drupal module | ||
DrupalTestCase:: |
function | Do a post request on a drupal page. It will be done as usual post request with SimpleBrowser | ||
DrupalTestCase:: |
function | @abstract Broker for the post function adds the authentication headers if necessary @author Earnest Berry III <earnest.berry@gmail.com> | ||
DrupalTestCase:: |
function | |||
DrupalTestCase:: |
function | Set a druapl variable and keep track of the changes for tearDown() | ||
DrupalTestCase:: |
function | Generates a random string, to be used as name or whatever | ||
DrupalTestCase:: |
function | Just some info for the reporter | ||
DrupalTestCase:: |
function | tearDown implementation, setting back switched modules etc | 1 | |
ShoutboxUserAccessTest:: |
property | A global administrative user who may bypass all restrictions. | ||
ShoutboxUserAccessTest:: |
property | A global basic user who is subject to moderation. | ||
ShoutboxUserAccessTest:: |
property | A global administrative user who may bypass all restrictions. | ||
ShoutboxUserAccessTest:: |
property | A global variable to hold the shout id of the shout created. This enables deletion of the shout during tear down. | ||
ShoutboxUserAccessTest:: |
property | A global basic user who is not subject to moderation. | ||
ShoutboxUserAccessTest:: |
function | |||
ShoutboxUserAccessTest:: |
function | |||
ShoutboxUserAccessTest:: |
function | |||
ShoutboxUserAccessTest:: |
function | |||
ShoutboxUserAccessTest:: |
function | |||
ShoutboxUserAccessTest:: |
function | Helper function to get the shout id |