You are here

public function ViewsRulesCollectActionTestCase::testEvaluate in Views Rules 7

Tests evaluating the action.

File

tests/views_rules.test, line 389
Simpletest implementations.

Class

ViewsRulesCollectActionTestCase
Rules plugin tests.

Code

public function testEvaluate() {
  $data = $this
    ->createSiteData();
  $variables = array(
    'term' => array(
      'type' => 'taxonomy_term',
      'label' => 'Term',
    ),
    'list1' => array(
      'type' => 'list',
      'label' => 'List 1',
      'parameter' => FALSE,
    ),
    'list2' => array(
      'type' => 'list',
      'label' => 'List 2',
      'parameter' => FALSE,
    ),
  );
  $provides = array(
    'list1',
    'list2',
  );
  $comp = rules_action_set($variables, $provides)
    ->action('views_rules_collect_rows', array(
    'views_rules_display' => 'views_rules_test:views_rules_1',
    'tid:select' => 'term:tid',
    'type' => 'article',
    'nid:var' => 'list_nid',
    'nid:label' => 'List of node IDs',
    'title:var' => 'list_title',
    'title:label' => 'List of node titles',
  ))
    ->action('data_set', array(
    'data:select' => 'list1',
    'value:select' => 'list_nid',
  ))
    ->action('data_set', array(
    'data:select' => 'list2',
    'value:select' => 'list_title',
  ));

  // Test evaluation.
  $expectedList1 = array(
    $data['node1']->nid,
    $data['node2']->nid,
    $data['node3']->nid,
  );
  $expectedList2 = array(
    $data['node1']->title,
    $data['node2']->title,
    $data['node3']->title,
  );
  $return = $comp
    ->execute($data['term']);
  $this
    ->assertIdentical($expectedList1, reset($return), 'Collect action correctly returns a list of data.');
  $this
    ->assertIdentical($expectedList2, next($return), 'Collect action correctly returns all lists of data.');
}