You are here

public function JsonBlueprintDenormalizerTest::testDenormalize in Subrequests 3.x

Same name and namespace in other branches
  1. 8.2 tests/src/Unit/Normalizer/JsonBlueprintDenormalizerTest.php \Drupal\Tests\subrequests\Normalizer\JsonBlueprintDenormalizerTest::testDenormalize()

File

tests/src/Unit/Normalizer/JsonBlueprintDenormalizerTest.php, line 46

Class

JsonBlueprintDenormalizerTest
@coversDefaultClass \Drupal\subrequests\Normalizer\JsonBlueprintDenormalizer @group subrequests

Namespace

Drupal\Tests\subrequests\Normalizer

Code

public function testDenormalize() {
  $subrequests[] = [
    'uri' => 'lorem',
    'action' => 'view',
    'requestId' => 'foo',
    'body' => '"bar"',
    'headers' => [],
  ];
  $subrequests[] = [
    'uri' => 'ipsum',
    'action' => 'sing',
    'requestId' => 'oop',
    'body' => '[]',
    'waitFor' => [
      'foo',
    ],
  ];
  $subrequests[] = [
    'uri' => 'lorem%3F%7B%7Bipsum%7D%7D',
    // lorem?{{ipsum}}
    'action' => 'create',
    'requestId' => 'oof',
    'body' => '"bar"',
    'waitFor' => [
      'foo',
    ],
  ];
  $actual = $this->sut
    ->denormalize($subrequests, SubrequestsTree::class, 'json', []);
  $tree = new SubrequestsTree();
  $tree
    ->stack([
    new Subrequest([
      'waitFor' => [
        '<ROOT>',
      ],
      '_resolved' => FALSE,
      'body' => 'bar',
    ] + $subrequests[0]),
  ]);
  $tree
    ->stack([
    new Subrequest([
      'headers' => [],
      '_resolved' => FALSE,
      'body' => [],
    ] + $subrequests[1]),
    // Make sure the URL is decoded so we can perform apply regular
    // expressions to it.
    new Subrequest([
      'headers' => [],
      '_resolved' => FALSE,
      'body' => 'bar',
      'uri' => 'lorem?{{ipsum}}',
    ] + $subrequests[2]),
  ]);
  $this
    ->assertEquals($tree, $actual);
}