You are here

public function AuthcacheFormTestHelpers::testFormAllowNotoken in Authenticated User Page Caching (Authcache) 7.2

Cover _authcache_form_allow_notoken().

File

modules/authcache_form/tests/authcache_form.test, line 58
Test classes for Authcache Form module.

Class

AuthcacheFormTestHelpers
Test helper functions

Code

public function testFormAllowNotoken() {
  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);
  variable_set('authcache_form_notoken_roles', array(
    'custom' => TRUE,
    'roles' => $noroles,
  ));
  $result = _authcache_form_allow_notoken('some-form-id', $auser);
  $this
    ->assertFalse($result);
  $result = _authcache_form_allow_notoken('some-form-id', $puser);
  $this
    ->assertFalse($result);
  $result = _authcache_form_allow_notoken('some-form-id', $admin);
  $this
    ->assertFalse($result);
  $result = _authcache_form_allow_notoken('notoken-form-id', $auser);
  $this
    ->assertFalse($result);
  $result = _authcache_form_allow_notoken('notoken-form-id', $puser);
  $this
    ->assertFalse($result);
  $result = _authcache_form_allow_notoken('notoken-form-id', $admin);
  $this
    ->assertFalse($result);
  variable_set('authcache_form_notoken_roles', array(
    'custom' => TRUE,
    'roles' => $onlyauser,
  ));
  $result = _authcache_form_allow_notoken('some-form-id', $auser);
  $this
    ->assertFalse($result);
  $result = _authcache_form_allow_notoken('some-form-id', $puser);
  $this
    ->assertFalse($result);
  $result = _authcache_form_allow_notoken('some-form-id', $admin);
  $this
    ->assertFalse($result);
  $result = _authcache_form_allow_notoken('notoken-form-id', $auser);
  $this
    ->assertTrue($result);
  $result = _authcache_form_allow_notoken('notoken-form-id', $puser);
  $this
    ->assertFalse($result);
  $result = _authcache_form_allow_notoken('notoken-form-id', $admin);
  $this
    ->assertFalse($result);
  variable_set('authcache_form_notoken_roles', array(
    'custom' => TRUE,
    'roles' => $onlypuser,
  ));
  $result = _authcache_form_allow_notoken('some-form-id', $auser);
  $this
    ->assertFalse($result);
  $result = _authcache_form_allow_notoken('some-form-id', $puser);
  $this
    ->assertFalse($result);
  $result = _authcache_form_allow_notoken('some-form-id', $admin);
  $this
    ->assertFalse($result);
  $result = _authcache_form_allow_notoken('notoken-form-id', $auser);
  $this
    ->assertFalse($result);
  $result = _authcache_form_allow_notoken('notoken-form-id', $puser);
  $this
    ->assertTrue($result);
  $result = _authcache_form_allow_notoken('notoken-form-id', $admin);
  $this
    ->assertFalse($result);
  variable_del('authcache_form_notoken_roles');
  $result = _authcache_form_allow_notoken('some-form-id', $auser);
  $this
    ->assertFalse($result);
  $result = _authcache_form_allow_notoken('some-form-id', $puser);
  $this
    ->assertFalse($result);
  $result = _authcache_form_allow_notoken('some-form-id', $admin);
  $this
    ->assertFalse($result);
  $result = _authcache_form_allow_notoken('notoken-form-id', $auser);
  $this
    ->assertTrue($result);
  $result = _authcache_form_allow_notoken('notoken-form-id', $puser);
  $this
    ->assertTrue($result);
  $result = _authcache_form_allow_notoken('notoken-form-id', $admin);
  $this
    ->assertFalse($result);
}