You are here

heartbeat.functional.test in Heartbeat 6.4

File

tests/heartbeat.functional.test
View source
<?php

/**
 * @file
 * Functional tests for heartbeat
 */
require_once dirname(__FILE__) . '/heartbeatwebtestcase.inc';
class HeartbeatFunctionalTest extends HeartbeatWebTestCase {

  /**
   * Implementation of setUp().
   */
  function setUp() {
    parent::setUp('heartbeat', 'heartbeattest');
  }

  /**
   * Implementation of getInfo().
   */
  function getInfo() {
    return array(
      'name' => t('Heartbeat Functional'),
      'description' => t('Tests for heartbeat functionality.'),
      'group' => t('Heartbeat'),
    );
  }

  /**
   * Function to test the heartbeat older messages function.
   * Since configuration is needed, grouping functionality
   * is tested here as well.
   *
   * First a public heartbeat stream is set to show two activity messages
   * Because grouping feature is enabled in the default message, we can
   * see the three added node activity.
   * After resetting the grouping to "single", only two messages are
   * appearing while a "older messages" button is shown.
   *
   * TODO Clicking it will start an ajax call with the third message
   * popping up.
   */
  function testOlderActivity() {
    $this
      ->drupalLogin($this
      ->drupalCreateUser($this->testRoles));
    $edit = array(
      'page_items_max' => 2,
      'page_pager_ajax' => FALSE,
    );
    $this
      ->configureStream('publicheartbeat', $edit);

    // Add three page nodes to prepare test.
    $time = $_SERVER['REQUEST_TIME'];
    $this
      ->drupalCreateNode(array(
      'title' => 'MyFirstTitle',
    ));
    $_SERVER['REQUEST_TIME'] += 1;
    $this
      ->drupalCreateNode(array(
      'title' => 'MySecondTitle',
    ));
    $_SERVER['REQUEST_TIME'] += 1;
    $this
      ->drupalCreateNode(array(
      'title' => 'MyThirdTitle',
    ));
    $_SERVER['REQUEST_TIME'] += 1;
    $this
      ->drupalCreateNode(array(
      'title' => 'MyFourthTitle',
    ));
    $_SERVER['REQUEST_TIME'] += 1;
    $this
      ->drupalCreateNode(array(
      'title' => 'MyFifthTitle',
    ));
    $_SERVER['REQUEST_TIME'] = $time;
    $this
      ->drupalGet('heartbeat/publicheartbeat');

    // Test if the first two posts are visible where the third isn't.
    $this
      ->assertText('MyFifthTitle', t('Fifth title is displayed in the public stream.'), t('Heartbeat'));
    $this
      ->assertText('MyFourthTitle', t('Fourth title is displayed in the public stream.'), t('Heartbeat'));
    $this
      ->assertText('MyThirdTitle', t('Third title is displayed in the public stream.'), t('Heartbeat'));

    // Configure add_node message template to diable its default grouping.
    $edit = array(
      'type' => 'single',
    );
    $this
      ->drupalPost('admin/build/heartbeat/edit/1', $edit, t('Save'));

    // @TODO Javascript calls is for the future
    $this
      ->drupalGet('heartbeat/publicheartbeat');

    // Test if the first post ise visible where the third isn't.
    $this
      ->assertText('MyFifthTitle', t('Fifth title is displayed in the public stream.'), t('Heartbeat'));
    $this
      ->assertNoText('MyThirdTitle', t('Third title is not displayed in the public stream.'), t('Heartbeat'));

    // Click on the button.
    $this
      ->clickLink(t('Older messages'));
    $this
      ->assertText('MyThirdTitle', t('Third title is now displayed in the public stream.'), t('Heartbeat'));

    // Click on the button.
    $this
      ->clickLink(t('Older messages'));
    $this
      ->assertText('MyFirstTitle', t('First title is now displayed in the public stream.'), t('Heartbeat'));

    // Click on the back button.
    $this
      ->clickLink(t('Go to previous messages'));
    $this
      ->assertText('MyFourthTitle', t('Fourth title is now displayed in the public stream.'), t('Heartbeat'));
  }

  /**
   * Function to test the heartbeat poll for activity function
   *
   * We're invoking the ajax menu callback with GET parameters
   * and test the result as a normal page.
   */
  function testPollActivity() {
    $this
      ->drupalLogin($this
      ->drupalCreateUser($this->testRoles));

    // Create page so heartbeattest.module can log activity through hook_nodeapi.
    $page_node = $this
      ->drupalCreateNode(array(
      'type' => 'page',
      'title' => 'MyPageTitle',
    ));

    // We cheat by resetting the most recent displayed uaid,
    // to make sure there is a newer message found.
    $options = array(
      'query' => 'stream=publicheartbeat&latestUaid=0&uaids=',
    );
    $this
      ->drupalGet('heartbeat/js/poll', $options);
    $this
      ->assertText('MyPageTitle', t('The page title is displayed in the public heartbeat stream ajax response.'), t('Heartbeat'));
  }

}

Classes