You are here

protected function NodeRevisionsAllTest::setUp in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/node/src/Tests/NodeRevisionsAllTest.php \Drupal\node\Tests\NodeRevisionsAllTest::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/NodeRevisionsAllTest.php, line 21
Contains \Drupal\node\Tests\NodeRevisionsAllTest.

Class

NodeRevisionsAllTest
Create a node with revisions and test viewing, saving, reverting, and deleting revisions for user with access to all.

Namespace

Drupal\node\Tests

Code

protected function setUp() {
  parent::setUp();
  $node_storage = $this->container
    ->get('entity.manager')
    ->getStorage('node');

  // Create and log in user.
  $web_user = $this
    ->drupalCreateUser(array(
    'view page revisions',
    'revert page revisions',
    'delete page revisions',
    'edit any page content',
    'delete any page content',
  ));
  $this
    ->drupalLogin($web_user);

  // Create an initial node.
  $node = $this
    ->drupalCreateNode();
  $settings = get_object_vars($node);
  $settings['revision'] = 1;
  $nodes = array();
  $logs = array();

  // Get the original node.
  $nodes[] = clone $node;

  // Create three revisions.
  $revision_count = 3;
  for ($i = 0; $i < $revision_count; $i++) {
    $logs[] = $node->revision_log = $this
      ->randomMachineName(32);

    // Create revision with a random title and body and update variables.
    $node->title = $this
      ->randomMachineName();
    $node->body = array(
      'value' => $this
        ->randomMachineName(32),
      'format' => filter_default_format(),
    );
    $node
      ->setNewRevision();
    $node
      ->save();
    $node_storage
      ->resetCache(array(
      $node
        ->id(),
    ));
    $node = $node_storage
      ->load($node
      ->id());

    // Make sure we get revision information.
    $nodes[] = clone $node;
  }
  $this->nodes = $nodes;
  $this->revisionLogs = $logs;
}