You are here

public function MultiresponseNormalizerTest::testNormalize in Subrequests 8.2

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

@covers ::normalize

File

tests/src/Unit/Normalizer/MultiresponseNormalizerTest.php, line 47

Class

MultiresponseNormalizerTest
@coversDefaultClass \Drupal\subrequests\Normalizer\MultiresponseNormalizer @group subrequests

Namespace

Drupal\Tests\subrequests\Normalizer

Code

public function testNormalize() {
  $sub_content_type = $this
    ->getRandomGenerator()
    ->string();
  $data = [
    Response::create('Foo!'),
    Response::create('Bar'),
  ];
  $actual = $this->sut
    ->normalize($data, NULL, [
    'sub-content-type' => $sub_content_type,
  ]);
  $parts = explode(', ', $actual['headers']['Content-Type']);
  $parts = explode('; ', $parts[0]);
  parse_str($parts[1], $parts);
  $delimiter = substr($parts['boundary'], 1, strlen($parts['boundary']) - 2);
  $this
    ->assertStringStartsWith('--' . $delimiter, $actual['content']);
  $this
    ->assertStringEndsWith('--' . $delimiter . '--', $actual['content']);
  $this
    ->assertRegExp("/\r\nFoo!\r\n/", $actual['content']);
  $this
    ->assertRegExp("/\r\nBar\r\n/", $actual['content']);
}