‪TYPO3CMS  11.5
ExportControllerTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use PHPUnit\Framework\MockObject\MockObject;
21 use Psr\Http\Message\ResponseFactoryInterface;
28 use TYPO3\CMS\Core\Page\PageRenderer;
32 use TYPO3\TestingFramework\Core\AccessibleObjectInterface;
33 
35 {
39  protected ‪$exportControllerMock;
40 
41  protected function ‪setUp(): void
42  {
43  parent::setUp();
44  $container = $this->getContainer();
45  $this->exportControllerMock = $this->getAccessibleMock(
46  ExportController::class,
47  ['dummy'],
48  [
49  $container->get(IconFactory::class),
50  $container->get(PageRenderer::class),
51  $container->get(UriBuilder::class),
52  $container->get(ModuleTemplateFactory::class),
53  $container->get(ResponseFactoryInterface::class),
54  ]
55  );
56  }
57 
61  public function ‪tableSelectOptionsContainPresetsTable(): void
62  {
63  ‪$tables = $this->exportControllerMock->_call('getTableSelectOptions');
64  self::assertArrayHasKey('tx_impexp_presets', ‪$tables);
65  }
66 
67  public function ‪resetExcludedRecordsDataProvider(): array
68  {
69  return [
70  [
71  ['exclude' => ['tt_content:1' => '1', 'tt_content:2' => '1']],
72  ['tt_content:1' => '1', 'tt_content:2' => '1'],
73  ],
74  [
75  ['exclude' => ['tt_content:1' => '1', 'tt_content:2' => '1'], 'resetExclude' => 1],
76  [],
77  ],
78  ];
79  }
80 
85  public function ‪resetExcludedRecords(array $requestParams, array $expected): void
86  {
87  $request = (new ‪ServerRequest())
88  ->withAttribute('applicationType', ‪SystemEnvironmentBuilder::REQUESTTYPE_BE)
89  ->withParsedBody([
90  'tx_impexp' => array_merge(['download_export' => 1], $requestParams),
91  ]);
92 
93  try {
94  $this->exportControllerMock->mainAction($request);
95  } catch (PropagateResponseException $e) {
96  // This exception is expected and not part of this test.
97  // It serves to prevent rendering the view.
98  }
99 
101  $export = $this->exportControllerMock->_get('export');
102  self::assertEquals($expected, $export->getExcludeMap());
103  }
104 
109  {
110  $request = (new ServerRequest())
111  ->withAttribute('applicationType', ‪SystemEnvironmentBuilder::REQUESTTYPE_BE)
112  ->withParsedBody([
113  'tx_impexp' => [
114  'download_export' => 1,
115  ],
116  ]);
117 
118  $this->expectExceptionCode(1629196918);
119  $this->expectException(PropagateResponseException::class);
120  $this->exportControllerMock->mainAction($request);
121  }
122 }
‪TYPO3\CMS\Impexp\Tests\Functional\Export\ExportControllerTest
Definition: ExportControllerTest.php:35
‪TYPO3\CMS\Impexp\Tests\Functional\Export\ExportControllerTest\throwsPropagateResponseExceptionOnDownloadExportFile
‪throwsPropagateResponseExceptionOnDownloadExportFile()
Definition: ExportControllerTest.php:107
‪TYPO3\CMS\Impexp\Tests\Functional\Export\ExportControllerTest\$exportControllerMock
‪ExportController MockObject AccessibleObjectInterface $exportControllerMock
Definition: ExportControllerTest.php:38
‪TYPO3\CMS\Backend\Template\ModuleTemplateFactory
Definition: ModuleTemplateFactory.php:29
‪TYPO3\CMS\Core\Core\SystemEnvironmentBuilder
Definition: SystemEnvironmentBuilder.php:41
‪TYPO3\CMS\Core\Core\SystemEnvironmentBuilder\REQUESTTYPE_BE
‪const REQUESTTYPE_BE
Definition: SystemEnvironmentBuilder.php:45
‪TYPO3\CMS\Impexp\Tests\Functional\Export\ExportControllerTest\resetExcludedRecords
‪resetExcludedRecords(array $requestParams, array $expected)
Definition: ExportControllerTest.php:84
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:34
‪TYPO3\CMS\Impexp\Controller\ExportController
Definition: ExportController.php:48
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:40
‪TYPO3\CMS\Impexp\Tests\Functional\Export\ExportControllerTest\tableSelectOptionsContainPresetsTable
‪tableSelectOptionsContainPresetsTable()
Definition: ExportControllerTest.php:60
‪TYPO3\CMS\Impexp\Tests\Functional\Export\ExportControllerTest\resetExcludedRecordsDataProvider
‪resetExcludedRecordsDataProvider()
Definition: ExportControllerTest.php:66
‪TYPO3\CMS\Core\Http\ServerRequest
Definition: ServerRequest.php:37
‪TYPO3\CMS\Core\Http\PropagateResponseException
Definition: PropagateResponseException.php:47
‪TYPO3\CMS\Impexp\Tests\Functional\Export
Definition: ExportControllerTest.php:18
‪TYPO3\CMS\Impexp\Tests\Functional\AbstractImportExportTestCase
Definition: AbstractImportExportTestCase.php:34
‪TYPO3\CMS\Impexp\Tests\Functional\Export\ExportControllerTest\setUp
‪setUp()
Definition: ExportControllerTest.php:40
‪TYPO3\CMS\Impexp\Export
Definition: Export.php:48
‪TYPO3\CMS\Impexp\Export\$tables
‪array $tables
Definition: Export.php:87