Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
namespace Drupal\Tests\subrequests\Normalizer;
use Drupal\subrequests\Normalizer\MultiresponseNormalizer;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\HttpFoundation\Response;
/**
* @coversDefaultClass \Drupal\subrequests\Normalizer\MultiresponseNormalizer
* @group subrequests
*/
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() {
$delimiter = $this->getRandomGenerator()->string();
$data = [Response::create('Foo!'), Response::create('Bar')];
$actual = $this->sut->normalize($data, NULL, ['delimiter' => $delimiter]);
$this->assertStringStartsWith('--' . $delimiter, $actual);
$this->assertStringEndsWith('--' . $delimiter . '--', $actual);
$this->assertRegExp("/\r\nFoo!\r\n/", $actual);
$this->assertRegExp("/\r\nBar\r\n/", $actual);
}
}