You are here

function FlagCommentOptimizationTestCase::setUp in Flag 7.3

Implements setUp().

Overrides DrupalWebTestCase::setUp

File

tests/flag.test, line 1679
Tests for the Flag module.

Class

FlagCommentOptimizationTestCase
Verifies the optimization for comment viewing.

Code

function setUp() {
  parent::setUp(array(
    'flag',
    'comment',
    'flag_comment_flag_test',
  ));
  $flag_data = array(
    'entity_type' => 'comment',
    'name' => 'test_flag',
    'title' => 'Test Flag',
    'global' => 0,
    'types' => array(),
    'flag_short' => 'Flag this item',
    'flag_long' => '',
    'flag_message' => '',
    'unflag_short' => 'Unflag this item',
    'unflag_long' => '',
    'unflag_message' => '',
    'unflag_denied_text' => 'You may not unflag this item',
    'link_type' => 'normal',
    'weight' => 0,
    'show_on_form' => 0,
    'access_author' => '',
    'show_contextual_link' => 0,
    'show_in_links' => array(
      'full' => 1,
      'teaser' => 1,
    ),
    'i18n' => 0,
    'api_version' => 3,
  );
  $this->flag = $this
    ->createFlag($flag_data);

  // Set up comments on article nodes.
  variable_set('comment_form_location_article', COMMENT_FORM_BELOW);

  // Create test user who can flag and unflag.
  $this->user = $this
    ->drupalCreateUser(array(
    'access comments',
    'post comments',
    'flag test_flag',
    'unflag test_flag',
  ));
  $this
    ->drupalLogin($this->user);

  // Create an article node.
  $title = $this
    ->randomName(8);
  $node = array(
    'title' => $title,
    'body' => array(
      LANGUAGE_NONE => array(
        array(
          'value' => $this
            ->randomName(32),
        ),
      ),
    ),
    'uid' => $this->user->uid,
    'type' => 'article',
    'is_new' => TRUE,
    'comment' => COMMENT_NODE_OPEN,
  );
  $node = node_submit((object) $node);
  node_save($node);
  $this->nid = $node->nid;

  // Create some comments on the node.
  $this->cids = array();
  foreach (range(1, 10) as $i) {
    $comment = (object) array(
      'cid' => NULL,
      'nid' => $node->nid,
      'pid' => 0,
      'uid' => $this->user->uid,
      'status' => COMMENT_PUBLISHED,
      'subject' => $this
        ->randomName(),
      'language' => LANGUAGE_NONE,
      'comment_body' => array(
        LANGUAGE_NONE => array(
          $this
            ->randomName(),
        ),
      ),
    );
    comment_save($comment);
    $this->cids[$comment->cid] = $comment->cid;
  }

  // Flag one comment.
  $this->flag
    ->flag('flag', reset($this->cids));
}