You are here

function HeartbeatFunctionalTest::testOlderActivity in Heartbeat 6.4

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.

File

tests/heartbeat.functional.test, line 44

Class

HeartbeatFunctionalTest

Code

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