1 comment.test CommentHelperCase::setUp($modules = array())

Sets up a Backdrop site for running functional and integration tests.

Generates a random database prefix and installs Backdrop with the specified installation profile in BackdropWebTestCase::$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.

Return value

bool TRUE if set up completes, FALSE if an error occurred.

Overrides BackdropWebTestCase::setUp

See also

BackdropWebTestCase::prepareDatabasePrefix()

BackdropWebTestCase::changeDatabasePrefix()

BackdropWebTestCase::prepareEnvironment()

File

core/modules/comment/tests/comment.test, line 13
Tests for the Comment module.

Class

CommentHelperCase

Code

function setUp($modules = array()) {
  $modules = func_get_args();
  if (isset($modules[0]) && is_array($modules[0])) {
    $modules = $modules[0];
  }
  $modules[] = 'comment';
  parent::setUp($modules);

  // Create a post content type with comments enabled.
  $this->backdropCreateContentType(array(
    'type' => 'post',
    'name' => 'Post',
    'settings' => array(
      'comment_default' => COMMENT_NODE_OPEN,
    ),
    'is_new' => TRUE,
  ));

  // Add text formats.
  $filtered_html_format = array(
    'format' => 'filtered_html',
    'name' => 'Filtered HTML',
    'weight' => 0,
    'editor' => 'ckeditor',
    'filters' => array(
      // URL filter.
      'filter_url' => array(
        'weight' => 0,
        'status' => 1,
      ),
      // HTML filter.
      'filter_html' => array(
        'weight' => 1,
        'status' => 1,
      ),
      // Line break filter.
      'filter_autop' => array(
        'weight' => 2,
        'status' => 1,
      ),
      // HTML corrector filter.
      'filter_htmlcorrector' => array(
        'weight' => 10,
        'status' => 1,
      ),
    ),
  );
  $filtered_html_format = (object) $filtered_html_format;
  filter_format_save($filtered_html_format);
  $filtered_html_permission = filter_permission_name($filtered_html_format);

  // Grant basic permissions for comments to anonymous and authenticated roles.
  user_role_grant_permissions(BACKDROP_ANONYMOUS_ROLE, array('access content', 'access comments', $filtered_html_permission));
  user_role_grant_permissions(BACKDROP_AUTHENTICATED_ROLE, array('access content', 'access comments', 'post comments', 'skip comment approval', $filtered_html_permission));

  // Create users and test node.
  $this->admin_user = $this->backdropCreateUser(array('administer site configuration', 'administer content types', 'create post content', 'edit any post content', 'delete any post content', 'administer comments', 'administer layouts', 'administer fields'));
  $this->web_user = $this->backdropCreateUser(array('create post content', 'edit own comments'));
  $this->node = $this->backdropCreateNode(array('type' => 'post', 'promote' => 1, 'uid' => $this->web_user->uid));
}