You are here

public function ScheduledTransitionEntityTest::testAccessByBundle in Scheduled Transitions 8

Same name and namespace in other branches
  1. 2.x tests/src/Functional/ScheduledTransitionEntityTest.php \Drupal\Tests\scheduled_transitions\Functional\ScheduledTransitionEntityTest::testAccessByBundle()

Tests transition pages access depending on enabled entity type/bundle.

File

tests/src/Functional/ScheduledTransitionEntityTest.php, line 51

Class

ScheduledTransitionEntityTest
Tests an entity with scheduled transitions capabilities.

Namespace

Drupal\Tests\scheduled_transitions\Functional

Code

public function testAccessByBundle() {
  $this
    ->enabledBundles([
    [
      'st_entity_test',
      'st_entity_test',
    ],
  ]);
  $workflow = $this
    ->createEditorialWorkflow();
  $workflow
    ->getTypePlugin()
    ->addEntityTypeAndBundle('st_entity_test', 'st_entity_test');
  $workflow
    ->save();
  $currentUser = $this
    ->drupalCreateUser([
    'administer st_entity_test entities',
    'use editorial transition create_new_draft',
    'use editorial transition publish',
    'use editorial transition archive',
    'view scheduled transitions st_entity_test st_entity_test',
  ]);
  $this
    ->drupalLogin($currentUser);
  $entity = ScheduledTransitionsTestEntity::create([
    'type' => 'st_entity_test',
  ]);
  $entity
    ->save();
  $this
    ->drupalGet($entity
    ->toUrl(ScheduledTransitionsRouteProvider::LINK_TEMPLATE));
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  \Drupal::configFactory()
    ->getEditable('scheduled_transitions.settings')
    ->set('bundles', [])
    ->save(TRUE);
  Cache::invalidateTags([
    SettingsForm::SETTINGS_TAG,
  ]);
  $this
    ->drupalGet($entity
    ->toUrl(ScheduledTransitionsRouteProvider::LINK_TEMPLATE));
  $this
    ->assertSession()
    ->statusCodeEquals(403);
}