You are here

protected function PrivateFileOnTranslatedEntityTest::setUp in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/file/tests/src/Functional/PrivateFileOnTranslatedEntityTest.php \Drupal\Tests\file\Functional\PrivateFileOnTranslatedEntityTest::setUp()
  2. 9 core/modules/file/tests/src/Functional/PrivateFileOnTranslatedEntityTest.php \Drupal\Tests\file\Functional\PrivateFileOnTranslatedEntityTest::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() : void {
  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
    ->drupalGet('admin/config/regional/language/add');
  $this
    ->submitForm($edit, '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
    ->drupalGet('admin/config/regional/content-language');
  $this
    ->submitForm($edit, 'Save configuration');
}