You are here

public function DefaultViewRecentComments::setUp in Views (for Drupal 7) 8.3

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 ViewTestBase::setUp

File

lib/Drupal/views/Tests/Comment/DefaultViewRecentComments.php, line 65
Definition of Drupal\views\Tests\Comment\DefaultViewRecentComments.

Class

DefaultViewRecentComments

Namespace

Drupal\views\Tests\Comment

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());
    $comment->uid = 0;
    $comment->nid = $this->node->nid;
    $comment->subject = 'Test comment ' . $i;
    $comment->node_type = 'comment_node_' . $this->node->type;
    $comment->comment_body[LANGUAGE_NOT_SPECIFIED][0]['value'] = 'Test body ' . $i;
    $comment->comment_body[LANGUAGE_NOT_SPECIFIED][0]['format'] = 'full_html';
    comment_save($comment);
  }

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