You are here

protected function ForwardTestBase::setUp in Forward 4.x

Same name and namespace in other branches
  1. 4.0.x tests/src/Functional/ForwardTestBase.php \Drupal\Tests\forward\Functional\ForwardTestBase::setUp()

Perform any initial set up tasks that run before every test method.

Overrides BrowserTestBase::setUp

File

tests/src/Functional/ForwardTestBase.php, line 48

Class

ForwardTestBase
Provides a base class for testing the Forward module.

Namespace

Drupal\Tests\forward\Functional

Code

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

  // Create Basic page and Article node types.
  if ($this->profile != 'standard') {
    $this
      ->drupalCreateContentType([
      'type' => 'page',
      'name' => 'Basic page',
      'display_submitted' => FALSE,
    ]);
    $this
      ->drupalCreateContentType([
      'type' => 'article',
      'name' => 'Article',
    ]);
  }
  $this->entityType = 'node';
  $this->bundle = 'article';
  $this->fieldName = mb_strtolower($this
    ->randomMachineName());
  $field_storage = FieldStorageConfig::create([
    'field_name' => $this->fieldName,
    'entity_type' => $this->entityType,
    'type' => 'forward',
  ]);
  $field_storage
    ->save();
  $instance = FieldConfig::create([
    'field_storage' => $field_storage,
    'bundle' => $this->bundle,
    'label' => $this
      ->randomMachineName(),
  ]);
  $instance
    ->save();
  $values = [
    'targetEntityType' => $this->entityType,
    'bundle' => $this->bundle,
    'mode' => 'default',
    'status' => TRUE,
  ];
  $this->display = \Drupal::entityTypeManager()
    ->getStorage('entity_view_display')
    ->load('node.article.default');
  $this->display
    ->setComponent($this->fieldName, [
    'type' => 'forward_link',
    'settings' => [
      'title' => 'Forward this [forward:entity-type] to a friend',
      'style' => 2,
      'icon' => '',
      'nofollow' => TRUE,
    ],
  ]);
  $this->display
    ->save();

  // Create test users.
  $this->webUser = $this
    ->drupalCreateUser([
    'access content',
  ]);
  $this->forwardUser = $this
    ->drupalCreateUser([
    'access content',
    'access forward',
  ]);
  $permissions = [
    'access forward',
    'administer forward',
    'administer users',
    'bypass node access',
  ];
  $this->adminUser = $this
    ->drupalCreateUser($permissions);
}