You are here

protected function BadgeRoleTest::setUp in User Badges 8

Overrides KernelTestBase::setUp

File

tests/src/Kernel/Entity/BadgeRoleTest.php, line 35

Class

BadgeRoleTest
Test role_id behavior on badges.

Namespace

Drupal\Tests\user_badges\Kernel\Entity

Code

protected function setUp() {
  parent::setUp();

  // Installing needed schema.
  $this
    ->installConfig([
    'user_badges',
  ]);
  $this
    ->installEntitySchema('user');
  $this
    ->installEntitySchema('badge');
  $this
    ->installSchema('system', 'sequences');
  $role = Role::create([
    'id' => $this
      ->randomMachineName(),
  ]);
  $role
    ->save();
  $this->rids[] = $role
    ->id();
  $role = Role::create([
    'id' => $this
      ->randomMachineName(),
  ]);
  $role
    ->save();
  $this->rids[] = $role
    ->id();
  foreach ([
    [],
    $this->rids[0],
    $this->rids,
  ] as $rids) {
    $badge = Badge::create([
      'type' => 'image_badge',
      'name' => $this
        ->randomString(),
      'role_id' => $rids,
    ]);
    $badge
      ->save();
    $this->badgeIds[] = $badge
      ->id();
  }
}