You are here

public function RngEventAccessTest::testComponentAccessDefaultsCache in RNG - Events and Registrations 3.x

Same name and namespace in other branches
  1. 8.2 src/Tests/RngEventAccessTest.php \Drupal\rng\Tests\RngEventAccessTest::testComponentAccessDefaultsCache()
  2. 8 src/Tests/RngEventAccessTest.php \Drupal\rng\Tests\RngEventAccessTest::testComponentAccessDefaultsCache()

Test access from event type rule defaults.

Ensure if these rules change they invalidate caches.

File

src/Tests/RngEventAccessTest.php, line 130

Class

RngEventAccessTest
Tests event access.

Namespace

Drupal\rng\Tests

Code

public function testComponentAccessDefaultsCache() {

  // Create a rule as a baseline.
  $rule = EventTypeRule::create([
    'trigger' => 'rng_event.register',
    'entity_type' => 'entity_test',
    'bundle' => 'entity_test',
    'machine_name' => 'user_role',
  ]);
  $rule
    ->setCondition('role', [
    'id' => 'rng_user_role',
    'roles' => [],
  ]);
  $rule
    ->setAction('registration_operations', [
    'id' => 'registration_operations',
    'configuration' => [
      'operations' => [],
    ],
  ]);
  $rule
    ->save();
  $event = EntityTest::create([
    EventManagerInterface::FIELD_REGISTRATION_TYPE => $this->registration_type
      ->id(),
    EventManagerInterface::FIELD_STATUS => TRUE,
  ]);
  $event
    ->save();
  $register_link = Url::fromRoute('rng.event.entity_test.register.type_list', [
    'entity_test' => $event
      ->id(),
  ]);
  $register_link_str = $register_link
    ->toString();
  $user_registrant = $this
    ->drupalCreateUser([
    'rng register self',
    'view test entity',
    'administer entity_test content',
  ]);
  $this
    ->drupalLogin($user_registrant);
  $this
    ->drupalGet($event
    ->toUrl());
  $this
    ->assertResponse(200);
  $this
    ->assertNoLinkByHref($register_link_str);
  $this
    ->drupalGet($register_link);
  $this
    ->assertResponse(403);
  $admin = $this
    ->drupalCreateUser([
    'administer event types',
  ]);
  $this
    ->drupalLogin($admin);
  $edit['actions[operations][user_role][create]'] = TRUE;
  $this
    ->drupalPostForm('admin/structure/rng/event_types/manage/entity_test.entity_test/access_defaults', $edit, t('Save'));
  $this
    ->drupalLogin($user_registrant);
  $this
    ->drupalGet($event
    ->toUrl());
  $this
    ->assertResponse(200);
  $this
    ->assertLinkByHref($register_link_str);
  $this
    ->drupalGet($register_link);
  $this
    ->assertResponse(200);
}