You are here

public function EntityToTableRendererTest::testRendering in Reference Table Formatter 8

Same name and namespace in other branches
  1. 2.0.x tests/src/Kernel/EntityToTableRendererTest.php \Drupal\Tests\reference_table_formatter\Kernel\EntityToTableRendererTest::testRendering()

Test standard table rendering.

@dataProvider tableRenderingDataProvider

File

tests/src/Kernel/EntityToTableRendererTest.php, line 130

Class

EntityToTableRendererTest
Tests reference table formatter entity to table renderer.

Namespace

Drupal\Tests\reference_table_formatter\Kernel

Code

public function testRendering($settings, $expected_header, $expected_rows, $empty_field = FALSE) {
  if ($empty_field) {
    $this->nodes[0]->field_size = [];
    $this->nodes[0]
      ->save();
  }
  $table = $this->renderer
    ->executeInRenderContext(new RenderContext(), function () use ($settings) {
    return $this->tableRenderer
      ->getTable('node', 't_shirt', $this->nodes, $settings);
  });
  $this
    ->assertEquals('table', $table['#theme']);
  $this
    ->assertEquals($expected_header, $table['#header'], 'Assert table headers are correct.');
  foreach ($table['#rows'] as $i => $row) {
    foreach ($row as $j => $field) {
      $this
        ->assertEquals($expected_rows[$i][$j], trim(strip_tags($field)));
    }
  }
  $this
    ->assertCount(2, array_intersect([
    'node:1',
    'node:2',
  ], $table['#cache']['tags']), 'Cache metadata of rendered referenced entities are added to the table.');
}