|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the Sonata Project package. |
|
7
|
|
|
* |
|
8
|
|
|
* (c) Thomas Rabaix <[email protected]> |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
11
|
|
|
* file that was distributed with this source code. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Sonata\AdminBundle\Tests\Export; |
|
15
|
|
|
|
|
16
|
|
|
use PHPUnit\Framework\TestCase; |
|
17
|
|
|
use Sonata\AdminBundle\Export\Exporter; |
|
18
|
|
|
use Sonata\Exporter\Source\ArraySourceIterator; |
|
19
|
|
|
use Sonata\Exporter\Source\SourceIteratorInterface; |
|
20
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* NEXT_MAJOR: remove this class. |
|
24
|
|
|
* |
|
25
|
|
|
* @group legacy |
|
26
|
|
|
*/ |
|
27
|
|
|
class ExporterTest extends TestCase |
|
28
|
|
|
{ |
|
29
|
|
|
public function testFilter(): void |
|
30
|
|
|
{ |
|
31
|
|
|
$this->expectException(\RuntimeException::class); |
|
32
|
|
|
|
|
33
|
|
|
$source = $this->createMock(SourceIteratorInterface::class); |
|
34
|
|
|
|
|
35
|
|
|
$exporter = new Exporter(); |
|
|
|
|
|
|
36
|
|
|
$exporter->getResponse('foo', 'foo', $source); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @dataProvider getGetResponseTests |
|
41
|
|
|
*/ |
|
42
|
|
|
public function testGetResponse($format, $filename, $contentType): void |
|
43
|
|
|
{ |
|
44
|
|
|
$source = new ArraySourceIterator([ |
|
45
|
|
|
['foo' => 'bar'], |
|
46
|
|
|
]); |
|
47
|
|
|
|
|
48
|
|
|
$exporter = new Exporter(); |
|
|
|
|
|
|
49
|
|
|
$response = $exporter->getResponse($format, $filename, $source); |
|
50
|
|
|
|
|
51
|
|
|
$this->assertInstanceOf(Response::class, $response); |
|
52
|
|
|
$this->assertSame($contentType, $response->headers->get('Content-Type')); |
|
53
|
|
|
// Quotes does not appear on some sonata versions. |
|
54
|
|
|
$this->assertRegExp('/attachment; filename="?'.$filename.'"?/', $response->headers->get('Content-Disposition')); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function getGetResponseTests() |
|
58
|
|
|
{ |
|
59
|
|
|
return [ |
|
60
|
|
|
['json', 'foo.json', 'application/json'], |
|
61
|
|
|
['xml', 'foo.xml', 'text/xml'], |
|
62
|
|
|
['xls', 'foo.xls', 'application/vnd.ms-excel'], |
|
63
|
|
|
['csv', 'foo.csv', 'text/csv'], |
|
64
|
|
|
]; |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.