You are here

protected function PrivateFileOnTranslatedEntityTest::setUp in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/file/src/Tests/PrivateFileOnTranslatedEntityTest.php \Drupal\file\Tests\PrivateFileOnTranslatedEntityTest::setUp()

Sets up a Drupal site for running functional and integration tests.

Installs Drupal with the installation profile specified in \Drupal\simpletest\WebTestBase::$profile into the prefixed database.

Afterwards, installs any additional modules specified in the static \Drupal\simpletest\WebTestBase::$modules property of each class in the class hierarchy.

After installation all caches are flushed and several configuration values are reset to the values of the parent site executing the test, since the default values may be incompatible with the environment in which tests are being executed.

Overrides FileFieldTestBase::setUp

File

core/modules/file/src/Tests/PrivateFileOnTranslatedEntityTest.php, line 35
Contains \Drupal\file\Tests\PrivateFileOnTranslatedEntityTest.

Class

PrivateFileOnTranslatedEntityTest
Uploads private files to translated node and checks access.

Namespace

Drupal\file\Tests

Code

protected function setUp() {
  parent::setUp();

  // Create the "Basic page" node type.
  $this
    ->drupalCreateContentType(array(
    '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', array(
    'uri_scheme' => 'private',
  ));

  // Create and login user.
  $permissions = array(
    '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 = array();
  $edit['predefined_langcode'] = 'fr';
  $this
    ->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language'));

  // Enable translation for "Basic page" nodes.
  $edit = array(
    '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'));
  \Drupal::entityManager()
    ->clearCachedDefinitions();
}