You are here

public function BlockAccessTest::setUp in Block Access 8

Overrides KernelTestBase::setUp

File

tests/src/Kernel/BlockAccessTest.php, line 89

Class

BlockAccessTest
Tests block access functionality.

Namespace

Drupal\Tests\block_access\Kernel

Code

public function setUp() {
  parent::setUp();
  $this
    ->installSchema('system', [
    'sequences',
  ]);
  $this
    ->installEntitySchema('block_content');
  $this
    ->installEntitySchema('user');

  // Setup some test entities.
  $this->blockType1 = BlockContentType::create([
    'id' => 'type1',
    'label' => 'name1',
  ]);
  $this->blockType1
    ->save();
  $this->blockType2 = BlockContentType::create([
    'id' => 'type2',
    'label' => 'name2',
  ]);
  $this->blockType2
    ->save();

  // First user is user 1, has all permissions.
  $this
    ->createUser();
  $this->user1 = $this
    ->createUser([
    'update any type1 block_content',
    'delete any type1 block_content',
    'create type1 block_content',
    'update own type2 block_content',
    'delete own type2 block_content',
  ]);
  $this->user2 = $this
    ->createUser([
    'update any type2 block_content',
    'delete any type2 block_content',
    'create type2 block_content',
    'update own type1 block_content',
    'delete own type1 block_content',
  ]);
  $this->user3 = $this
    ->createUser();
  $this->blockContent1 = BlockContent::create([
    'type' => 'type1',
    'info' => 'block1',
    'revision_user' => $this->user2
      ->id(),
  ]);
  $this->blockContent1
    ->save();
  $this->blockContent2 = BlockContent::create([
    'type' => 'type2',
    'info' => 'block2',
    'revision_user' => $this->user2
      ->id(),
  ]);
  $this->blockContent2
    ->save();
  $this->blockContent3 = BlockContent::create([
    'type' => 'type2',
    'info' => 'block3',
    'revision_user' => $this->user1
      ->id(),
  ]);
  $this->blockContent3
    ->save();
}