You are here

protected function ProfileTestBase::setUp in Profile 8

Overrides BrowserTestBase::setUp

4 calls to ProfileTestBase::setUp()
ProfileDefaultTest::setUp in tests/src/Functional/ProfileDefaultTest.php
ProfileFieldAccessTest::setUp in tests/src/Functional/ProfileFieldAccessTest.php
ProfileRevisionTest::setUp in tests/src/Functional/ProfileRevisionTest.php
@inheritDoc
ProfileTypeTest::setUp in tests/src/Functional/ProfileTypeTest.php
4 methods override ProfileTestBase::setUp()
ProfileDefaultTest::setUp in tests/src/Functional/ProfileDefaultTest.php
ProfileFieldAccessTest::setUp in tests/src/Functional/ProfileFieldAccessTest.php
ProfileRevisionTest::setUp in tests/src/Functional/ProfileRevisionTest.php
@inheritDoc
ProfileTypeTest::setUp in tests/src/Functional/ProfileTypeTest.php

File

tests/src/Functional/ProfileTestBase.php, line 65

Class

ProfileTestBase
Tests profile access handling.

Namespace

Drupal\Tests\profile\Functional

Code

protected function setUp() {
  parent::setUp();
  $this
    ->drupalPlaceBlock('local_tasks_block');
  $this
    ->drupalPlaceBlock('local_actions_block');
  $this
    ->drupalPlaceBlock('page_title_block');
  $user_form_display = EntityFormDisplay::load("user.user.default");
  if (!$user_form_display) {
    $user_form_display = EntityFormDisplay::create([
      'targetEntityType' => 'user',
      'bundle' => 'user',
      'mode' => 'default',
      'status' => TRUE,
    ]);
    $user_form_display
      ->save();
  }
  $this->type = $this
    ->createProfileType('test', 'Test profile', TRUE);
  $id = $this->type
    ->id();
  $field_storage = FieldStorageConfig::create([
    'field_name' => 'profile_fullname',
    'entity_type' => 'profile',
    'type' => 'text',
  ]);
  $field_storage
    ->save();
  $this->field = FieldConfig::create([
    'field_storage' => $field_storage,
    'bundle' => $this->type
      ->id(),
    'label' => 'Full name',
  ]);
  $this->field
    ->save();

  // Configure the default display.
  $user_display = EntityViewDisplay::load("user.user.default");
  if (!$user_display) {
    $user_display = EntityViewDisplay::create([
      'targetEntityType' => 'user',
      'bundle' => 'user',
      'mode' => 'default',
      'status' => TRUE,
    ]);
    $user_display
      ->save();
  }

  // Configure the default display.
  $this->display = EntityViewDisplay::load("profile.{$this->type->id()}.default");
  if (!$this->display) {
    $this->display = EntityViewDisplay::create([
      'targetEntityType' => 'profile',
      'bundle' => $this->type
        ->id(),
      'mode' => 'default',
      'status' => TRUE,
    ]);
    $this->display
      ->save();
  }
  $this->display
    ->setComponent($this->field
    ->getName(), [
    'type' => 'string',
  ])
    ->save();

  // Configure the profile field display on user view modes.
  $profile_types = ProfileType::loadMultiple();
  foreach ($profile_types as $profile_type) {
    $field_name = $profile_type
      ->id() . '_profiles';

    // Assign display properties for the 'default' view mode.
    $user_display
      ->setComponent($field_name, [
      'label' => 'above',
      'type' => 'entity_reference_entity_view',
      'settings' => [
        'view_mode' => $this->display
          ->id(),
      ],
    ])
      ->save();
  }

  // Configure the default form.
  $this->form = EntityFormDisplay::load("profile.{$this->type->id()}.default");
  if (!$this->form) {
    $this->form = EntityFormDisplay::create([
      'targetEntityType' => 'profile',
      'bundle' => $this->type
        ->id(),
      'mode' => 'default',
      'status' => TRUE,
    ]);
    $this->form
      ->save();
  }
  $this->form
    ->setComponent($this->field
    ->getName(), [
    'type' => 'string_textfield',
  ])
    ->save();
  $this
    ->checkPermissions([
    'administer profile types',
    "create {$id} profile",
    "view own {$id} profile",
    "view any {$id} profile",
    "update own {$id} profile",
    "update any {$id} profile",
    "delete own {$id} profile",
    "delete any {$id} profile",
  ]);
  $this->adminUser = $this
    ->drupalCreateUser([
    'administer profile types',
    'administer profile',
    "view any {$id} profile",
    "create {$id} profile",
    "update any {$id} profile",
    "delete any {$id} profile",
  ]);
}