Commit 0d1b8985 authored by alexpott's avatar alexpott

Issue #2197091 by kirby14, undertext, lhangea, hussainweb, ACF, smiro,...

Issue #2197091 by kirby14, undertext, lhangea, hussainweb, ACF, smiro, visabhishek | ivanjaros: Fixed Class HTML attribute is present even when no class is assigned to the list.
parent 1d749884
<?php
/**
* @file
* Contains Drupal\views\Tests\Plugin\StyleHtmlListTest.
*/
namespace Drupal\views\Tests\Plugin;
use Drupal\views\Tests\ViewUnitTestBase;
use Drupal\views\Views;
/**
* Tests the HTML list style plugin.
*
* @group views
* @see \Drupal\views\Plugin\views\style\HtmlList
*/
class StyleHtmlListTest extends ViewUnitTestBase {
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = array('test_style_html_list');
/**
* Make sure that the HTML list style markup is correct.
*/
function testDefaultRowClasses() {
$view = Views::getView('test_style_html_list');
$output = $view->preview();
$output = drupal_render($output);
// Check that an empty class attribute is not added if the wrapper class is
// not set.
$this->assertTrue(strpos($output, '<div>') !== FALSE, 'Empty class is not added to DIV when class is not set');
// Check that an empty class attribute is not added if the list class is
// not set.
$this->assertTrue(strpos($output, '<ul>') !== FALSE, 'Empty class is not added to UL when class is not set');
// Set wrapper class and list class in style options.
$view->style_plugin->options['class'] = 'class';
$view->style_plugin->options['wrapper_class'] = 'wrapper-class';
$output = $view->preview();
$output = drupal_render($output);
// Check that class attribute is present if the wrapper class is set.
$this->assertTrue(strpos($output, '<div class="wrapper-class">') !== FALSE, 'Class is added to DIV');
// Check that class attribute is present if the list class is set.
$this->assertTrue(strpos($output, '<ul class="class">') !== FALSE, 'Class is added to UL');
}
}
base_field: id
base_table: views_test_data
core: 8.x
description: ''
status: '1'
display:
default:
display_plugin: default
id: default
display_title: Master
position: null
display_options:
access:
type: none
options: { }
cache:
type: none
options: { }
query:
type: views_query
options: { }
exposed_form:
type: basic
options: { }
pager:
type: full
options: { }
style:
type: html_list
options:
grouping: { }
row_class: ''
default_row_class: true
type: ul
wrapper_class: ''
class: ''
provider: views
row:
type: fields
options: { }
fields:
name:
id: name
table: views_test_data
field: name
provider: views_test_data
label: ''
module: views
id: test_style_html_list
tag: ''
langcode: en
......@@ -829,20 +829,20 @@ function template_preprocess_views_view_list(&$variables) {
$handler = $variables['view']->style_plugin;
// Fetch classes from handler options.
$class = explode(' ', $handler->options['class']);
$class = array_map('drupal_clean_css_identifier', $class);
if ($handler->options['class']) {
$class = explode(' ', $handler->options['class']);
$class = array_map('drupal_clean_css_identifier', $class);
// Fetch wrapper classes from handler options.
$wrapper_class = explode(' ', $handler->options['wrapper_class']);
$wrapper_class = array_map('drupal_clean_css_identifier', $wrapper_class);
// Initialize a new attribute class for $class.
$variables['list']['attributes'] = new Attribute(array('class' => $class));
}
// Initialize a new attribute class for $wrapper_class.
if ($wrapper_class) {
$variables['attributes']['class'] = $wrapper_class;
// Fetch wrapper classes from handler options.
if ($handler->options['wrapper_class']) {
$wrapper_class = explode(' ', $handler->options['wrapper_class']);
$variables['attributes']['class'] = array_map('drupal_clean_css_identifier', $wrapper_class);
}
// Initialize a new attribute class for $class.
$variables['list']['attributes'] = new Attribute(array('class' => $class));
$variables['list']['type'] = $handler->options['type'];
template_preprocess_views_view_unformatted($variables);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment