public function AuthcacheFormTestHelpers::testFormAllowP13n in Authenticated User Page Caching (Authcache) 7.2
Cover _authcache_form_allow_p13n().
File
- modules/
authcache_form/ tests/ authcache_form.test, line 152 - Test classes for Authcache Form module.
Class
- AuthcacheFormTestHelpers
- Test helper functions
Code
public function testFormAllowP13n() {
variable_set('authcache_form_notoken', 'notoken-form-id');
$auser = $this
->drupalCreateUser();
// Work around #1873606.
user_save($auser, array(
'roles' => array(
DRUPAL_AUTHENTICATED_RID => DRUPAL_AUTHENTICATED_RID,
),
));
$puser = $this
->drupalCreateUser(array(
'access content',
));
$admin = $this
->drupalCreateUser(array(
'administer nodes',
));
$noroles = array();
$onlyauser = $auser->roles;
$onlypuser = $puser->roles;
unset($onlypuser[DRUPAL_AUTHENTICATED_RID]);
$allusers = $onlyauser + $onlypuser;
// All users but admin are allowed.
variable_set('authcache_roles', $allusers);
// First pass: authcache personalization module disabled.
variable_set('authcache_form_roles', array(
'custom' => TRUE,
'roles' => $noroles,
));
$result = _authcache_form_allow_p13n('ignored-form-id', $auser);
$this
->assertFalse($result);
$result = _authcache_form_allow_p13n('ignored-form-id', $puser);
$this
->assertFalse($result);
$result = _authcache_form_allow_p13n('ignored-form-id', $admin);
$this
->assertFalse($result);
variable_set('authcache_form_roles', array(
'custom' => TRUE,
'roles' => $onlyauser,
));
$result = _authcache_form_allow_p13n('ignored-form-id', $auser);
$this
->assertFalse($result);
$result = _authcache_form_allow_p13n('ignored-form-id', $puser);
$this
->assertFalse($result);
$result = _authcache_form_allow_p13n('ignored-form-id', $admin);
$this
->assertFalse($result);
variable_set('authcache_form_roles', array(
'custom' => TRUE,
'roles' => $onlypuser,
));
$result = _authcache_form_allow_p13n('ignored-form-id', $auser);
$this
->assertFalse($result);
$result = _authcache_form_allow_p13n('ignored-form-id', $puser);
$this
->assertFalse($result);
$result = _authcache_form_allow_p13n('ignored-form-id', $admin);
$this
->assertFalse($result);
variable_del('authcache_form_roles');
$result = _authcache_form_allow_p13n('ignored-form-id', $auser);
$this
->assertFalse($result);
$result = _authcache_form_allow_p13n('ignored-form-id', $puser);
$this
->assertFalse($result);
$result = _authcache_form_allow_p13n('ignored-form-id', $admin);
$this
->assertFalse($result);
// Second pass: authcache personalization module enabled.
module_enable(array(
'authcache_p13n',
));
$this
->resetAll();
variable_set('authcache_form_roles', array(
'custom' => TRUE,
'roles' => $noroles,
));
$result = _authcache_form_allow_p13n('ignored-form-id', $auser);
$this
->assertFalse($result);
$result = _authcache_form_allow_p13n('ignored-form-id', $puser);
$this
->assertFalse($result);
$result = _authcache_form_allow_p13n('ignored-form-id', $admin);
$this
->assertFalse($result);
variable_set('authcache_form_roles', array(
'custom' => TRUE,
'roles' => $onlyauser,
));
$result = _authcache_form_allow_p13n('ignored-form-id', $auser);
$this
->assertTrue($result);
$result = _authcache_form_allow_p13n('ignored-form-id', $puser);
$this
->assertFalse($result);
$result = _authcache_form_allow_p13n('ignored-form-id', $admin);
$this
->assertFalse($result);
variable_set('authcache_form_roles', array(
'custom' => TRUE,
'roles' => $onlypuser,
));
$result = _authcache_form_allow_p13n('ignored-form-id', $auser);
$this
->assertFalse($result);
$result = _authcache_form_allow_p13n('ignored-form-id', $puser);
$this
->assertTrue($result);
$result = _authcache_form_allow_p13n('ignored-form-id', $admin);
$this
->assertFalse($result);
variable_del('authcache_form_roles');
$result = _authcache_form_allow_p13n('ignored-form-id', $auser);
$this
->assertTrue($result);
$result = _authcache_form_allow_p13n('ignored-form-id', $puser);
$this
->assertTrue($result);
$result = _authcache_form_allow_p13n('ignored-form-id', $admin);
$this
->assertFalse($result);
module_disable(array(
'authcache_p13n',
));
$this
->resetAll();
}