You are here

public function TwigConvertTest::providerTestJsonDecodeValues in Twig Tools 8

Provides test data for jsonDecode.

Return value

array An array of test JSON strings and their rendered equivalents.

File

tests/src/Unit/TwigConvertTest.php, line 246

Class

TwigConvertTest
Tests to ensure conversions filters work correctly.

Namespace

Drupal\Tests\twig_tools\Unit

Code

public function providerTestJsonDecodeValues() {
  return [
    [
      '{% set json = \'{
        "a": 1,
        "b": 2,
        "c": 3,
        "d": 4,
        "e": 5
      }\'|json_decode(true) %}{{ json|join(",") }}',
      '1,2,3,4,5',
    ],
    [
      '{% set json = \'{
        "aliceblue": "#f0f8ff",
        "antiquewhite": "#faebd7",
        "aqua": "#00ffff",
        "aquamarine": "#7fffd4",
        "azure": "#f0ffff",
        "beige": "#f5f5dc",
        "bisque": "#ffe4c4",
        "black": "#000000",
        "blanchedalmond": "#ffebcd",
        "blue": "#0000ff",
        "blueviolet": "#8a2be2",
        "brown": "#a52a2a"
      }\'|json_decode %}{{ json|join(", ") }}',
      '#f0f8ff, #faebd7, #00ffff, #7fffd4, #f0ffff, #f5f5dc, #ffe4c4, #000000, #ffebcd, #0000ff, #8a2be2, #a52a2a',
    ],
    [
      '{% set json = \'{
        "string": "string",
        "boolean_true": true,
        "boolean_false": false,
        "integer": 42,
        "float": 4.2
      }\'|json_decode %}{{ json|join(", ") }}',
      'string, 1, , 42, 4.2',
    ],
  ];
}