function PrivateFileOnTranslatedEntityTest::setUp

Same name in other branches
  1. 9 core/modules/file/tests/src/Functional/PrivateFileOnTranslatedEntityTest.php \Drupal\Tests\file\Functional\PrivateFileOnTranslatedEntityTest::setUp()
  2. 10 core/modules/file/tests/src/Functional/PrivateFileOnTranslatedEntityTest.php \Drupal\Tests\file\Functional\PrivateFileOnTranslatedEntityTest::setUp()
  3. 11.x core/modules/file/tests/src/Functional/PrivateFileOnTranslatedEntityTest.php \Drupal\Tests\file\Functional\PrivateFileOnTranslatedEntityTest::setUp()

Overrides FileFieldTestBase::setUp

File

core/modules/file/tests/src/Functional/PrivateFileOnTranslatedEntityTest.php, line 35

Class

PrivateFileOnTranslatedEntityTest
Uploads private files to translated node and checks access.

Namespace

Drupal\Tests\file\Functional

Code

protected function setUp() {
    parent::setUp();
    // Create the "Basic page" node type.
    $this->drupalCreateContentType([
        'type' => 'page',
        'name' => 'Basic page',
    ]);
    // Create a file field on the "Basic page" node type.
    $this->fieldName = strtolower($this->randomMachineName());
    $this->createFileField($this->fieldName, 'node', 'page', [
        'uri_scheme' => 'private',
    ]);
    // Create and log in user.
    $permissions = [
        'access administration pages',
        'administer content translation',
        'administer content types',
        'administer languages',
        'create content translations',
        'create page content',
        'edit any page content',
        'translate any entity',
    ];
    $admin_user = $this->drupalCreateUser($permissions);
    $this->drupalLogin($admin_user);
    // Add a second language.
    $edit = [];
    $edit['predefined_langcode'] = 'fr';
    $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language'));
    // Enable translation for "Basic page" nodes.
    $edit = [
        'entity_types[node]' => 1,
        'settings[node][page][translatable]' => 1,
        "settings[node][page][fields][{$this->fieldName}]" => 1,
    ];
    $this->drupalPostForm('admin/config/regional/content-language', $edit, t('Save configuration'));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.