You are here

public function ViewsRulesViewsDisplayTestCase::testExecuteIterator in Views Rules 7

Tests iterator evaluation.

File

tests/views_rules.test, line 140
Simpletest implementations.

Class

ViewsRulesViewsDisplayTestCase
Views display tests.

Code

public function testExecuteIterator() {
  $iterable = new ViewsRulesTestIterable();

  /** @var $iterator views_rules_plugin_display_rules */
  $iterator = views_rules_get_view('views_rules_test:views_rules_1')->display_handler;

  // Create sample items.
  $data = $this
    ->createSiteData();

  // Disable nid and test executing iterator.
  $option = $iterator
    ->get_option('rules_variables');
  $option['nid']['enabled'] = 0;
  $iterator
    ->set_option('rules_variables', $option);
  $iterator
    ->execute_iterator(array(
    $data['term']->tid,
  ), $iterable);
  $expectedData = array(
    array(
      'title' => 'Node 1',
    ),
    array(
      'title' => 'Node 2',
    ),
    array(
      'title' => 'Node 3',
    ),
  );
  $this
    ->assertIdentical($expectedData, $iterable->rows, 'Iterator display correctly evaluates.');

  // Check execution for rendered result.
  $iterator = views_rules_get_view('views_rules_test:views_rules_1')->display_handler;
  $option = $iterator
    ->get_option('fields');
  $option['title']['alter']['alter_text'] = 1;
  $option['title']['alter']['text'] = '<em>[title]</em>';
  $option['title']['link_to_node'] = 0;
  $iterator
    ->set_option('fields', $option);
  $option = $iterator
    ->get_option('rules_variables');
  $option['nid']['enabled'] = 0;
  $option['title']['rendered'] = 1;
  $iterator
    ->set_option('rules_variables', $option);
  $iterator
    ->execute_iterator(array(
    $data['term']->tid,
  ), $iterable
    ->reset());
  $expectedData = array(
    array(
      'title' => '<em>Node 1</em>',
    ),
    array(
      'title' => '<em>Node 2</em>',
    ),
    array(
      'title' => '<em>Node 3</em>',
    ),
  );
  $this
    ->assertIdentical($expectedData, $iterable->rows, 'Iterator display correctly evaluates rendered result.');

  // Check execution for non-field row styles.
  $iterator = views_rules_get_view('views_rules_non_field_test:views_rules_1')->display_handler;
  $iterator
    ->execute_iterator(array(
    $data['term']->tid,
  ), $iterable
    ->reset());
  $expectedData = array(
    array(
      'node' => $data['node1']->nid,
    ),
    array(
      'node' => $data['node2']->nid,
    ),
    array(
      'node' => $data['node3']->nid,
    ),
  );
  $this
    ->assertIdentical($expectedData, $iterable->rows, 'Iterator display correctly evaluates for non-field row style.');
}