3 namespace Drupal\Tests\views\Kernel\Handler;
5 use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
6 use Drupal\views\Views;
9 * Tests the core Drupal\views\Plugin\views\field\Numeric handler.
12 * @see \Drupal\views\Plugin\views\field\Numeric
14 class FieldNumericTest extends ViewsKernelTestBase {
17 * Views used by this test.
21 public static $testViews = ['test_view'];
24 * Tests the Numeric handler with different settings.
26 * @dataProvider providerTestFieldNumeric
28 public function testFieldNumeric($field_settings, $values, $expected_values) {
29 $view = Views::getView('test_view');
32 if (!empty($field_settings)) {
33 $view->displayHandlers->get('default')->overrideOption('fields', ['age' => $field_settings]);
35 $this->executeView($view);
37 foreach ($values as $key => $value) {
38 $view->result[0]->views_test_data_age = $value;
39 $this->assertSame($expected_values[$key], $view->field['age']->advancedRender($view->result[0]));
44 * Data provider for testFieldNumeric.
47 * The data set containing field settings, values to set and expected
50 public function providerTestFieldNumeric() {
54 [0, 0.1234, -0.1234, 1000.1234, -1000.1234],
55 ['0', '0.1234', '-0.1234', '1,000.1234', '-1,000.1234'],
57 'precision_2-hide_empty-hide_zero' => [
61 'set_precision' => TRUE,
64 'table' => 'views_test_data',
66 'relationship' => 'none',
68 [0, 0.1234, -0.1234, 1000.1234, -1000.1234, 0.0001, -0.0001, NULL, ''],
69 ['', '0.12', '-0.12', '1,000.12', '-1,000.12', '', '', '', ''],
71 'decimal-separator' => [
78 'table' => 'views_test_data',
80 'relationship' => 'none',
82 [0.1234, -0.1234, 1000.1234, -1000.1234],
83 ['0,1234', '-0,1234', '1.000,1234', '-1.000,1234'],
85 'precision_2-no_separator' => [
89 'set_precision' => TRUE,
94 'table' => 'views_test_data',
96 'relationship' => 'none',
98 [1234, 1234.01, -1234, -1234.01],
99 ['1234,00', '1234,01', '-1234,00', '-1234,01'],
101 'precision_0-no_separator' => [
103 'hide_empty' => TRUE,
105 'set_precision' => TRUE,
107 'empty_zero' => TRUE,
109 'table' => 'views_test_data',
111 'relationship' => 'none',
113 [1234, 1234.01, -1234, -1234.01],
114 ['1234', '1234', '-1234', '-1234'],
116 'precision_0-hide_empty-zero_empty' => [
118 'hide_empty' => TRUE,
120 'set_precision' => TRUE,
121 'empty_zero' => TRUE,
123 'table' => 'views_test_data',
125 'relationship' => 'none',
126 'prefix' => 'test: ',
128 [0, 0.1234, -0.1234, 1000.1234, -1000.1234],
129 ['', '', '', 'test: 1,000', 'test: -1,000'],
131 'precision_0-hide_empty-not_zero_empty' => [
133 'hide_empty' => TRUE,
135 'set_precision' => TRUE,
136 'empty_zero' => FALSE,
138 'table' => 'views_test_data',
140 'relationship' => 'none',
143 [0, 0.1234, -0.1234],
146 'precision_2-hide_empty-not_zero_empty' => [
148 'hide_empty' => TRUE,
150 'set_precision' => TRUE,
151 'empty_zero' => FALSE,
153 'table' => 'views_test_data',
155 'relationship' => 'none',
158 [0, 0.001234, -0.001234, NULL],
159 ['0.00', '0.00', '0.00', ''],