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()
Same name and namespace in other branches
  1. 7.2 tests/registration.test \RegistrationAPITestCase::testHookAccess()
  2. 7 tests/registration.test \RegistrationAPITestCase::testHookAccess()

Test hook_registration_access().

File

tests/registration.test, line 597
Tests for the Registration module

Class

RegistrationAPITestCase

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');
  }
}