class MultiresponseNormalizerTest in Subrequests 8.2
Same name and namespace in other branches
- 3.x tests/src/Unit/Normalizer/MultiresponseNormalizerTest.php \Drupal\Tests\subrequests\Normalizer\MultiresponseNormalizerTest
@coversDefaultClass \Drupal\subrequests\Normalizer\MultiresponseNormalizer @group subrequests
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\subrequests\Normalizer\MultiresponseNormalizerTest
Expanded class hierarchy of MultiresponseNormalizerTest
File
- tests/
src/ Unit/ Normalizer/ MultiresponseNormalizerTest.php, line 13
Namespace
Drupal\Tests\subrequests\NormalizerView source
class MultiresponseNormalizerTest extends UnitTestCase {
/**
* @var \Drupal\subrequests\Normalizer\MultiresponseNormalizer
*/
protected $sut;
protected function setUp() {
parent::setUp();
$this->sut = new MultiresponseNormalizer();
}
/**
* @dataProvider dataProviderSupportsNormalization
* @covers ::supportsNormalization
*/
public function testSupportsNormalization($data, $format, $is_supported) {
$actual = $this->sut
->supportsNormalization($data, $format);
$this
->assertSame($is_supported, $actual);
}
public function dataProviderSupportsNormalization() {
return [
[
[
Response::create(''),
],
'multipart-related',
TRUE,
],
[
[],
'multipart-related',
TRUE,
],
[
[
Response::create(''),
],
'fail',
FALSE,
],
[
NULL,
'multipart-related',
FALSE,
],
[
[
Response::create(''),
NULL,
],
'multipart-related',
FALSE,
],
];
}
/**
* @covers ::normalize
*/
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']);
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MultiresponseNormalizerTest:: |
protected | property | ||
MultiresponseNormalizerTest:: |
public | function | ||
MultiresponseNormalizerTest:: |
protected | function |
Overrides UnitTestCase:: |
|
MultiresponseNormalizerTest:: |
public | function | @covers ::normalize | |
MultiresponseNormalizerTest:: |
public | function | @dataProvider dataProviderSupportsNormalization @covers ::supportsNormalization | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |