You are here

public function FieldGroupRowsTest::testGroupRows in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/views/src/Tests/Handler/FieldGroupRowsTest.php \Drupal\views\Tests\Handler\FieldGroupRowsTest::testGroupRows()

Testing the "Grouped rows" functionality.

File

core/modules/views/src/Tests/Handler/FieldGroupRowsTest.php, line 70
Contains \Drupal\views\Tests\Handler\FieldGroupRowsTest.

Class

FieldGroupRowsTest
Tests the "Display all values in the same row" setting.

Namespace

Drupal\views\Tests\Handler

Code

public function testGroupRows() {

  /** @var \Drupal\Core\Render\RendererInterface $renderer */
  $renderer = \Drupal::service('renderer');
  $edit = array(
    'title' => $this
      ->randomMachineName(),
    $this->fieldName => array(
      'a',
      'b',
      'c',
    ),
  );
  $this
    ->drupalCreateNode($edit);
  $view = Views::getView('test_group_rows');

  // Test grouped rows.
  $this
    ->executeView($view);
  $output = $renderer
    ->executeInRenderContext(new RenderContext(), function () use ($view) {
    return $view->field[$this->fieldName]
      ->advancedRender($view->result[0]);
  });
  $this
    ->assertEqual($output, 'a, b, c');

  // Change the group_rows checkbox to false.
  $view = Views::getView('test_group_rows');
  $view
    ->setHandlerOption('default', 'field', $this->fieldName, 'group_rows', FALSE);

  // Test ungrouped rows.
  $this
    ->executeView($view);
  $view
    ->render();
  $view->row_index = 0;
  $output = $renderer
    ->executeInRenderContext(new RenderContext(), function () use ($view) {
    return $view->field[$this->fieldName]
      ->advancedRender($view->result[0]);
  });
  $this
    ->assertEqual($output, 'a');
  $view->row_index = 1;
  $output = $renderer
    ->executeInRenderContext(new RenderContext(), function () use ($view) {
    return $view->field[$this->fieldName]
      ->advancedRender($view->result[1]);
  });
  $this
    ->assertEqual($output, 'b');
  $view->row_index = 2;
  $output = $renderer
    ->executeInRenderContext(new RenderContext(), function () use ($view) {
    return $view->field[$this->fieldName]
      ->advancedRender($view->result[2]);
  });
  $this
    ->assertEqual($output, 'c');
}