You are here

function RegistrationAPITestCase::testHookAccess in Entity Registration 7

Same name and namespace in other branches
  1. 8.2 tests/registration.test \RegistrationAPITestCase::testHookAccess()
  2. 7.2 tests/registration.test \RegistrationAPITestCase::testHookAccess()

Test hook_registration_access().

File

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

Class

RegistrationAPITestCase

Code

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

  // Test hook.
  $registration = $this
    ->createRegistration($registration_values);
  $random = $this
    ->randomString();
  $registration->hook_registration_access = $random;
  $this
    ->assertEqual($random, module_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');
  }
}