You are here

protected function CommentNonNodeTest::setUp in Zircon Profile 8

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

File

core/modules/comment/src/Tests/CommentNonNodeTest.php, line 50
Contains \Drupal\comment\Tests\CommentNonNodeTest.

Class

CommentNonNodeTest
Tests commenting on a test entity.

Namespace

Drupal\comment\Tests

Code

protected function setUp() {
  parent::setUp();
  $this
    ->drupalPlaceBlock('system_breadcrumb_block');
  $this
    ->drupalPlaceBlock('page_title_block');

  // Create a bundle for entity_test.
  entity_test_create_bundle('entity_test', 'Entity Test', 'entity_test');
  entity_create('comment_type', array(
    'id' => 'comment',
    'label' => 'Comment settings',
    'description' => 'Comment settings',
    'target_entity_type_id' => 'entity_test',
  ))
    ->save();

  // Create comment field on entity_test bundle.
  $this
    ->addDefaultCommentField('entity_test', 'entity_test');

  // Verify that bundles are defined correctly.
  $bundles = \Drupal::entityManager()
    ->getBundleInfo('comment');
  $this
    ->assertEqual($bundles['comment']['label'], 'Comment settings');

  // Create test user.
  $this->adminUser = $this
    ->drupalCreateUser(array(
    'administer comments',
    'skip comment approval',
    'post comments',
    'access comments',
    'view test entity',
    'administer entity_test content',
  ));

  // Enable anonymous and authenticated user comments.
  user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, array(
    'access comments',
    'post comments',
    'skip comment approval',
  ));
  user_role_grant_permissions(RoleInterface::AUTHENTICATED_ID, array(
    'access comments',
    'post comments',
    'skip comment approval',
  ));

  // Create a test entity.
  $random_label = $this
    ->randomMachineName();
  $data = array(
    'type' => 'entity_test',
    'name' => $random_label,
  );
  $this->entity = entity_create('entity_test', $data);
  $this->entity
    ->save();
}