public function NodeAccessLanguageAwareTest::setUp

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

Generates a random database prefix and installs Drupal with the specified installation profile in Drupal\simpletest\WebTestBase::$profile into the prefixed database. Afterwards, installs any additional modules specified by the test.

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.

Parameters

...: List of modules to enable for the duration of the test. This can be either a single array or a variable number of string arguments.

Overrides NodeTestBase::setUp

See also

Drupal\simpletest\WebTestBase::prepareDatabasePrefix()

Drupal\simpletest\WebTestBase::changeDatabasePrefix()

Drupal\simpletest\WebTestBase::prepareEnvironment()

File

drupal/core/modules/node/lib/Drupal/node/Tests/NodeAccessLanguageAwareTest.php, line 46
Contains \Drupal\node\Tests\NodeAccessLanguageAwareTest.

Class

NodeAccessLanguageAwareTest
Tests node access functionality for multiple languages.

Namespace

Drupal\node\Tests

Code

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

  // After enabling a node access module, the access table has to be rebuild.
  node_access_rebuild();

  // Create a normal authenticated user.
  $this->web_user = $this
    ->drupalCreateUser(array(
    'access content',
  ));

  // Load the user 1 user for later use as an admin user with permission to
  // see everything.
  $this->admin_user = user_load(1);

  // Add Hungarian and Catalan.
  $language = new Language(array(
    'langcode' => 'hu',
  ));
  language_save($language);
  $language = new Language(array(
    'langcode' => 'ca',
  ));
  language_save($language);

  // The node_access_test_language module allows individual translations of a
  // node to be marked private (not viewable by normal users).
  // Create six nodes:
  // 1. Four Hungarian nodes with Catalan translations
  //   - One with neither language marked as private.
  //   - One with only the Hungarian translation private.
  //   - One with only the Catalan translation private.
  //   - One with both the Hungarian and Catalan translations private.
  // 2. Two nodes with no language specified.
  //   - One public.
  //   - One private.
  $this->nodes['both_public'] = $node = $this
    ->drupalCreateNode(array(
    'body' => array(
      array(),
    ),
    'langcode' => 'hu',
    'field_private' => array(
      array(
        'value' => 0,
      ),
    ),
  ));
  $translation = $node
    ->getTranslation('ca');
  $translation->field_private[0]->value = 0;
  $node
    ->save();
  $this->nodes['ca_private'] = $node = $this
    ->drupalCreateNode(array(
    'body' => array(
      array(),
    ),
    'langcode' => 'hu',
    'field_private' => array(
      array(
        'value' => 0,
      ),
    ),
  ));
  $translation = $node
    ->getTranslation('ca');
  $translation->field_private[0]->value = 1;
  $node
    ->save();
  $this->nodes['hu_private'] = $node = $this
    ->drupalCreateNode(array(
    'body' => array(
      array(),
    ),
    'langcode' => 'hu',
    'field_private' => array(
      array(
        'value' => 1,
      ),
    ),
  ));
  $translation = $node
    ->getTranslation('ca');
  $translation->field_private[0]->value = 0;
  $node
    ->save();
  $this->nodes['both_private'] = $node = $this
    ->drupalCreateNode(array(
    'body' => array(
      array(),
    ),
    'langcode' => 'hu',
    'field_private' => array(
      array(
        'value' => 1,
      ),
    ),
  ));
  $translation = $node
    ->getTranslation('ca');
  $translation->field_private[0]->value = 1;
  $node
    ->save();
  $this->nodes['no_language_public'] = $this
    ->drupalCreateNode(array(
    'field_private' => array(
      array(
        'value' => 0,
      ),
    ),
  ));
  $this->nodes['no_language_private'] = $this
    ->drupalCreateNode(array(
    'field_private' => array(
      array(
        'value' => 1,
      ),
    ),
  ));
}