Commit e81caa00 authored by alexpott's avatar alexpott

Issue #2546924 by jhedstrom: Views fatal error when grouping on a field without a label set

parent 553e77cd
......@@ -583,7 +583,7 @@ public function renderGrouping($records, $groupings = array(), $group_rendered =
$group_content = $this->view->field[$field]->options['label'] . ': ' . $group_content;
}
if ($rendered) {
$grouping = $group_content;
$grouping = (string) $group_content;
if ($rendered_strip) {
$group_content = $grouping = strip_tags(htmlspecialchars_decode($group_content));
}
......
......@@ -118,7 +118,7 @@ function _testGrouping($stripped = FALSE) {
));
// Add the job and age field.
$view->displayHandlers->get('default')->overrideOption('fields', array(
$fields = array(
'name' => array(
'id' => 'name',
'table' => 'views_test_data',
......@@ -140,7 +140,8 @@ function _testGrouping($stripped = FALSE) {
'relationship' => 'none',
'label' => 'Age',
),
));
);
$view->displayHandlers->get('default')->overrideOption('fields', $fields);
// Now run the query and groupby the result.
$this->executeView($view);
......@@ -177,16 +178,16 @@ function _testGrouping($stripped = FALSE) {
if ($stripped) {
// Add some html to the result and expected value.
$rand = '<a data="' . $this->randomMachineName() . '" />';
$view->result[0]->views_test_data_job .= $rand;
$expected['Job: Singer']['rows']['Age: 25']['rows'][0]->views_test_data_job = 'Singer' . $rand;
$rand1 = '<a data="' . $this->randomMachineName() . '" />';
$view->result[0]->views_test_data_job .= $rand1;
$expected['Job: Singer']['rows']['Age: 25']['rows'][0]->views_test_data_job = 'Singer' . $rand1;
$expected['Job: Singer']['group'] = 'Job: Singer';
$rand = '<a data="' . $this->randomMachineName() . '" />';
$view->result[1]->views_test_data_job .= $rand;
$expected['Job: Singer']['rows']['Age: 27']['rows'][1]->views_test_data_job = 'Singer' . $rand;
$rand = '<a data="' . $this->randomMachineName() . '" />';
$view->result[2]->views_test_data_job .= $rand;
$expected['Job: Drummer']['rows']['Age: 28']['rows'][2]->views_test_data_job = 'Drummer' . $rand;
$rand2 = '<a data="' . $this->randomMachineName() . '" />';
$view->result[1]->views_test_data_job .= $rand2;
$expected['Job: Singer']['rows']['Age: 27']['rows'][1]->views_test_data_job = 'Singer' . $rand2;
$rand3 = '<a data="' . $this->randomMachineName() . '" />';
$view->result[2]->views_test_data_job .= $rand3;
$expected['Job: Drummer']['rows']['Age: 28']['rows'][2]->views_test_data_job = 'Drummer' . $rand3;
$expected['Job: Drummer']['group'] = 'Job: Drummer';
$view->style_plugin->options['grouping'][0] = array('field' => 'job', 'rendered' => TRUE, 'rendered_strip' => TRUE);
......@@ -204,19 +205,52 @@ function _testGrouping($stripped = FALSE) {
$sets_new_value = $view->style_plugin->renderGrouping($view->result, $view->style_plugin->options['grouping'], FALSE);
// Reorder the group structure to grouping by value.
$expected['Singer'] = $expected['Job: Singer'];
$expected['Singer']['rows']['25'] = $expected['Job: Singer']['rows']['Age: 25'];
$expected['Singer']['rows']['27'] = $expected['Job: Singer']['rows']['Age: 27'];
$expected['Drummer'] = $expected['Job: Drummer'];
$expected['Drummer']['rows']['28'] = $expected['Job: Drummer']['rows']['Age: 28'];
unset($expected['Job: Singer']);
unset($expected['Singer']['rows']['Age: 25']);
unset($expected['Singer']['rows']['Age: 27']);
unset($expected['Job: Drummer']);
unset($expected['Drummer']['rows']['Age: 28']);
$this->assertEqual($sets_new_value, $expected, 'The style plugins should proper group the results with grouping by the value.');
$new_expected = $expected;
$new_expected['Singer'] = $expected['Job: Singer'];
$new_expected['Singer']['rows']['25'] = $expected['Job: Singer']['rows']['Age: 25'];
$new_expected['Singer']['rows']['27'] = $expected['Job: Singer']['rows']['Age: 27'];
$new_expected['Drummer'] = $expected['Job: Drummer'];
$new_expected['Drummer']['rows']['28'] = $expected['Job: Drummer']['rows']['Age: 28'];
unset($new_expected['Job: Singer']);
unset($new_expected['Singer']['rows']['Age: 25']);
unset($new_expected['Singer']['rows']['Age: 27']);
unset($new_expected['Job: Drummer']);
unset($new_expected['Drummer']['rows']['Age: 28']);
$this->assertEqual($sets_new_value, $new_expected, 'The style plugins should proper group the results with grouping by the value.');
}
// Test that grouping works on fields having no label.
$fields['job']['label'] = '';
$view->destroy();
$view->setDisplay();
$view->initStyle();
$view->displayHandlers->get('default')->overrideOption('fields', $fields);
$view->style_plugin->options['grouping'] = array(
array('field' => 'job'),
array('field' => 'age'),
);
$this->executeView($view);
if ($stripped) {
$view->result[0]->views_test_data_job .= $rand1;
$view->result[1]->views_test_data_job .= $rand2;
$view->result[2]->views_test_data_job .= $rand3;
$view->style_plugin->options['grouping'][0] = array('field' => 'job', 'rendered' => TRUE, 'rendered_strip' => TRUE);
$view->style_plugin->options['grouping'][1] = array('field' => 'age', 'rendered' => TRUE, 'rendered_strip' => TRUE);
}
$sets_new_rendered = $view->style_plugin->renderGrouping($view->result, $view->style_plugin->options['grouping'], TRUE);
// Remove labels from expected results.
foreach ($expected as $job => $data) {
unset($expected[$job]);
$job = str_replace('Job: ', '', $job);
$data['group'] = $job;
$expected[$job] = $data;
}
$this->assertEqual($expected, $sets_new_rendered);
}
/**
......
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