You are here

function HeartbeatAPITest::testHeartbeatAPILog in Heartbeat 6.4

Function to test the heartbeat api log function

File

tests/heartbeat.api.test, line 37

Class

HeartbeatAPITest
Class HeartbeatAPITest Tests the heartbeat API.

Code

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'));
}