You are here

public function WebformViewsFieldTestBase::testMultiValueAllInOne in Webform Views Integration 8.5

Test the multivalue element placing all values into single cell.

File

tests/src/Kernel/field/WebformViewsFieldTestBase.php, line 31

Class

WebformViewsFieldTestBase
Reasonable starting point for testing webform views field handlers.

Namespace

Drupal\Tests\webform_views\Kernel\field

Code

public function testMultiValueAllInOne() {

  // Convert each webform element into multivalue before creating the webform.
  $webform_elements = $this->webform_elements;
  foreach ($webform_elements as $k => $v) {
    $webform_elements[$k]['#multiple'] = 10;
  }
  $this->webform = $this
    ->createWebform($webform_elements);
  $this
    ->createWebformSubmissions($this->webform_submission_multivalue_data, $this->webform);

  // Convert each view field handler into 'all in one' multi value before
  // creating the view.
  $view_handlers = $this->view_handlers;
  foreach ($view_handlers['field'] as $k => $v) {
    $view_handlers['field'][$k]['options']['webform_multiple_value'] = TRUE;
  }
  $this->view = $this
    ->initView($this->webform, $view_handlers);
  $rendered_cells = $this
    ->renderView($this->view);
  $expected = [];
  foreach ($this->webform_submission_multivalue_data as $i => $submission) {
    foreach ($submission as $element => $data) {
      $render = [
        '#theme' => 'item_list',
        '#items' => $data,
      ];
      $expected[$i][$element] = (string) \Drupal::service('renderer')
        ->renderRoot($render);
    }
  }
  $this
    ->assertSame($expected, $rendered_cells);
}