You are here

public function MultiresponseJsonNormalizerTest::testNormalize in Subrequests 8.2

Same name and namespace in other branches
  1. 3.x tests/src/Unit/Normalizer/MultiresponseJsonNormalizerTest.php \Drupal\Tests\subrequests\Normalizer\MultiresponseJsonNormalizerTest::testNormalize()

@covers ::normalize

File

tests/src/Unit/Normalizer/MultiresponseJsonNormalizerTest.php, line 48

Class

MultiresponseJsonNormalizerTest
@coversDefaultClass \Drupal\subrequests\Normalizer\MultiresponseJsonNormalizer @group subrequests

Namespace

Drupal\Tests\subrequests\Normalizer

Code

public function testNormalize() {
  $sub_content_type = $this
    ->getRandomGenerator()
    ->string();
  $data = [
    Response::create('Foo!', 200, [
      'Content-ID' => '<f>',
    ]),
    Response::create('Bar', 200, [
      'Content-ID' => '<b>',
    ]),
  ];
  $actual = $this->sut
    ->normalize($data, NULL, [
    'sub-content-type' => $sub_content_type,
  ]);
  $this
    ->assertSame('application/json; type=' . $sub_content_type, $actual['headers']['Content-Type']);
  $parsed = Json::decode($actual['content']);
  $this
    ->assertSame('Foo!', $parsed['f']['body']);
  $this
    ->assertSame('Bar', $parsed['b']['body']);
}