Issue #2560553 by joelpittet, subhojit777, mdrummond, iMiksu, Manuel Garcia, mr.baileys, dawehner: Views render pipeline is escaping CustomBooleanTest
parent
b921d2b3c0
commit
f26b06587f
|
@ -9,6 +9,7 @@ namespace Drupal\views\Plugin\views\field;
|
|||
|
||||
use Drupal\Component\Utility\Xss as UtilityXss;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\views\Render\ViewsRenderPipelineSafeString;
|
||||
use Drupal\views\ResultRow;
|
||||
use Drupal\views\ViewExecutable;
|
||||
use Drupal\views\Plugin\views\display\DisplayPluginBase;
|
||||
|
@ -118,7 +119,8 @@ class Boolean extends FieldPluginBase {
|
|||
}
|
||||
|
||||
if ($this->options['type'] == 'custom') {
|
||||
return $value ? UtilityXss::filterAdmin($this->options['type_custom_true']) : UtilityXss::filterAdmin($this->options['type_custom_false']);
|
||||
$custom_value = $value ? $this->options['type_custom_true'] : $this->options['type_custom_false'];
|
||||
return ViewsRenderPipelineSafeString::create(UtilityXss::filterAdmin($custom_value));
|
||||
}
|
||||
elseif (isset($this->formats[$this->options['type']])) {
|
||||
return $value ? $this->formats[$this->options['type']][0] : $this->formats[$this->options['type']][1];
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
{#
|
||||
/**
|
||||
* @file
|
||||
* Theme override to display all the fields in a views row.
|
||||
*
|
||||
* The reason for this template is to override the theme function provided by
|
||||
* views to allow tests to run against the twig template.
|
||||
*/
|
||||
#}
|
||||
{% include '@views/views-view-field.html.twig' %}
|
||||
Use posts instead of twigs to protect your llamas from escaping the field.
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
namespace Drupal\views_ui\Tests;
|
||||
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Drupal\views\Views;
|
||||
|
||||
/**
|
||||
|
@ -101,12 +102,85 @@ class CustomBooleanTest extends UITestBase {
|
|||
$view = Views::getView('test_view');
|
||||
$output = $view->preview();
|
||||
$output = \Drupal::service('renderer')->renderRoot($output);
|
||||
$this->{$values['test']}(strpos($output, $values['true']), SafeMarkup::format('Expected custom boolean TRUE value %value in output for %type', ['%value' => $values['true'], '%type' => $type]));
|
||||
$this->{$values['test']}(strpos($output, $values['false']), SafeMarkup::format('Expected custom boolean FALSE value %value in output for %type', ['%value' => $values['false'], '%type' => $type]));
|
||||
}
|
||||
}
|
||||
|
||||
$replacements = array('%type' => $type);
|
||||
$this->{$values['test']}(strpos($output, $values['true']), format_string('Expected custom boolean TRUE value in output for %type.', $replacements));
|
||||
$this->{$values['test']}(strpos($output, $values['false']), format_string('Expected custom boolean FALSE value in output for %type', $replacements));
|
||||
/**
|
||||
* Tests the setting and output of custom labels for boolean values.
|
||||
*/
|
||||
public function testCustomOptionTemplate() {
|
||||
// Install theme to test with template system.
|
||||
\Drupal::service('theme_handler')->install(['views_test_theme']);
|
||||
|
||||
// Set the default theme for Views preview.
|
||||
$this->config('system.theme')
|
||||
->set('default', 'views_test_theme')
|
||||
->save();
|
||||
$this->assertEqual($this->config('system.theme')->get('default'), 'views_test_theme');
|
||||
|
||||
// Add the boolean field handler to the test view.
|
||||
$view = Views::getView('test_view');
|
||||
$view->setDisplay();
|
||||
|
||||
$view->displayHandlers->get('default')->overrideOption('fields', [
|
||||
'age' => [
|
||||
'id' => 'age',
|
||||
'table' => 'views_test_data',
|
||||
'field' => 'age',
|
||||
'relationship' => 'none',
|
||||
'plugin_id' => 'boolean',
|
||||
],
|
||||
]);
|
||||
$view->save();
|
||||
|
||||
$this->executeView($view);
|
||||
|
||||
$custom_true = 'Yay';
|
||||
$custom_false = 'Nay';
|
||||
|
||||
// Set up some custom value mappings for different types.
|
||||
$custom_values = array(
|
||||
'plain' => array(
|
||||
'true' => $custom_true,
|
||||
'false' => $custom_false,
|
||||
'test' => 'assertTrue',
|
||||
),
|
||||
'allowed tag' => array(
|
||||
'true' => '<p>' . $custom_true . '</p>',
|
||||
'false' => '<p>' . $custom_false . '</p>',
|
||||
'test' => 'assertTrue',
|
||||
),
|
||||
'disallowed tag' => array(
|
||||
'true' => '<script>' . $custom_true . '</script>',
|
||||
'false' => '<script>' . $custom_false . '</script>',
|
||||
'test' => 'assertFalse',
|
||||
),
|
||||
);
|
||||
|
||||
// Run the same tests on each type.
|
||||
foreach ($custom_values as $type => $values) {
|
||||
$options = array(
|
||||
'options[type]' => 'custom',
|
||||
'options[type_custom_true]' => $values['true'],
|
||||
'options[type_custom_false]' => $values['false'],
|
||||
);
|
||||
$this->drupalPostForm('admin/structure/views/nojs/handler/test_view/default/field/age', $options, 'Apply');
|
||||
|
||||
// Save the view.
|
||||
$this->drupalPostForm('admin/structure/views/view/test_view', array(), 'Save');
|
||||
|
||||
$view = Views::getView('test_view');
|
||||
$output = $view->preview();
|
||||
$output = \Drupal::service('renderer')->renderRoot($output);
|
||||
$this->{$values['test']}(strpos($output, $values['true']), SafeMarkup::format('Expected custom boolean TRUE value %value in output for %type', ['%value' => $values['true'], '%type' => $type]));
|
||||
$this->{$values['test']}(strpos($output, $values['false']), SafeMarkup::format('Expected custom boolean FALSE value %value in output for %type', ['%value' => $values['false'], '%type' => $type]));
|
||||
|
||||
// Assert that we are using the correct template.
|
||||
$this->setRawContent($output);
|
||||
$this->assertText('llama', 'Loaded the correct views-view-field.html.twig template');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue