summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2014-09-12 11:05:00 (GMT)
committerAlex Pott2014-09-12 11:05:00 (GMT)
commit0d1b898502a51f80a74a46b3aecb707ae6fa3c5e (patch)
tree91a51a53f554429d6bc5c8253ff440e34f603e7d
parent1d74988427f967d8675e2dd12d055eb0de324c67 (diff)
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.
-rw-r--r--core/modules/views/src/Tests/Plugin/StyleHtmlListTest.php58
-rw-r--r--core/modules/views/tests/modules/views_test_config/test_views/views.view.test_style_html_list.yml51
-rw-r--r--core/modules/views/views.theme.inc20
3 files changed, 119 insertions, 10 deletions
diff --git a/core/modules/views/src/Tests/Plugin/StyleHtmlListTest.php b/core/modules/views/src/Tests/Plugin/StyleHtmlListTest.php
new file mode 100644
index 0000000..0642eff
--- /dev/null
+++ b/core/modules/views/src/Tests/Plugin/StyleHtmlListTest.php
@@ -0,0 +1,58 @@
+<?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');
+ }
+
+}
diff --git a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_style_html_list.yml b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_style_html_list.yml
new file mode 100644
index 0000000..0323178
--- /dev/null
+++ b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_style_html_list.yml
@@ -0,0 +1,51 @@
+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
diff --git a/core/modules/views/views.theme.inc b/core/modules/views/views.theme.inc
index f32da9a..81df6a1 100644
--- a/core/modules/views/views.theme.inc
+++ b/core/modules/views/views.theme.inc
@@ -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);