public function DefaultViewRecentComments::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 ViewTestBase::setUp

See also

Drupal\simpletest\WebTestBase::prepareDatabasePrefix()

Drupal\simpletest\WebTestBase::changeDatabasePrefix()

Drupal\simpletest\WebTestBase::prepareEnvironment()

File

drupal/core/modules/comment/lib/Drupal/comment/Tests/Views/DefaultViewRecentComments.php, line 65
Contains \Drupal\comment\Tests\Views\DefaultViewRecentComments.

Class

DefaultViewRecentComments

Namespace

Drupal\comment\Tests\Views

Code

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

  // Create a new content type
  $content_type = $this
    ->drupalCreateContentType();

  // Add a node of the new content type.
  $node_data = array(
    'type' => $content_type->type,
  );
  $this->node = $this
    ->drupalCreateNode($node_data);

  // Create some comments and attach them to the created node.
  for ($i = 0; $i < $this->masterDisplayResults; $i++) {
    $comment = entity_create('comment', array(
      'node_type' => 'comment_node_' . $this->node->type,
    ));
    $comment->uid->target_id = 0;
    $comment->nid->target_id = $this->node->nid;
    $comment->subject->value = 'Test comment ' . $i;
    $comment->comment_body->value = 'Test body ' . $i;
    $comment->comment_body->format = 'full_html';

    // Ensure comments are sorted in ascending order.
    $time = REQUEST_TIME + ($this->masterDisplayResults - $i);
    $comment->created->value = $time;
    $comment->changed->value = $time;
    $comment
      ->save();
  }

  // Store all the nodes just created to access their properties on the tests.
  $this->commentsCreated = entity_load_multiple('comment');

  // Sort created comments in ascending order.
  ksort($this->commentsCreated, SORT_NUMERIC);
}