‪TYPO3CMS  ‪main
ImportExportUtilityTest.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\DataProvider;
21 use PHPUnit\Framework\Attributes\Test;
25 
27 {
28  public static function ‪importFailsDataProvider(): array
29  {
30  return [
31  'path to not existing file' => [
32  'EXT:impexp/Tests/Functional/Fixtures/XmlImports/me_does_not_exist.xml',
33  ],
34  'unsupported file extension' => [
35  'EXT:impexp/Tests/Functional/Fixtures/XmlImports/unsupported.json',
36  ],
37  'missing required extension' => [
38  'EXT:impexp/Tests/Functional/Fixtures/XmlImports/sys_category_table_with_news.xml',
39  ],
40  ];
41  }
42 
43  #[DataProvider('importFailsDataProvider')]
44  #[Test]
45  public function ‪importFails(string $filePath): void
46  {
47  $this->expectException(\ErrorException::class);
48  $this->expectExceptionMessage('No page records imported');
49 
50  $importUtilityMock = $this->getAccessibleMock(
51  ImportExportUtility::class,
52  null,
53  ['eventDispatcher' => new ‪NoopEventDispatcher()]
54  );
55  $importUtilityMock->importT3DFile($filePath, 0);
56  }
57 
58  #[Test]
59  public function ‪importSucceeds(): void
60  {
61  $filePath = 'EXT:impexp/Tests/Functional/Fixtures/XmlImports/pages-and-ttcontent.xml';
62 
63  $importUtilityMock = $this->getAccessibleMock(
64  ImportExportUtility::class,
65  null,
66  ['eventDispatcher' => new ‪NoopEventDispatcher()]
67  );
68  $result = $importUtilityMock->importT3DFile($filePath, 0);
69 
70  self::assertEquals(1, $result);
71  }
72 }
‪TYPO3\CMS\Impexp\Tests\Functional\Utility\ImportExportUtilityTest\importSucceeds
‪importSucceeds()
Definition: ImportExportUtilityTest.php:59
‪TYPO3\CMS\Impexp\Tests\Functional\Utility\ImportExportUtilityTest\importFails
‪importFails(string $filePath)
Definition: ImportExportUtilityTest.php:45
‪TYPO3\CMS\Impexp\Tests\Functional\Utility
Definition: ImportExportUtilityTest.php:18
‪TYPO3\CMS\Impexp\Utility\ImportExportUtility
Definition: ImportExportUtility.php:33
‪TYPO3\CMS\Impexp\Tests\Functional\Utility\ImportExportUtilityTest
Definition: ImportExportUtilityTest.php:27
‪TYPO3\CMS\Core\EventDispatcher\NoopEventDispatcher
Definition: NoopEventDispatcher.php:29
‪TYPO3\CMS\Impexp\Tests\Functional\AbstractImportExportTestCase
Definition: AbstractImportExportTestCase.php:33
‪TYPO3\CMS\Impexp\Tests\Functional\Utility\ImportExportUtilityTest\importFailsDataProvider
‪static importFailsDataProvider()
Definition: ImportExportUtilityTest.php:28