function FieldExampleBrowserTestBase::setUp

Same name in other branches
  1. 4.0.x modules/field_example/tests/src/Functional/FieldExampleBrowserTestBase.php \Drupal\Tests\field_example\Functional\FieldExampleBrowserTestBase::setUp()

Once installed, a content type with the desired field is created.

Overrides ExamplesBrowserTestBase::setUp

File

modules/field_example/tests/src/Functional/FieldExampleBrowserTestBase.php, line 61

Class

FieldExampleBrowserTestBase
Class FieldExampleBrowserTestBase.

Namespace

Drupal\Tests\field_example\Functional

Code

protected function setUp() : void {
    // Install Drupal.
    parent::setUp();
    // Create and login a user that creates the content type.
    $permissions = [
        'administer content types',
        'administer node fields',
        'administer node form display',
        'administer node display',
    ];
    $this->administratorAccount = $this->drupalCreateUser($permissions);
    parent::drupalLogin($this->administratorAccount);
    // Prepare a new content type where the field will be added.
    $this->contentTypeName = strtolower($this->randomMachineName(10));
    $this->drupalGet('admin/structure/types/add');
    $edit = [
        'name' => $this->contentTypeName,
        'type' => $this->contentTypeName,
    ];
    $this->submitForm($edit, 'Save and manage fields');
    $this->assertSession()
        ->pageTextContains((string) new FormattableMarkup('The content type @name has been added.', [
        '@name' => $this->contentTypeName,
    ]));
    // Reset the permission cache.
    $create_permission = 'create ' . $this->contentTypeName . ' content';
    $this->checkPermissions([
        $create_permission,
    ]);
    // Now that we have a new content type, create a user that has privileges
    // on the content type.
    $this->authorAccount = $this->drupalCreateUser([
        $create_permission,
    ]);
}