1 | <?php |
||||
2 | |||||
3 | /** |
||||
4 | * MIT License |
||||
5 | * For full license information, please view the LICENSE file that was distributed with this source code. |
||||
6 | */ |
||||
7 | |||||
8 | namespace SprykerTest\Zed\CmsSlotBlockDataImport\Communication\Plugin; |
||||
9 | |||||
10 | use ArrayObject; |
||||
11 | use Codeception\Test\Unit; |
||||
12 | use Generated\Shared\Transfer\CategoryTransfer; |
||||
13 | use Generated\Shared\Transfer\CmsBlockTransfer; |
||||
14 | use Generated\Shared\Transfer\CmsSlotTemplateTransfer; |
||||
15 | use Generated\Shared\Transfer\CmsSlotTransfer; |
||||
16 | use Generated\Shared\Transfer\ProductAbstractTransfer; |
||||
17 | use Spryker\Zed\CmsSlotBlockDataImport\Communication\Plugin\CmsSlotBlockDataImportPlugin; |
||||
18 | use Spryker\Zed\DataImport\Business\Exception\DataImportException; |
||||
19 | |||||
20 | /** |
||||
21 | * Auto-generated group annotations |
||||
22 | * |
||||
23 | * @group SprykerTest |
||||
24 | * @group Zed |
||||
25 | * @group CmsSlotBlockDataImport |
||||
26 | * @group Communication |
||||
27 | * @group Plugin |
||||
28 | * @group CmsSlotBlockDataImportPluginTest |
||||
29 | * Add your own group annotations below this line |
||||
30 | */ |
||||
31 | class CmsSlotBlockDataImportPluginTest extends Unit |
||||
32 | { |
||||
33 | /** |
||||
34 | * @var string |
||||
35 | */ |
||||
36 | protected const CMS_SLOT_CONTENT_PROVIDER_TYPE = 'SprykerCmsSlotBlock'; |
||||
37 | |||||
38 | /** |
||||
39 | * @var string |
||||
40 | */ |
||||
41 | protected const CMS_SLOT_TEMPLATE_PATH = '@TestPage/views/pdp/pdp.twig'; |
||||
42 | |||||
43 | /** |
||||
44 | * @var string |
||||
45 | */ |
||||
46 | protected const CMS_SLOT_KEY = 'test-slot-key'; |
||||
47 | |||||
48 | /** |
||||
49 | * @var string |
||||
50 | */ |
||||
51 | protected const CMS_BLOCK_KEY = 'test-block-key'; |
||||
52 | |||||
53 | /** |
||||
54 | * @var string |
||||
55 | */ |
||||
56 | protected const CMS_PAGE_KEY = 'test-page-key'; |
||||
57 | |||||
58 | /** |
||||
59 | * @var string |
||||
60 | */ |
||||
61 | protected const CATEGORY_KEY = 'test-category-key'; |
||||
62 | |||||
63 | /** |
||||
64 | * @var string |
||||
65 | */ |
||||
66 | protected const PRODUCT_ABSTRACT_SKU = 'test-product-abstract-sku'; |
||||
67 | |||||
68 | /** |
||||
69 | * @var \SprykerTest\Zed\CmsSlotBlockDataImport\CmsSlotBlockDataImportCommunicationTester |
||||
70 | */ |
||||
71 | protected $tester; |
||||
72 | |||||
73 | /** |
||||
74 | * @return void |
||||
75 | */ |
||||
76 | public function setUp(): void |
||||
77 | { |
||||
78 | parent::setUp(); |
||||
79 | |||||
80 | $this->tester->ensureCmsSlotBlockTableIsEmpty(); |
||||
81 | $this->tester->ensureCmsSlotTemplateTableIsEmpty(); |
||||
82 | $this->tester->ensureCmsSlotTableIsEmpty(); |
||||
83 | $this->tester->removeCmsBlockByKey(static::CMS_BLOCK_KEY); |
||||
84 | } |
||||
85 | |||||
86 | /** |
||||
87 | * @return void |
||||
88 | */ |
||||
89 | public function testCmsSlotBlockDataImportThrowsExceptionWhenSlotTemplateDoesNotExist(): void |
||||
90 | { |
||||
91 | // Arrange |
||||
92 | $this->tester->haveCmsSlotInDb([ |
||||
93 | CmsSlotTransfer::KEY => static::CMS_SLOT_KEY, |
||||
94 | CmsSlotTransfer::CONTENT_PROVIDER_TYPE => static::CMS_SLOT_CONTENT_PROVIDER_TYPE, |
||||
95 | ]); |
||||
96 | $this->tester->haveCmsBlock([CmsBlockTransfer::KEY => static::CMS_BLOCK_KEY]); |
||||
97 | |||||
98 | $dataImportConfigurationTransfer = $this->tester->createDataImporterConfigurationTransfer(codecept_data_dir() . 'import/cms_slot_block.csv'); |
||||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
99 | |||||
100 | // Assert |
||||
101 | $this->expectException(DataImportException::class); |
||||
102 | $this->expectExceptionMessage('Could not find CMS slot template ID by path "' . static::CMS_SLOT_TEMPLATE_PATH . '"'); |
||||
103 | |||||
104 | // Act |
||||
105 | (new CmsSlotBlockDataImportPlugin())->import($dataImportConfigurationTransfer); |
||||
106 | } |
||||
107 | |||||
108 | /** |
||||
109 | * @return void |
||||
110 | */ |
||||
111 | public function testCmsSlotBlockDataImportThrowsExceptionWhenSlotDoesNotExist(): void |
||||
112 | { |
||||
113 | // Arrange |
||||
114 | $this->tester->haveCmsSlotTemplateInDb([CmsSlotTemplateTransfer::PATH => static::CMS_SLOT_TEMPLATE_PATH]); |
||||
115 | $this->tester->haveCmsBlock([CmsBlockTransfer::KEY => static::CMS_BLOCK_KEY]); |
||||
116 | |||||
117 | $dataImportConfigurationTransfer = $this->tester->createDataImporterConfigurationTransfer(codecept_data_dir() . 'import/cms_slot_block.csv'); |
||||
0 ignored issues
–
show
The function
codecept_data_dir was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
118 | |||||
119 | // Assert |
||||
120 | $this->expectException(DataImportException::class); |
||||
121 | $this->expectExceptionMessage('Could not find CMS slot ID by key "' . static::CMS_SLOT_KEY . '"'); |
||||
122 | |||||
123 | // Act |
||||
124 | (new CmsSlotBlockDataImportPlugin())->import($dataImportConfigurationTransfer); |
||||
125 | } |
||||
126 | |||||
127 | /** |
||||
128 | * @return void |
||||
129 | */ |
||||
130 | public function testCmsSlotBlockDataImportThrowsExceptionWhenBlockDoesNotExist(): void |
||||
131 | { |
||||
132 | // Arrange |
||||
133 | $this->tester->haveCmsSlotTemplateInDb([CmsSlotTemplateTransfer::PATH => static::CMS_SLOT_TEMPLATE_PATH]); |
||||
134 | $this->tester->haveCmsSlotInDb([ |
||||
135 | CmsSlotTransfer::KEY => static::CMS_SLOT_KEY, |
||||
136 | CmsSlotTransfer::CONTENT_PROVIDER_TYPE => static::CMS_SLOT_CONTENT_PROVIDER_TYPE, |
||||
137 | ]); |
||||
138 | |||||
139 | $dataImportConfigurationTransfer = $this->tester->createDataImporterConfigurationTransfer(codecept_data_dir() . 'import/cms_slot_block.csv'); |
||||
0 ignored issues
–
show
The function
codecept_data_dir was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
140 | |||||
141 | // Assert |
||||
142 | $this->expectException(DataImportException::class); |
||||
143 | $this->expectExceptionMessage('Could not find CMS Block ID by key "' . static::CMS_BLOCK_KEY . '"'); |
||||
144 | |||||
145 | // Act |
||||
146 | (new CmsSlotBlockDataImportPlugin())->import($dataImportConfigurationTransfer); |
||||
147 | } |
||||
148 | |||||
149 | /** |
||||
150 | * @return void |
||||
151 | */ |
||||
152 | public function testCmsSlotBlockDataImportPopulatesTableWhenDataIsCorrect(): void |
||||
153 | { |
||||
154 | // Arrange |
||||
155 | $cmsSlotTemplateTransfer = $this->tester->haveCmsSlotTemplateInDb([CmsSlotTemplateTransfer::PATH => static::CMS_SLOT_TEMPLATE_PATH]); |
||||
156 | $cmsSlotTransfer = $this->tester->haveCmsSlotInDb([ |
||||
157 | CmsSlotTransfer::KEY => static::CMS_SLOT_KEY, |
||||
158 | CmsSlotTransfer::CONTENT_PROVIDER_TYPE => static::CMS_SLOT_CONTENT_PROVIDER_TYPE, |
||||
159 | ]); |
||||
160 | $cmsBlockTransfer = $this->tester->haveCmsBlock([CmsBlockTransfer::KEY => static::CMS_BLOCK_KEY]); |
||||
161 | $categoryTransfer = $this->tester->haveCategory([CategoryTransfer::CATEGORY_KEY => static::CATEGORY_KEY]); |
||||
162 | $productAbstractTransfer = $this->tester->haveProductAbstract([ProductAbstractTransfer::SKU => static::PRODUCT_ABSTRACT_SKU]); |
||||
163 | $cmsSlotBlockConditions = $this->tester->getCmsSlotBlockConditions($categoryTransfer, $productAbstractTransfer); |
||||
164 | |||||
165 | $dataImportConfigurationTransfer = $this->tester->createDataImporterConfigurationTransfer(codecept_data_dir() . 'import/cms_slot_block.csv'); |
||||
0 ignored issues
–
show
The function
codecept_data_dir was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
166 | |||||
167 | // Act |
||||
168 | $dataImporterReportTransfer = (new CmsSlotBlockDataImportPlugin())->import($dataImportConfigurationTransfer); |
||||
169 | |||||
170 | $cmsSlotBlockTransferFromDb = $this->tester->findCmsSlotBlock( |
||||
171 | $cmsSlotTemplateTransfer->getIdCmsSlotTemplate(), |
||||
172 | $cmsSlotTransfer->getIdCmsSlot(), |
||||
173 | ); |
||||
174 | |||||
175 | //Assert |
||||
176 | $this->assertTrue($dataImporterReportTransfer->getIsSuccess()); |
||||
177 | $this->assertSame($cmsSlotBlockTransferFromDb->getIdCmsBlock(), $cmsBlockTransfer->getIdCmsBlock()); |
||||
178 | $this->assertSame(1, $cmsSlotBlockTransferFromDb->getPosition()); |
||||
179 | $this->assertEquals($cmsSlotBlockConditions, $cmsSlotBlockTransferFromDb->getConditions()); |
||||
180 | } |
||||
181 | |||||
182 | /** |
||||
183 | * @return void |
||||
184 | */ |
||||
185 | public function testCmsSlotBlockDataImportPopulatesTableWithEmptyConditionsWhenThereAreNoConditionsInCsv(): void |
||||
186 | { |
||||
187 | // Arrange |
||||
188 | $cmsSlotTemplateTransfer = $this->tester->haveCmsSlotTemplateInDb([CmsSlotTemplateTransfer::PATH => static::CMS_SLOT_TEMPLATE_PATH]); |
||||
189 | $cmsSlotTransfer = $this->tester->haveCmsSlotInDb([ |
||||
190 | CmsSlotTransfer::KEY => static::CMS_SLOT_KEY, |
||||
191 | CmsSlotTransfer::CONTENT_PROVIDER_TYPE => static::CMS_SLOT_CONTENT_PROVIDER_TYPE, |
||||
192 | ]); |
||||
193 | $this->tester->haveCmsBlock([CmsBlockTransfer::KEY => static::CMS_BLOCK_KEY]); |
||||
194 | |||||
195 | $dataImportConfigurationTransfer = $this->tester->createDataImporterConfigurationTransfer(codecept_data_dir() . 'import/cms_slot_block_without_conditions.csv'); |
||||
0 ignored issues
–
show
The function
codecept_data_dir was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
196 | |||||
197 | // Act |
||||
198 | (new CmsSlotBlockDataImportPlugin())->import($dataImportConfigurationTransfer); |
||||
199 | |||||
200 | $cmsSlotBlockTransferFromDb = $this->tester->findCmsSlotBlock( |
||||
201 | $cmsSlotTemplateTransfer->getIdCmsSlotTemplate(), |
||||
202 | $cmsSlotTransfer->getIdCmsSlot(), |
||||
203 | ); |
||||
204 | |||||
205 | //Assert |
||||
206 | $this->assertEquals(new ArrayObject(), $cmsSlotBlockTransferFromDb->getConditions()); |
||||
207 | } |
||||
208 | } |
||||
209 |