View source
<?php
namespace Drupal\Tests\forward\Functional;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\Tests\BrowserTestBase;
abstract class ForwardTestBase extends BrowserTestBase {
protected static $modules = [
'forward',
'node',
'user',
'forward_test',
];
protected $defaultTheme = 'stark';
protected $webUser;
protected $forwardUser;
protected $adminUser;
protected function setUp() {
parent::setUp();
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();
$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);
}
}