|
| 1 | +<?php declare(strict_types=1); |
| 2 | + |
| 3 | +namespace Neusta\Pimcore\ImportExportBundle\Tests\Integration\Documents\Export; |
| 4 | + |
| 5 | +use Neusta\Pimcore\ImportExportBundle\Documents\Import\PageImporter; |
| 6 | +use Neusta\Pimcore\TestingFramework\Database\ResetDatabase; |
| 7 | +use Pimcore\Test\KernelTestCase; |
| 8 | +use Spatie\Snapshots\MatchesSnapshots; |
| 9 | + |
| 10 | +class PageImporterTest extends KernelTestCase |
| 11 | +{ |
| 12 | + use MatchesSnapshots; |
| 13 | + use ResetDatabase; |
| 14 | + |
| 15 | + private PageImporter $importer; |
| 16 | + |
| 17 | + protected function setUp(): void |
| 18 | + { |
| 19 | + $this->importer = self::getContainer()->get(PageImporter::class); |
| 20 | + } |
| 21 | + |
| 22 | + public function testSinglePageImport_exceptional_case(): void |
| 23 | + { |
| 24 | + $yaml = |
| 25 | + <<<YAML |
| 26 | + pages: |
| 27 | + - |
| 28 | + page: |
| 29 | + id: 999 |
| 30 | + path: /path-does-not-exist/ |
| 31 | + key: test_document_1 |
| 32 | + YAML; |
| 33 | + |
| 34 | + $this->expectException(\InvalidArgumentException::class); |
| 35 | + $this->expectExceptionMessage('Neither parentId nor path leads to a valid parent element'); |
| 36 | + $this->importer->parseYaml($yaml); |
| 37 | + } |
| 38 | + |
| 39 | + public function testSinglePageExport_regular_case_parent_id(): void |
| 40 | + { |
| 41 | + $yaml = |
| 42 | + <<<YAML |
| 43 | + pages: |
| 44 | + - |
| 45 | + page: |
| 46 | + id: 999 |
| 47 | + parentId: 1 |
| 48 | + type: email |
| 49 | + published: false |
| 50 | + path: /path/will/be/overwritten/by/parent_id/ |
| 51 | + language: fr |
| 52 | + navigation_name: 'Mein Dokument' |
| 53 | + navigation_title: 'Mein Dokument - Titel' |
| 54 | + key: test_document_1 |
| 55 | + title: 'Titel meines Dokuments' |
| 56 | + controller: Irgend/ein/Controller |
| 57 | + YAML; |
| 58 | + |
| 59 | + $pages = $this->importer->parseYaml($yaml); |
| 60 | + self::assertEquals(999, $pages[0]->getId()); |
| 61 | + self::assertEquals('/', $pages[0]->getPath()); |
| 62 | + |
| 63 | + self::assertEquals('test_document_1', $pages[0]->getKey()); |
| 64 | + self::assertEquals('Titel meines Dokuments', $pages[0]->getTitle()); |
| 65 | + self::assertEquals('email', $pages[0]->getType()); |
| 66 | + self::assertEquals('Irgend/ein/Controller', $pages[0]->getController()); |
| 67 | + self::assertEquals('fr', $pages[0]->getProperty('language')); |
| 68 | + self::assertEquals('Mein Dokument', $pages[0]->getProperty('navigation_name')); |
| 69 | + self::assertEquals('Mein Dokument - Titel', $pages[0]->getProperty('navigation_title')); |
| 70 | + } |
| 71 | + |
| 72 | + public function testSinglePageExport_regular_case_path(): void |
| 73 | + { |
| 74 | + $yaml = |
| 75 | + <<<YAML |
| 76 | + pages: |
| 77 | + - |
| 78 | + page: |
| 79 | + id: 999 |
| 80 | + parentId: 99999 |
| 81 | + type: email |
| 82 | + published: false |
| 83 | + path: / |
| 84 | + language: fr |
| 85 | + navigation_name: 'Mein Dokument' |
| 86 | + navigation_title: 'Mein Dokument - Titel' |
| 87 | + key: test_document_1 |
| 88 | + title: 'Titel meines Dokuments' |
| 89 | + controller: Irgend/ein/Controller |
| 90 | + YAML; |
| 91 | + |
| 92 | + $pages = $this->importer->parseYaml($yaml); |
| 93 | + self::assertEquals(999, $pages[0]->getId()); |
| 94 | + self::assertEquals('/', $pages[0]->getPath()); |
| 95 | + self::assertEquals(1, $pages[0]->getParentId()); |
| 96 | + |
| 97 | + self::assertEquals('test_document_1', $pages[0]->getKey()); |
| 98 | + self::assertEquals('Titel meines Dokuments', $pages[0]->getTitle()); |
| 99 | + self::assertEquals('email', $pages[0]->getType()); |
| 100 | + self::assertEquals('Irgend/ein/Controller', $pages[0]->getController()); |
| 101 | + self::assertEquals('fr', $pages[0]->getProperty('language')); |
| 102 | + self::assertEquals('Mein Dokument', $pages[0]->getProperty('navigation_name')); |
| 103 | + self::assertEquals('Mein Dokument - Titel', $pages[0]->getProperty('navigation_title')); |
| 104 | + } |
| 105 | + |
| 106 | + public function testSinglePageImport_tree_case(): void |
| 107 | + { |
| 108 | + $yaml = |
| 109 | + <<<YAML |
| 110 | + pages: |
| 111 | + - |
| 112 | + page: |
| 113 | + parentId: 1 |
| 114 | + id: 999 |
| 115 | + path: /my_path/ |
| 116 | + key: test_document_1 |
| 117 | + - |
| 118 | + page: |
| 119 | + parentId: 999 |
| 120 | + id: 1000 |
| 121 | + path: /my_path/test_document_1/ |
| 122 | + key: test_document_1_1 |
| 123 | + - |
| 124 | + page: |
| 125 | + parentId: 1000 |
| 126 | + id: 1001 |
| 127 | + path: /my_path/test_document_1/test_document_1_1/ |
| 128 | + key: test_document_1_1_1 |
| 129 | + YAML; |
| 130 | + |
| 131 | + $pages = $this->importer->parseYaml($yaml); |
| 132 | + |
| 133 | + self::assertEquals('/test_document_1/test_document_1_1/', $pages[2]->getPath()); |
| 134 | + } |
| 135 | +} |
0 commit comments