function FileOnTranslatedEntityTest::setUp

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

Overrides FileFieldTestBase::setUp

File

core/modules/file/tests/src/Functional/FileOnTranslatedEntityTest.php, line 34

Class

FileOnTranslatedEntityTest
Uploads files to translated nodes.

Namespace

Drupal\Tests\file\Functional

Code

protected function setUp() : void {
    parent::setUp();
    // This test expects unused managed files to be marked as temporary a file.
    $this->config('file.settings')
        ->set('make_unused_managed_files_temporary', TRUE)
        ->save();
    // Create the "Basic page" node type.
    // @todo Remove the disabling of new revision creation in
    //   https://www.drupal.org/node/1239558.
    $this->drupalCreateContentType([
        'type' => 'page',
        'name' => 'Basic page',
        'new_revision' => FALSE,
    ]);
    // Create a file field on the "Basic page" node type.
    $this->fieldName = strtolower($this->randomMachineName());
    $this->createFileField($this->fieldName, 'node', 'page');
    // 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',
        'delete any page content',
    ];
    $admin_user = $this->drupalCreateUser($permissions);
    $this->drupalLogin($admin_user);
    // Add a second and third language.
    $edit = [];
    $edit['predefined_langcode'] = 'fr';
    $this->drupalGet('admin/config/regional/language/add');
    $this->submitForm($edit, 'Add language');
    $edit = [];
    $edit['predefined_langcode'] = 'nl';
    $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');
}

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