You are here

heartbeatcomments.test in Heartbeat 6.4

File

modules/heartbeat_comments/tests/heartbeatcomments.test
View source
<?php

/**
 * @file
 *   Test class to test rules execution on heartbeat logging.
 */
require_once dirname(__FILE__) . '/../../../tests/heartbeatwebtestcase.inc';

/**
 * Class HeartbeatRulesTest
 *
 */
class HeartbeatCommentsTest extends HeartbeatWebTestCase {
  protected $testRoles = array(
    'administer content types',
    'access content',
    'view revisions',
    'administer nodes',
    'access user profiles',
    'view heartbeat messages',
    'configure heartbeat messages',
    'view personal heartbeat activity',
    'administer heartbeat comments',
    'add heartbeat comment',
    'delete own comments',
    'delete any comment',
    'post comments',
  );

  /**
   * Implementation of getInfo().
   */
  function getInfo() {
    return array(
      'name' => t('Heartbeat comments test'),
      'description' => t('Test heartbeat comments'),
      'group' => t('Heartbeat'),
    );
  }

  /**
   * Implementation of setUp().
   */
  function setUp() {
    parent::setUp('token', 'rules', 'heartbeat', 'hrules', 'heartbeat_comments');
  }

  /**
   * Tests if a heartbeat message is logged for an event.
   */
  function testHeartbeatComments() {
    $this
      ->drupalLogin($this
      ->drupalCreateUser($this->testRoles));
    variable_set('comment_page', 2);
    $edit = array(
      'page_items_max' => 5,
      'page_pager_ajax' => FALSE,
    );
    $this
      ->configureStream('publicheartbeat', $edit);
    drupal_flush_all_caches();
    $this
      ->drupalGet('admin/content/node-type/page');
    $page_node = $this
      ->drupalCreateNode(array(
      'type' => 'page',
      'title' => 'MyFirstPage',
    ));

    // Get a stream page and check if the page post appears in the heartbeat activity stream.
    $this
      ->drupalGet('heartbeat/publicheartbeat');
    $this
      ->assertText('MyFirstPage', t('The page title is displayed in the public heartbeat stream.'), t('Heartbeat'));

    // Configure the message type to have node comments.
    $edit = array(
      'type' => 'single',
      'attachments[heartbeat_comments]' => TRUE,
      'attachments[comment_comments]' => TRUE,
    );
    $this
      ->drupalPost('admin/build/heartbeat/edit/2', $edit, t('Save'));

    // Verbose check, not needed otherwise.
    $this
      ->drupalGet('admin/build/heartbeat/edit/2');

    // Get a stream page and check if the page post appears in the heartbeat activity stream.
    $page_node = $this
      ->drupalCreateNode(array(
      'type' => 'page',
      'title' => 'MySecondPageWithComments',
    ));
    $this
      ->drupalGet('heartbeat/publicheartbeat');
    $this
      ->assertText('MySecondPageWithComments', t('The page title is displayed in the public heartbeat stream.'), t('Heartbeat'));
    $this
      ->assertText('React', t('The react button is on the screen.'), t('Heartbeat'));

    // Add a comment and check if it's there.
    $edit = array(
      'message' => 'My First Comment',
      'nid' => 2,
      'node_comment' => TRUE,
      'uaid' => 2,
    );
    $this
      ->drupalPost('heartbeat/publicheartbeat', $edit, t('Submit'));
    $this
      ->drupalGet('heartbeat/publicheartbeat');
    $this
      ->assertText('My First Comment', t('The posted comment is displayed.'), t('Heartbeat'));

    // Check the comment administration.
    $this
      ->drupalGet('admin/content/heartbeat/comments');
    $this
      ->assertText('No comments available', t('No comments found.'), t('Heartbeat'));

    // Re-configure the message type to have normal heartbeat comments.
    $edit = array(
      'attachments[heartbeat_comments]' => TRUE,
      'attachments[comment_comments]' => FALSE,
    );
    $this
      ->drupalPost('admin/build/heartbeat/edit/2', $edit, t('Save'));

    // Add a heartbeat comment.
    $edit = array(
      'message' => 'My First Heartbeat Comment',
      'uaid' => 2,
    );
    $this
      ->drupalPost('heartbeat/publicheartbeat', $edit, t('Submit'));
    $this
      ->drupalGet('admin/content/heartbeat/comments');
    $this
      ->assertNoText('No comments available', t('Comments are found.'), t('Heartbeat'));
    $this
      ->assertText('My First Heartbeat Comment', t('The posted comment can be managed.'), t('Heartbeat'));
  }

}

Classes

Namesort descending Description
HeartbeatCommentsTest Class HeartbeatRulesTest