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\AclDataImport\Communication\Plugin; |
||||
9 | |||||
10 | use Codeception\Test\Unit; |
||||
11 | use Generated\Shared\Transfer\AclRoleCriteriaTransfer; |
||||
12 | use Generated\Shared\Transfer\DataImporterConfigurationTransfer; |
||||
13 | use Generated\Shared\Transfer\DataImporterReaderConfigurationTransfer; |
||||
14 | use Generated\Shared\Transfer\DataImporterReportTransfer; |
||||
15 | use Spryker\Zed\AclDataImport\AclDataImportConfig; |
||||
16 | use Spryker\Zed\AclDataImport\Communication\Plugin\AclRoleDataImportPlugin; |
||||
17 | use Spryker\Zed\DataImport\Business\Exception\DataImportException; |
||||
18 | |||||
19 | /** |
||||
20 | * Auto-generated group annotations |
||||
21 | * |
||||
22 | * @group SprykerTest |
||||
23 | * @group Zed |
||||
24 | * @group AclDataImport |
||||
25 | * @group Communication |
||||
26 | * @group Plugin |
||||
27 | * @group AclRoleDataImportPluginTest |
||||
28 | * Add your own group annotations below this line |
||||
29 | */ |
||||
30 | class AclRoleDataImportPluginTest extends Unit |
||||
31 | { |
||||
32 | /** |
||||
33 | * @var int |
||||
34 | */ |
||||
35 | protected const EXPECTED_IMPORT_COUNT = 3; |
||||
36 | |||||
37 | /** |
||||
38 | * @var string |
||||
39 | */ |
||||
40 | protected const ACL_ROLE_NAME_1 = 'User'; |
||||
41 | |||||
42 | /** |
||||
43 | * @var string |
||||
44 | */ |
||||
45 | protected const ACL_ROLE_NAME_2 = 'Moderator'; |
||||
46 | |||||
47 | /** |
||||
48 | * @var string |
||||
49 | */ |
||||
50 | protected const ACL_ROLE_NAME_3 = 'Administrator'; |
||||
51 | |||||
52 | /** |
||||
53 | * @var \SprykerTest\Zed\AclRoleDataImport\AclDataImportCommunicationTester |
||||
54 | */ |
||||
55 | protected $tester; |
||||
56 | |||||
57 | /** |
||||
58 | * @return void |
||||
59 | */ |
||||
60 | public function testImportImportsAclRole(): void |
||||
61 | { |
||||
62 | // Arrange |
||||
63 | $this->tester->deleteRoles( |
||||
64 | (new AclRoleCriteriaTransfer())->setNames( |
||||
65 | [static::ACL_ROLE_NAME_1, static::ACL_ROLE_NAME_2, static::ACL_ROLE_NAME_3], |
||||
66 | ), |
||||
67 | ); |
||||
68 | $dataImporterReaderConfigurationTransfer = new DataImporterReaderConfigurationTransfer(); |
||||
69 | $dataImporterReaderConfigurationTransfer->setFileName(codecept_data_dir() . 'import/acl_role.csv'); |
||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||
70 | |||||
71 | $dataImportConfigurationTransfer = (new DataImporterConfigurationTransfer()) |
||||
72 | ->setReaderConfiguration($dataImporterReaderConfigurationTransfer); |
||||
73 | |||||
74 | // Act |
||||
75 | $dataImportPlugin = $this->getAclRoleDataImportPlugin(); |
||||
76 | $dataImporterReportTransfer = $dataImportPlugin->import($dataImportConfigurationTransfer); |
||||
77 | |||||
78 | // Assert |
||||
79 | $this->assertInstanceOf(DataImporterReportTransfer::class, $dataImporterReportTransfer); |
||||
80 | $this->assertTrue($dataImporterReportTransfer->getIsSuccess()); |
||||
81 | $this->assertSame(static::EXPECTED_IMPORT_COUNT, $dataImporterReportTransfer->getImportedDataSetCount()); |
||||
82 | } |
||||
83 | |||||
84 | /** |
||||
85 | * @group foo |
||||
86 | * |
||||
87 | * @return void |
||||
88 | */ |
||||
89 | public function testImportImportsAclRoleWithEmptyName(): void |
||||
90 | { |
||||
91 | // Arrange |
||||
92 | $dataImporterReaderConfigurationTransfer = new DataImporterReaderConfigurationTransfer(); |
||||
93 | $dataImporterReaderConfigurationTransfer->setFileName(codecept_data_dir() . 'import/acl_role_empty_name.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
![]() |
|||||
94 | |||||
95 | $dataImportConfigurationTransfer = (new DataImporterConfigurationTransfer()) |
||||
96 | ->setReaderConfiguration($dataImporterReaderConfigurationTransfer) |
||||
97 | ->setThrowException(true); |
||||
98 | |||||
99 | // Assert |
||||
100 | $this->expectException(DataImportException::class); |
||||
101 | $this->expectExceptionMessage('Field "name" cannot be empty'); |
||||
102 | |||||
103 | // Act |
||||
104 | ($this->getAclRoleDataImportPlugin())->import($dataImportConfigurationTransfer); |
||||
105 | } |
||||
106 | |||||
107 | /** |
||||
108 | * @return void |
||||
109 | */ |
||||
110 | public function testGetImportTypeReturnsTypeOfImporter(): void |
||||
111 | { |
||||
112 | // Arrange |
||||
113 | $dataImportPlugin = $this->getAclRoleDataImportPlugin(); |
||||
114 | |||||
115 | // Act |
||||
116 | $importType = $dataImportPlugin->getImportType(); |
||||
117 | |||||
118 | // Assert |
||||
119 | $this->assertEquals(AclDataImportConfig::IMPORT_TYPE_ACL_ROLE, $importType); |
||||
120 | } |
||||
121 | |||||
122 | /** |
||||
123 | * @return \Spryker\Zed\AclDataImport\Communication\Plugin\AclRoleDataImportPlugin |
||||
124 | */ |
||||
125 | protected function getAclRoleDataImportPlugin(): AclRoleDataImportPlugin |
||||
126 | { |
||||
127 | return new AclRoleDataImportPlugin(); |
||||
128 | } |
||||
129 | } |
||||
130 |