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\CategoryDataImport\Communication; |
||
9 | |||
10 | use Codeception\Test\Unit; |
||
11 | use Generated\Shared\Transfer\CategoryTransfer; |
||
12 | use Generated\Shared\Transfer\DataImporterConfigurationTransfer; |
||
13 | use Generated\Shared\Transfer\DataImporterReaderConfigurationTransfer; |
||
14 | use Generated\Shared\Transfer\StoreTransfer; |
||
15 | use Spryker\Zed\Category\CategoryDependencyProvider; |
||
16 | use Spryker\Zed\Category\Communication\Plugin\Category\MainChildrenPropagationCategoryStoreAssignerPlugin; |
||
17 | use Spryker\Zed\CategoryDataImport\Communication\Plugin\DataImport\CategoryStoreDataImportPlugin; |
||
18 | |||
19 | /** |
||
20 | * Auto-generated group annotations |
||
21 | * |
||
22 | * @group SprykerTest |
||
23 | * @group Zed |
||
24 | * @group CategoryDataImport |
||
25 | * @group Communication |
||
26 | * @group CategoryStoreDataImportPluginTest |
||
27 | * Add your own group annotations below this line |
||
28 | */ |
||
29 | class CategoryStoreDataImportPluginTest extends Unit |
||
30 | { |
||
31 | /** |
||
32 | * @var string |
||
33 | */ |
||
34 | protected const STORE_NAME_DE = 'DE'; |
||
35 | |||
36 | /** |
||
37 | * @var string |
||
38 | */ |
||
39 | protected const STORE_NAME_AT = 'AT'; |
||
40 | |||
41 | /** |
||
42 | * @var string |
||
43 | */ |
||
44 | protected const CATEGORY_NAME_TEST = 'test-category'; |
||
45 | |||
46 | /** |
||
47 | * @var string |
||
48 | */ |
||
49 | protected const CATEGORY_PARENT_NAME_TEST = 'parent-test-category'; |
||
50 | |||
51 | /** |
||
52 | * @var string |
||
53 | */ |
||
54 | protected const CATEGORY_CHILD_NAME_TEST = 'child-test-category'; |
||
55 | |||
56 | /** |
||
57 | * @var int |
||
58 | */ |
||
59 | protected const EXPECTED_IMPORT_COUNT = 1; |
||
60 | |||
61 | /** |
||
62 | * @uses \Spryker\Zed\CategoryDataImport\CategoryDataImportConfig::IMPORT_TYPE_CATEGORY_STORE |
||
63 | * |
||
64 | * @var string |
||
65 | */ |
||
66 | protected const IMPORT_TYPE_CATEGORY_STORE = 'category-store'; |
||
67 | |||
68 | /** |
||
69 | * @var \SprykerTest\Zed\CategoryDataImport\CategoryDataImportCommunicationTester |
||
70 | */ |
||
71 | protected $tester; |
||
72 | |||
73 | /** |
||
74 | * @return void |
||
75 | */ |
||
76 | protected function setUp(): void |
||
77 | { |
||
78 | parent::setUp(); |
||
79 | |||
80 | $this->tester->setDependency( |
||
81 | CategoryDependencyProvider::PLUGIN_CATEGORY_STORE_ASSIGNER, |
||
82 | new MainChildrenPropagationCategoryStoreAssignerPlugin(), |
||
83 | ); |
||
84 | } |
||
85 | |||
86 | /** |
||
87 | * @return void |
||
88 | */ |
||
89 | public function testImportWillImportCategoryStoreRelationshipsData(): void |
||
90 | { |
||
91 | // Arrange |
||
92 | $this->tester->haveStore([StoreTransfer::NAME => static::STORE_NAME_DE]); |
||
93 | $this->tester->haveStore([StoreTransfer::NAME => static::STORE_NAME_AT]); |
||
94 | $this->tester->haveCategory([CategoryTransfer::CATEGORY_KEY => static::CATEGORY_NAME_TEST]); |
||
95 | |||
96 | $dataImporterReaderConfigurationTransfer = (new DataImporterReaderConfigurationTransfer()) |
||
97 | ->setFileName(codecept_data_dir() . 'import/category_store.csv'); |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
98 | |||
99 | $dataImportConfigurationTransfer = (new DataImporterConfigurationTransfer()) |
||
100 | ->setReaderConfiguration($dataImporterReaderConfigurationTransfer); |
||
101 | |||
102 | $categoryStoreDataImportPlugin = new CategoryStoreDataImportPlugin(); |
||
103 | |||
104 | // Act |
||
105 | $dataImporterReportTransfer = $categoryStoreDataImportPlugin->import($dataImportConfigurationTransfer); |
||
106 | |||
107 | // Assert |
||
108 | $this->assertTrue($dataImporterReportTransfer->getIsSuccess()); |
||
109 | |||
110 | $this->assertSame( |
||
111 | static::EXPECTED_IMPORT_COUNT, |
||
112 | $dataImporterReportTransfer->getImportedDataSetCount(), |
||
113 | sprintf( |
||
114 | 'Imported number of category stores is %s, expected %s.', |
||
115 | $dataImporterReportTransfer->getImportedDataSetCount(), |
||
116 | static::EXPECTED_IMPORT_COUNT, |
||
117 | ), |
||
118 | ); |
||
119 | } |
||
120 | |||
121 | /** |
||
122 | * @return void |
||
123 | */ |
||
124 | public function testImportWillImportCategoryStoreRelationshipsDataWithParentInheritance(): void |
||
125 | { |
||
126 | // Arrange |
||
127 | $this->tester->haveStore([StoreTransfer::NAME => static::STORE_NAME_DE]); |
||
128 | $this->tester->haveStore([StoreTransfer::NAME => static::STORE_NAME_AT]); |
||
129 | $parentCategoryTransfer = $this->tester->haveCategory([ |
||
130 | CategoryTransfer::CATEGORY_KEY => static::CATEGORY_PARENT_NAME_TEST, |
||
131 | ]); |
||
132 | |||
133 | $categoryTransfer = $this->tester->haveCategory([ |
||
134 | CategoryTransfer::CATEGORY_KEY => static::CATEGORY_CHILD_NAME_TEST, |
||
135 | CategoryTransfer::PARENT_CATEGORY_NODE => $parentCategoryTransfer->getCategoryNode(), |
||
136 | ]); |
||
137 | |||
138 | $dataImporterReaderConfigurationTransfer = (new DataImporterReaderConfigurationTransfer()) |
||
139 | ->setFileName(codecept_data_dir() . 'import/category_store_parent.csv'); |
||
140 | |||
141 | $dataImportConfigurationTransfer = (new DataImporterConfigurationTransfer()) |
||
142 | ->setReaderConfiguration($dataImporterReaderConfigurationTransfer); |
||
143 | |||
144 | $categoryStoreDataImportPlugin = new CategoryStoreDataImportPlugin(); |
||
145 | |||
146 | // Act |
||
147 | $dataImporterReportTransfer = $categoryStoreDataImportPlugin->import($dataImportConfigurationTransfer); |
||
148 | |||
149 | // Assert |
||
150 | $this->assertTrue($dataImporterReportTransfer->getIsSuccess()); |
||
151 | |||
152 | $this->assertSame( |
||
153 | 2, |
||
154 | $this->tester->countCategoryStoreRelations($parentCategoryTransfer->getIdCategoryOrFail()), |
||
155 | 'Number of store does not match expected value.', |
||
156 | ); |
||
157 | $this->assertSame( |
||
158 | 1, |
||
159 | $this->tester->countCategoryStoreRelations($categoryTransfer->getIdCategoryOrFail()), |
||
160 | 'Number of store does not match expected value.', |
||
161 | ); |
||
162 | } |
||
163 | |||
164 | /** |
||
165 | * @return void |
||
166 | */ |
||
167 | public function testGetImportTypeReturnsExpectedTypeOfImporter(): void |
||
168 | { |
||
169 | //Assign |
||
170 | $priceProductScheduleDataImportPlugin = new CategoryStoreDataImportPlugin(); |
||
171 | |||
172 | //Act |
||
173 | $importType = $priceProductScheduleDataImportPlugin->getImportType(); |
||
174 | |||
175 | //Assert |
||
176 | $this->assertSame(static::IMPORT_TYPE_CATEGORY_STORE, $importType); |
||
177 | } |
||
178 | } |
||
179 |