You are here

public function AuthcacheP13nTestSettingBuilder::testSettingBuilderAccessChecker in Authenticated User Page Caching (Authcache) 7.2

Test request with access checker.

File

modules/authcache_p13n/tests/authcache_p13n.request-handler.test, line 801
Define unit tests for request handler.

Class

AuthcacheP13nTestSettingBuilder
Tests update functionality unrelated to the database.

Code

public function testSettingBuilderAccessChecker() {
  global $user;
  $orig_user = $user;
  $fake_user = (object) array(
    'uid' => 42,
    'mail' => 'fake@example.com',
    'name' => 'fake',
  );
  $settings = array(
    's1' => array(
      'renderer' => new AuthcacheP13nTestEchoSetting(),
      'target' => 'targetSetting',
      'validator' => NULL,
      'access' => new AuthcacheP13nTestEchoSettingAccess(),
    ),
  );
  $builder = new AuthcacheP13nSettingBuilder($settings);
  $user = $fake_user;
  $input = array(
    'a' => array(
      's1' => array(
        'account' => $fake_user,
      ),
    ),
  );
  try {
    $builder
      ->build($input, array());
    $this
      ->pass('AuthcacheP13nSettingBuilder should not throw an AuthcacheP13nRequestAccessDenied when access check succeeds');
  } catch (AuthcacheP13nRequestAccessDenied $e) {
    unset($e);
    $this
      ->fail('AuthcacheP13nSettingBuilder should not throw an AuthcacheP13nRequestAccessDenied when access check succeeds');
  }
  $user = $orig_user;
  $user = $fake_user;
  $input = array(
    'a' => array(
      's1' => array(
        'account' => FALSE,
      ),
    ),
  );
  try {
    $builder
      ->build($input, array());
    $this
      ->fail('AuthcacheP13nSettingBuilder should throw an AuthcacheP13nRequestAccessDenied when access check fails');
  } catch (AuthcacheP13nRequestAccessDenied $e) {
    unset($e);
    $this
      ->pass('AuthcacheP13nSettingBuilder should throw an AuthcacheP13nRequestAccessDenied when access check fails');
  }
  $user = $orig_user;
}