3 namespace Drupal\Tests\views\Kernel\Plugin;
5 use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
6 use Drupal\views\Views;
9 * Tests the HTML list style plugin.
12 * @see \Drupal\views\Plugin\views\style\HtmlList
14 class StyleHtmlListTest extends ViewsKernelTestBase {
17 * Views used by this test.
21 public static $testViews = ['test_style_html_list'];
24 * Make sure that the HTML list style markup is correct.
26 public function testDefaultRowClasses() {
27 $view = Views::getView('test_style_html_list');
28 $output = $view->preview();
29 $output = \Drupal::service('renderer')->renderRoot($output);
31 // Check that an empty class attribute is not added if the wrapper class is
33 $this->assertTrue(strpos($output, '<div>') !== FALSE, 'Empty class is not added to DIV when class is not set');
35 // Check that an empty class attribute is not added if the list class is
37 $this->assertTrue(strpos($output, '<ul>') !== FALSE, 'Empty class is not added to UL when class is not set');
39 // Set wrapper class and list class in style options.
40 $view->style_plugin->options['class'] = 'class';
41 $view->style_plugin->options['wrapper_class'] = 'wrapper-class';
43 $output = $view->preview();
44 $output = \Drupal::service('renderer')->renderRoot($output);
46 // Check that class attribute is present if the wrapper class is set.
47 $this->assertTrue(strpos($output, '<div class="wrapper-class">') !== FALSE, 'Class is added to DIV');
49 // Check that class attribute is present if the list class is set.
50 $this->assertTrue(strpos($output, '<ul class="class">') !== FALSE, 'Class is added to UL');