You are here

protected function NodeAccessLanguageAwareTest::setUp in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/node/src/Tests/NodeAccessLanguageAwareTest.php \Drupal\node\Tests\NodeAccessLanguageAwareTest::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 NodeTestBase::setUp

File

core/modules/node/src/Tests/NodeAccessLanguageAwareTest.php, line 50
Contains \Drupal\node\Tests\NodeAccessLanguageAwareTest.

Class

NodeAccessLanguageAwareTest
Tests node_access and db_select() with node_access tag functionality with multiple languages with node_access_test_language which is language-aware.

Namespace

Drupal\node\Tests

Code

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

  // Create the 'private' field, which allows the node to be marked as private
  // (restricted access) in a given translation.
  $field_storage = entity_create('field_storage_config', array(
    'field_name' => 'field_private',
    'entity_type' => 'node',
    'type' => 'boolean',
    'cardinality' => 1,
  ));
  $field_storage
    ->save();
  entity_create('field_config', array(
    'field_storage' => $field_storage,
    'bundle' => 'page',
    'widget' => array(
      'type' => 'options_buttons',
    ),
    'settings' => array(
      'on_label' => 'Private',
      'off_label' => 'Not private',
    ),
  ))
    ->save();

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

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

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

  // Add Hungarian and Catalan.
  ConfigurableLanguage::createFromLangcode('hu')
    ->save();
  ConfigurableLanguage::createFromLangcode('ca')
    ->save();

  // 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
    ->addTranslation('ca');
  $translation->title->value = $this
    ->randomString();
  $translation->field_private->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
    ->addTranslation('ca');
  $translation->title->value = $this
    ->randomString();
  $translation->field_private->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
    ->addTranslation('ca');
  $translation->title->value = $this
    ->randomString();
  $translation->field_private->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
    ->addTranslation('ca');
  $translation->title->value = $this
    ->randomString();
  $translation->field_private->value = 1;
  $node
    ->save();
  $this->nodes['no_language_public'] = $this
    ->drupalCreateNode(array(
    'field_private' => array(
      array(
        'value' => 0,
      ),
    ),
    'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
  ));
  $this->nodes['no_language_private'] = $this
    ->drupalCreateNode(array(
    'field_private' => array(
      array(
        'value' => 1,
      ),
    ),
    'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
  ));
}