function ContactAttachSettingsFormTestCase::testContactAttachSettingsForm in Contact Attach 7
Tests the module settings form with granted permissions for various roles.
File
- ./
contact_attach.test, line 36 - Tests for the Contact Attach module.
Class
- ContactAttachSettingsFormTestCase
- Tests the Contact Attach settings form.
Code
function testContactAttachSettingsForm() {
$admin_user = $this
->drupalCreateUser(array(
'administer site configuration',
));
$this
->drupalLogin($admin_user);
$this
->drupalGet('admin/config/media/contact_attach');
$this
->assertResponse(200);
$this
->assertUniqueText(t('Settings for the site-wide contact form'));
$this
->assertUniqueText(t('Settings for personal contact forms'));
$this
->assertNoText(t('Use simple file field.'));
module_enable(array(
'file',
), FALSE);
$this
->drupalGet('admin/config/media/contact_attach');
$this
->assertUniqueText(t('Use simple file field.'));
// Check that setting the simple field type setting works.
$this
->drupalPost('admin/config/media/contact_attach', array(
'contact_attach_simple_field' => 1,
), t('Save configuration'));
$this
->assertUniqueText(t('The configuration options have been saved.'), 'Settings successfully saved.');
$this
->assertRaw('name="contact_attach_simple_field" value="1" checked="checked"', 'Setting contact_attach_simple_field was fetched properly after being saved.');
$this
->drupalPost('admin/config/media/contact_attach', array(
'contact_attach_simple_field' => FALSE,
), t('Save configuration'));
$this
->assertUniqueText(t('The configuration options have been saved.'), 'Settings successfully saved.');
$this
->assertRaw('name="contact_attach_simple_field" value="1" cl', 'Setting contact_attach_simple_field was fetched properly after being saved.');
// Check that the administrator role is listed on the settings page even
// when not having set permissions and test that we can define its settings.
$this
->checkPermittedRoleOnSettingsPage(variable_get('user_admin_role'), FALSE);
// Check that the anonymous role is listed on the settings page after
// granting it permissions and test that we can define its settings.
$anon_role = $this
->checkPermittedRoleOnSettingsPage(DRUPAL_ANONYMOUS_RID);
// Check that the anonymous role is not listed on the settings page after
// revoking its permissions.
$this
->revokePermsAndCheckIfRoleNotListed($anon_role);
$admin_user_roles = $admin_user->roles;
unset($admin_user_roles[DRUPAL_AUTHENTICATED_RID]);
reset($admin_user_roles);
$created_role_rid = key($admin_user_roles);
// Check that the created role is listed on the settings page after granting
// it permissions and test that we can define its settings.
$created_role = $this
->checkPermittedRoleOnSettingsPage($created_role_rid);
// Check that the created role is not listed on the settings page after
// revoking its permissions.
$this
->revokePermsAndCheckIfRoleNotListed($created_role);
// Check that the authenticated user role is listed on the settings page
// after granting it permissions and test that we can define its settings.
$auth_role = $this
->checkPermittedRoleOnSettingsPage(DRUPAL_AUTHENTICATED_RID);
// Check that the role created when the admin user was created is listed on
// the settings page after granting the authenticated user role permissions
// and test that we can define its settings.
$this
->checkPermittedRoleOnSettingsPage($created_role->rid, FALSE);
// Check that the authenticated user role and the created role that inherit
// the permissions are not listed on the settings page after revoking the
// permissions of the authenticated user role.
$this
->revokePermsAndCheckIfRoleNotListed($auth_role, array(
$created_role->name,
));
}