diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/row/DataFieldRow.php b/core/modules/views/lib/Drupal/views/Plugin/views/row/DataFieldRow.php index 2c96e0d..a7a2074 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/row/DataFieldRow.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/row/DataFieldRow.php @@ -46,7 +46,7 @@ public function init(ViewExecutable $view, &$display, $options = NULL) { if (!empty($this->options['aliases'])) { // Prepare a trimmed version of replacement aliases. - $this->replacementAliases = array_map('trim', (array) $this->options['aliases']); + $this->replacementAliases = array_filter(array_map('trim', (array) $this->options['aliases'])); } } diff --git a/core/modules/views/lib/Drupal/views/Tests/Plugin/StyleSerializeTest.php b/core/modules/views/lib/Drupal/views/Tests/Plugin/StyleSerializeTest.php index 813510b..787d1c9 100644 --- a/core/modules/views/lib/Drupal/views/Tests/Plugin/StyleSerializeTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/Plugin/StyleSerializeTest.php @@ -26,8 +26,8 @@ class StyleSerializeTest extends PluginTestBase { public static function getInfo() { return array( - 'name' => 'Style: Serialize plugin', - 'description' => 'Tests the serialize style plugin.', + 'name' => 'Style: Serializer plugin', + 'description' => 'Tests the serializer style plugin.', 'group' => 'Views Plugins', ); } @@ -103,7 +103,28 @@ public function testUIFieldAlias() { $row_options = 'admin/structure/views/nojs/display/test_serialize_display_field/data_1/row_options'; $this->assertLinkByHref($row_options); - // Add a random alias for the name field and save the view. + // Test an empty string for an alias, this should not be used. + $this->drupalPost($row_options, array('row_options[aliases][name]' => ''), t('Apply')); + $this->drupalPost(NULL, array(), t('Save')); + + $view = views_get_view('test_serialize_display_field'); + $view->setDisplay('data_1'); + $this->executeView($view); + + $expected = array(); + foreach ($view->result as $row) { + $expected_row = array(); + foreach ($view->field as $id => $field) { + // Original field key is expected. + $expected_row[$id] = $row->{$field->field_alias}; + } + $expected[] = $expected_row; + } + + // Use an AJAX call, as this will return decoded JSON data. + $this->assertIdentical($this->drupalGetAJAX('test/serialize/field'), $expected); + + // Test a random alias for the name field, this should be replaced. $random_name = $this->randomName(); $this->drupalPost($row_options, array('row_options[aliases][name]' => $random_name), t('Apply')); $this->drupalPost(NULL, array(), t('Save')); @@ -116,12 +137,13 @@ public function testUIFieldAlias() { foreach ($view->result as $row) { $expected_row = array(); foreach ($view->field as $id => $field) { + // Replacement alias is expected. $expected_row[$random_name] = $row->{$field->field_alias}; } $expected[] = $expected_row; } - $this->assertIdentical($this->drupalGet('test/serialize/field', array(), array('Content-type: application/json')), json_encode($expected)); + $this->assertIdentical($this->drupalGetAJAX('test/serialize/field'), $expected); } }