1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace ApplicationTest\Action; |
6
|
|
|
|
7
|
|
|
use Application\Action\ExportTransactionLinesAction; |
8
|
|
|
use Application\Model\TransactionLine; |
9
|
|
|
use ApplicationTest\Traits\TestWithTransaction; |
10
|
|
|
use PHPUnit\Framework\TestCase; |
11
|
|
|
|
12
|
|
|
class ExcelExportActionTest extends TestCase |
13
|
|
|
{ |
14
|
|
|
use TestWithTransaction; |
15
|
|
|
|
16
|
|
|
public function testExportTransactionLines(): void |
17
|
|
|
{ |
18
|
|
|
// Query to generate the Excel file |
19
|
|
|
$hostname = 'my-ichtus.lan'; |
20
|
|
|
$qb = _em()->getRepository(TransactionLine::class)->createQueryBuilder('tl'); |
21
|
|
|
$action = new ExportTransactionLinesAction($hostname); |
22
|
|
|
$url = $action->generate($qb->getQuery()); |
23
|
|
|
|
24
|
|
|
$this->assertStringStartsWith('https://' . $hostname . '/export/transactionLines/', $url); |
25
|
|
|
|
26
|
|
|
// Try to download the Excel file |
27
|
|
|
$ch = curl_init(); |
28
|
|
|
curl_setopt($ch, CURLOPT_URL, $url); |
|
|
|
|
29
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
30
|
|
|
curl_setopt($ch, CURLOPT_HEADER, true); |
31
|
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); |
32
|
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); |
33
|
|
|
$response = curl_exec($ch); |
|
|
|
|
34
|
|
|
$headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE); |
|
|
|
|
35
|
|
|
$header = mb_substr($response, 0, $headerSize); |
36
|
|
|
|
37
|
|
|
$this->assertStringContainsStringIgnoringCase('content-disposition: attachment; filename=Ichtus_compta_ecritures', $header); |
38
|
|
|
$this->assertStringContainsStringIgnoringCase('content-type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', $header); |
39
|
|
|
$this->assertRegExp('/content\-length: [1-9][0-9]+/', $header); |
40
|
|
|
} |
41
|
|
|
} |
42
|
|
|
|