‪TYPO3CMS  ‪main
ExportCommandTest.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\Attributes\Test;
21 use Symfony\Component\Console\Tester\CommandTester;
26 
28 {
29  #[Test]
30  public function ‪exportCommandRequiresNoArguments(): void
31  {
32  $exportMock = $this->getAccessibleMock(Export::class, ['setMetaData']);
33  $tester = new CommandTester(new ‪ExportCommand($exportMock));
34  $tester->execute([], []);
35 
36  self::assertEquals(0, $tester->getStatusCode());
37  }
38 
39  #[Test]
41  {
42  $fileName = 'empty_export';
43 
44  $exportMock = $this->getAccessibleMock(Export::class, ['setMetaData']);
45  $tester = new CommandTester(new ‪ExportCommand($exportMock));
46  $tester->execute(['filename' => $fileName], []);
47 
48  preg_match('/([^\s]*importexport[^\s]*)/', $tester->getDisplay(), $display);
49  $filePath = ‪Environment::getPublicPath() . '/' . $display[1];
50 
51  self::assertEquals(0, $tester->getStatusCode());
52  self::assertStringEndsWith('empty_export.xml', $filePath);
53  self::assertXmlFileEqualsXmlFile(__DIR__ . '/../Fixtures/XmlExports/empty.xml', $filePath);
54  }
55 
56  #[Test]
58  {
59  $input = [
60  'filename' => 'empty_export',
61  '--type' => ‪Export::FILETYPE_T3D,
62  '--pid' => 123,
64  '--table' => ['tt_content'],
65  '--record' => ['sys_category:6'],
66  '--list' => ['sys_category:123'],
67  '--include-related' => ['be_users'],
68  '--include-static' => ['sys_category'],
69  '--exclude' => ['be_users:3'],
70  '--exclude-disabled-records' => false,
71  '--exclude-html-css' => false,
72  '--title' => 'Export Command',
73  '--description' => 'The export which considers all arguments passed on the command line.',
74  '--notes' => 'This export is not for production use.',
75  '--dependency' => ['bootstrap_package'],
76  '--save-files-outside-export-file' => false,
77  ];
78 
79  $exportMock = $this->getAccessibleMock(Export::class, [
80  'setExportFileType', 'setExportFileName', 'setPid', 'setLevels', 'setTables', 'setRecord', 'setList',
81  'setRelOnlyTables', 'setRelStaticTables', 'setExcludeMap', 'setExcludeDisabledRecords',
82  'setIncludeExtFileResources', 'setTitle', 'setDescription', 'setNotes', 'setExtensionDependencies',
83  'setSaveFilesOutsideExportFile',
84  ]);
85  $exportMock->expects(self::once())->method('setExportFileName')->with(self::equalTo('empty_export'));
86  $exportMock->expects(self::once())->method('setExportFileType')->with(self::equalTo(‪Export::FILETYPE_T3D));
87  $exportMock->expects(self::once())->method('setPid')->with(self::equalTo(123));
88  $exportMock->expects(self::once())->method('setLevels')->with(self::equalTo(‪Export::LEVELS_RECORDS_ON_THIS_PAGE));
89  $exportMock->expects(self::once())->method('setTables')->with(self::equalTo(['tt_content']));
90  $exportMock->expects(self::once())->method('setRecord')->with(self::equalTo(['sys_category:6']));
91  $exportMock->expects(self::once())->method('setList')->with(self::equalTo(['sys_category:123']));
92  $exportMock->expects(self::once())->method('setRelOnlyTables')->with(self::equalTo(['be_users']));
93  $exportMock->expects(self::once())->method('setRelStaticTables')->with(self::equalTo(['sys_category']));
94  $exportMock->expects(self::once())->method('setExcludeMap')->with(self::equalTo(['be_users:3']));
95  $exportMock->expects(self::once())->method('setExcludeDisabledRecords')->with(self::equalTo(false));
96  $exportMock->expects(self::once())->method('setIncludeExtFileResources')->with(self::equalTo(true));
97  $exportMock->expects(self::once())->method('setTitle')->with(self::equalTo('Export Command'));
98  $exportMock->expects(self::once())->method('setDescription')->with(self::equalTo('The export which considers all arguments passed on the command line.'));
99  $exportMock->expects(self::once())->method('setNotes')->with(self::equalTo('This export is not for production use.'));
100  $exportMock->expects(self::once())->method('setExtensionDependencies')->with(self::equalTo(['bootstrap_package']));
101  $exportMock->expects(self::once())->method('setSaveFilesOutsideExportFile')->with(self::equalTo(false));
102 
103  $tester = new CommandTester(new ‪ExportCommand($exportMock));
104  $tester->execute($input);
105  }
106 }
‪TYPO3\CMS\Impexp\Tests\Functional\Command\ExportCommandTest\exportCommandPassesArgumentsToExportObject
‪exportCommandPassesArgumentsToExportObject()
Definition: ExportCommandTest.php:57
‪TYPO3\CMS\Core\Core\Environment\getPublicPath
‪static getPublicPath()
Definition: Environment.php:187
‪TYPO3\CMS\Impexp\Tests\Functional\Command\ExportCommandTest
Definition: ExportCommandTest.php:28
‪TYPO3\CMS\Impexp\Export\FILETYPE_T3D
‪const FILETYPE_T3D
Definition: Export.php:57
‪TYPO3\CMS\Impexp\Export\LEVELS_RECORDS_ON_THIS_PAGE
‪const LEVELS_RECORDS_ON_THIS_PAGE
Definition: Export.php:53
‪TYPO3\CMS\Impexp\Tests\Functional\Command\ExportCommandTest\exportCommandRequiresNoArguments
‪exportCommandRequiresNoArguments()
Definition: ExportCommandTest.php:30
‪TYPO3\CMS\Impexp\Tests\Functional\Command\ExportCommandTest\exportCommandSavesExportWithGivenFileName
‪exportCommandSavesExportWithGivenFileName()
Definition: ExportCommandTest.php:40
‪TYPO3\CMS\Impexp\Tests\Functional\AbstractImportExportTestCase
Definition: AbstractImportExportTestCase.php:33
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:41
‪TYPO3\CMS\Impexp\Export
Definition: Export.php:52
‪TYPO3\CMS\Impexp\Command\ExportCommand
Definition: ExportCommand.php:36
‪TYPO3\CMS\Impexp\Tests\Functional\Command
Definition: ExportCommandTest.php:18