You are here

public function RngEventSettingsTest::testEvent in RNG - Events and Registrations 3.x

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

Create two bundles of the same entity type, one bundle is an event type.

Check if entities of each bundle are events.

File

src/Tests/RngEventSettingsTest.php, line 28

Class

RngEventSettingsTest
Tests event settings page.

Namespace

Drupal\rng\Tests

Code

public function testEvent() {
  $bundle[0] = $this->event_bundle;
  $bundle[1] = $this
    ->drupalCreateContentType();
  $bundle[2] = $this
    ->drupalCreateContentType();
  $event_types[0] = $this->event_type;
  $event_types[1] = $this
    ->createEventType('node', $bundle[2]
    ->id());
  \Drupal::service('router.builder')
    ->rebuildIfNeeded();
  $account = $this
    ->drupalCreateUser([
    'edit own ' . $bundle[0]
      ->id() . ' content',
    'edit own ' . $bundle[1]
      ->id() . ' content',
  ]);
  $this
    ->drupalLogin($account);
  $entity[0] = $this
    ->createEntity($bundle[0]);
  $entity[1] = $this
    ->createEntity($bundle[1]);
  $base_url = 'node/1';
  $this
    ->drupalGet($base_url);
  $this
    ->assertLinkByHref($base_url . '/event');
  $this
    ->drupalGet($base_url . '/event');
  $this
    ->assertResponse(200);
  $base_url = 'node/2';
  $this
    ->drupalGet($base_url);

  // Need for test for both existing and non existing links,
  // errors could show, and assertNoLink could be true.
  $this
    ->assertLinkByHref($base_url);
  $this
    ->assertNoLinkByHref($base_url . '/event');
  $this
    ->drupalGet($base_url . '/event');
  $this
    ->assertResponse(403);

  // Ensure that after removing an event type, the Event links do not persist
  // for other entities of the same entity type, but different bundle.
  foreach ([
    403,
    404,
  ] as $code) {
    $event_type = array_shift($event_types);
    $event_type
      ->delete();
    \Drupal::service('router.builder')
      ->rebuildIfNeeded();
    foreach ([
      'node/1',
      'node/2',
    ] as $base_url) {
      $this
        ->drupalGet($base_url . '/event');
      $this
        ->assertResponse($code);
      $this
        ->drupalGet($base_url);
      $this
        ->assertLinkByHref($base_url);
      $this
        ->assertNoLinkByHref($base_url . '/event');
    }
  }
}