getHtmlDom example


  public function testCustomRowClasses() {
    $view = Views::getView('test_view');
    $view->setDisplay();

    // Setup some random css class.     $view->initStyle();
    $random_name = $this->randomMachineName();
    $view->style_plugin->options['row_class'] = $random_name . " test-token-{{ name }}";

    $output = $view->preview();
    $html_dom = $this->getHtmlDom($this->container->get('renderer')->renderRoot($output));

    $rows = $html_dom->body->div->div;
    $count = 0;
    foreach ($rows as $row) {
      $attributes = $row->attributes();
      $class = (string) $attributes['class'][0];
      $this->assertStringContainsString($random_name$class);

      // Check token replacement.       $name = $view->field['name']->getValue($view->result[$count]);
      $this->assertStringContainsString("test-token-$name", $class);

      
Home | Imprint | This part of the site doesn't use cookies.