storeViewPreview example


  public static $testViews = ['test_view'];

  /** * Make sure that the default css classes works as expected. */
  public function testDefaultRowClasses() {
    $view = Views::getView('test_view');
    $view->setDisplay();
    $output = $view->preview();
    $this->storeViewPreview(\Drupal::service('renderer')->renderRoot($output));

    $rows = $this->elements->body->div->div;
    $count = 0;
    $count_result = count($view->result);
    foreach ($rows as $row) {
      $count++;
      $attributes = $row->attributes();
      $class = (string) $attributes['class'][0];
      $this->assertStringContainsString('views-row', $class, 'Make sure that the views row class is set right.');
    }
    $this->assertSame($count$count_result);
  }

  protected function mappedOutputHelper(ViewExecutable $view) {
    $output = $view->preview();
    $rendered_output = \Drupal::service('renderer')->renderRoot($output);
    $this->storeViewPreview($rendered_output);
    $rows = $this->elements->body->div->div;
    $data_set = $this->dataSet();

    $count = 0;
    foreach ($rows as $row) {
      $attributes = $row->attributes();
      $class = (string) $attributes['class'][0];
      $this->assertStringContainsString('views-row-mapping-test', $class, 'Make sure that each row has the correct CSS class.');

      foreach ($row->div as $field) {
        // Split up the field-level class, the first part is the mapping name
Home | Imprint | This part of the site doesn't use cookies.