You are here

heartbeat.api.test in Heartbeat 6.4

Same filename and directory in other branches
  1. 7 tests/heartbeat.api.test

File

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

/**
 * @file
 * Tests for heartbeat API
 */
require_once dirname(__FILE__) . '/heartbeatwebtestcase.inc';

/**
 * Class HeartbeatAPITest
 *   Tests the heartbeat API.
 */
class HeartbeatAPITest extends HeartbeatWebTestCase {

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

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

  /**
   * Function to test the heartbeat api log function
   */
  function testHeartbeatAPILog() {
    $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',
    ));

    // Test if something was logged to database
    $count_logs = db_result(db_query("SELECT COUNT(uaid) FROM {heartbeat_activity}"));
    $this
      ->assertEqual(1, $count_logs, t('Number of activity messages ( ' . $count_logs . ') matches the number of logs.'), t('Heartbeat'));

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

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

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

    // Test if something was logged to database
    $count_logs = db_result(db_query("SELECT COUNT(uaid) FROM {heartbeat_activity}"));
    $this
      ->assertEqual(2, $count_logs, t('Number of activity messages ( ' . $count_logs . ') matches the number of logs.'), t('Heartbeat'));
  }

}

Classes

Namesort descending Description
HeartbeatAPITest Class HeartbeatAPITest Tests the heartbeat API.