You are here

function RegistrationAPITestCase::testHookAccess in Entity Registration 8.2

Same name in this branch
  1. 8.2 tests/registration.test \RegistrationAPITestCase::testHookAccess()
  2. 8.2 src/RegistrationAPITestCase.php \Drupal\registration\RegistrationAPITestCase::testHookAccess()

Test hook_registration_access().

File

src/RegistrationAPITestCase.php, line 21

Class

RegistrationAPITestCase

Namespace

Drupal\registration

Code

function testHookAccess() {
  $account = $this
    ->drupalCreateUser();
  $crud = array(
    'create',
    'view',
    'update',
    'delete',
  );
  $registration_values = array(
    'registrant_id' => $account->uid,
  );

  // Test hook.
  $registration = $this
    ->createRegistration($registration_values);
  $random = $this
    ->randomString();
  $registration->hook_registration_access = $random;
  $this
    ->assertEqual($random, \Drupal::moduleHandler()
    ->invoke('registration_test_api', 'registration_access', [
    'view',
    $registration,
    $account,
  ]), t('Manually invoke hook_registration_access()'), 'Registration');

  // Default access (none).
  foreach ($crud as $op) {
    $registration = $this
      ->createRegistration();
    $this
      ->assertFalse(entity_access($op, 'registration', $registration, $account), t('User cannot @op registration.', array(
      '@op' => $op,
    )), 'Registration');
  }

  // Force allow access.
  foreach ($crud as $op) {
    $registration = $this
      ->createRegistration($registration_values);
    $registration->hook_registration_access = TRUE;
    $this
      ->assertTrue(entity_access($op, 'registration', $registration, $account), t('User can @op registration.', array(
      '@op' => $op,
    )), 'Registration');
  }
}