You are here

public function FieldNumericTest::providerTestFieldNumeric in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/views/tests/src/Kernel/Handler/FieldNumericTest.php \Drupal\Tests\views\Kernel\Handler\FieldNumericTest::providerTestFieldNumeric()

Data provider for testFieldNumeric.

Return value

array The data set containing field settings, values to set and expected values.

File

core/modules/views/tests/src/Kernel/Handler/FieldNumericTest.php, line 50

Class

FieldNumericTest
Tests the core Drupal\views\Plugin\views\field\Numeric handler.

Namespace

Drupal\Tests\views\Kernel\Handler

Code

public function providerTestFieldNumeric() {
  return [
    'no-formating' => [
      [],
      [
        0,
        0.1234,
        -0.1234,
        1000.1234,
        -1000.1234,
      ],
      [
        '0',
        '0.1234',
        '-0.1234',
        '1,000.1234',
        '-1,000.1234',
      ],
    ],
    'precision_2-hide_empty-hide_zero' => [
      [
        'hide_empty' => TRUE,
        'precision' => 2,
        'set_precision' => TRUE,
        'empty_zero' => TRUE,
        'id' => 'age',
        'table' => 'views_test_data',
        'field' => 'age',
        'relationship' => 'none',
      ],
      [
        0,
        0.1234,
        -0.1234,
        1000.1234,
        -1000.1234,
        0.0001,
        -0.0001,
        NULL,
        '',
      ],
      [
        '',
        '0.12',
        '-0.12',
        '1,000.12',
        '-1,000.12',
        '',
        '',
        '',
        '',
      ],
    ],
    'decimal-separator' => [
      [
        'hide_empty' => TRUE,
        'decimal' => ',',
        'separator' => '.',
        'empty_zero' => TRUE,
        'id' => 'age',
        'table' => 'views_test_data',
        'field' => 'age',
        'relationship' => 'none',
      ],
      [
        0.1234,
        -0.1234,
        1000.1234,
        -1000.1234,
      ],
      [
        '0,1234',
        '-0,1234',
        '1.000,1234',
        '-1.000,1234',
      ],
    ],
    'precision_2-no_separator' => [
      [
        'hide_empty' => TRUE,
        'precision' => 2,
        'set_precision' => TRUE,
        'decimal' => ',',
        'separator' => '',
        'empty_zero' => TRUE,
        'id' => 'age',
        'table' => 'views_test_data',
        'field' => 'age',
        'relationship' => 'none',
      ],
      [
        1234,
        1234.01,
        -1234,
        -1234.01,
      ],
      [
        '1234,00',
        '1234,01',
        '-1234,00',
        '-1234,01',
      ],
    ],
    'precision_0-no_separator' => [
      [
        'hide_empty' => TRUE,
        'precision' => 0,
        'set_precision' => TRUE,
        'separator' => '',
        'empty_zero' => TRUE,
        'id' => 'age',
        'table' => 'views_test_data',
        'field' => 'age',
        'relationship' => 'none',
      ],
      [
        1234,
        1234.01,
        -1234,
        -1234.01,
      ],
      [
        '1234',
        '1234',
        '-1234',
        '-1234',
      ],
    ],
    'precision_0-hide_empty-zero_empty' => [
      [
        'hide_empty' => TRUE,
        'precision' => 0,
        'set_precision' => TRUE,
        'empty_zero' => TRUE,
        'id' => 'age',
        'table' => 'views_test_data',
        'field' => 'age',
        'relationship' => 'none',
        'prefix' => 'test: ',
      ],
      [
        0,
        0.1234,
        -0.1234,
        1000.1234,
        -1000.1234,
      ],
      [
        '',
        '',
        '',
        'test: 1,000',
        'test: -1,000',
      ],
    ],
    'precision_0-hide_empty-not_zero_empty' => [
      [
        'hide_empty' => TRUE,
        'precision' => 0,
        'set_precision' => TRUE,
        'empty_zero' => FALSE,
        'id' => 'age',
        'table' => 'views_test_data',
        'field' => 'age',
        'relationship' => 'none',
        'prefix' => '',
      ],
      [
        0,
        0.1234,
        -0.1234,
      ],
      [
        '0',
        '0',
        '0',
      ],
    ],
    'precision_2-hide_empty-not_zero_empty' => [
      [
        'hide_empty' => TRUE,
        'precision' => 2,
        'set_precision' => TRUE,
        'empty_zero' => FALSE,
        'id' => 'age',
        'table' => 'views_test_data',
        'field' => 'age',
        'relationship' => 'none',
        'prefix' => '',
      ],
      [
        0,
        0.001234,
        -0.001234,
        NULL,
      ],
      [
        '0.00',
        '0.00',
        '0.00',
        '',
      ],
    ],
  ];
}