Issues (3641)

Plugin/AclGroupRoleDataImportPluginTest.php (3 issues)

Labels
Severity
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 Generated\Shared\Transfer\GroupCriteriaTransfer;
16
use Generated\Shared\Transfer\GroupTransfer;
17
use Generated\Shared\Transfer\RoleTransfer;
18
use Spryker\Zed\AclDataImport\AclDataImportConfig;
19
use Spryker\Zed\AclDataImport\Communication\Plugin\AclGroupRoleDataImportPlugin;
20
use Spryker\Zed\DataImport\Business\Exception\DataImportException;
21
22
/**
23
 * Auto-generated group annotations
24
 *
25
 * @group SprykerTest
26
 * @group Zed
27
 * @group AclDataImport
28
 * @group Communication
29
 * @group Plugin
30
 * @group AclGroupRoleDataImportPluginTest
31
 * Add your own group annotations below this line
32
 */
33
class AclGroupRoleDataImportPluginTest extends Unit
34
{
35
    /**
36
     * @var string
37
     */
38
    protected const ACL_GROUP_NAME_1 = 'Group foo';
39
40
    /**
41
     * @var string
42
     */
43
    protected const ACL_GROUP_NAME_2 = 'Group bar';
44
45
    /**
46
     * @var string
47
     */
48
    protected const ACL_GROUP_REFERENCE_1 = 'group_foo';
49
50
    /**
51
     * @var string
52
     */
53
    protected const ACL_GROUP_REFERENCE_2 = 'group_bar';
54
55
    /**
56
     * @var string
57
     */
58
    protected const ACL_ROLE_NAME_1 = 'Role foo';
59
60
    /**
61
     * @var string
62
     */
63
    protected const ACL_ROLE_NAME_2 = 'Role bar';
64
65
    /**
66
     * @var string
67
     */
68
    protected const ACL_ROLE_REFERENCE_1 = 'role_foo';
69
70
    /**
71
     * @var string
72
     */
73
    protected const ACL_ROLE_REFERENCE_2 = 'role_bar';
74
75
    /**
76
     * @var int
77
     */
78
    protected const EXPECTED_IMPORT_COUNT = 2;
79
80
    /**
81
     * @var \SprykerTest\Zed\AclRoleDataImport\AclDataImportCommunicationTester
82
     */
83
    protected $tester;
84
85
    /**
86
     * @return void
87
     */
88
    public function testImportImportsAclGroupRole(): void
89
    {
90
        // Arrange
91
        $this->tester->deleteRoles(
92
            (new AclRoleCriteriaTransfer())->setNames([static::ACL_ROLE_NAME_1, static::ACL_ROLE_NAME_2]),
93
        );
94
        $this->tester->deleteGroups(
95
            (new GroupCriteriaTransfer())->setNames([static::ACL_GROUP_NAME_1, static::ACL_GROUP_NAME_2]),
96
        );
97
98
        $this->tester->haveGroup(
99
            [
100
                GroupTransfer::NAME => static::ACL_GROUP_NAME_1,
101
                GroupTransfer::REFERENCE => static::ACL_GROUP_REFERENCE_1,
102
            ],
103
        );
104
        $this->tester->haveGroup(
105
            [
106
                GroupTransfer::NAME => static::ACL_GROUP_NAME_2,
107
                GroupTransfer::REFERENCE => static::ACL_GROUP_REFERENCE_2,
108
            ],
109
        );
110
        $this->tester->haveRole(
111
            [
112
                RoleTransfer::NAME => static::ACL_ROLE_NAME_1,
113
                RoleTransfer::REFERENCE => static::ACL_ROLE_REFERENCE_1,
114
            ],
115
        );
116
        $this->tester->haveRole(
117
            [
118
                RoleTransfer::NAME => static::ACL_ROLE_NAME_2,
119
                RoleTransfer::REFERENCE => static::ACL_ROLE_REFERENCE_2,
120
            ],
121
        );
122
123
        $dataImporterReaderConfigurationTransfer = new DataImporterReaderConfigurationTransfer();
124
        $dataImporterReaderConfigurationTransfer->setFileName(codecept_data_dir() . 'import/acl_group_role.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 ignore-call  annotation

124
        $dataImporterReaderConfigurationTransfer->setFileName(/** @scrutinizer ignore-call */ codecept_data_dir() . 'import/acl_group_role.csv');
Loading history...
125
126
        $dataImportConfigurationTransfer = (new DataImporterConfigurationTransfer())
127
            ->setReaderConfiguration($dataImporterReaderConfigurationTransfer);
128
129
        // Act
130
        $dataImportPlugin = $this->getAclGroupRoleDataImportPlugin();
131
        $dataImporterReportTransfer = $dataImportPlugin->import($dataImportConfigurationTransfer);
132
133
        // Assert
134
        $this->assertInstanceOf(DataImporterReportTransfer::class, $dataImporterReportTransfer);
135
        $this->assertTrue($dataImporterReportTransfer->getIsSuccess());
136
        $this->assertSame(static::EXPECTED_IMPORT_COUNT, $dataImporterReportTransfer->getImportedDataSetCount());
137
    }
138
139
    /**
140
     * @return void
141
     */
142
    public function testImportImportsAclGroupRoleWithEmptyGroupReference(): void
143
    {
144
        // Arrange
145
        $dataImporterReaderConfigurationTransfer = new DataImporterReaderConfigurationTransfer();
146
        $dataImporterReaderConfigurationTransfer->setFileName(codecept_data_dir() . 'import/acl_group_role_empty_group_reference.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 ignore-call  annotation

146
        $dataImporterReaderConfigurationTransfer->setFileName(/** @scrutinizer ignore-call */ codecept_data_dir() . 'import/acl_group_role_empty_group_reference.csv');
Loading history...
147
148
        $dataImportConfigurationTransfer = (new DataImporterConfigurationTransfer())
149
            ->setReaderConfiguration($dataImporterReaderConfigurationTransfer);
150
        $dataImportConfigurationTransfer->setThrowException(true);
151
152
        // Assert
153
        $this->expectException(DataImportException::class);
154
        $this->expectExceptionMessage('Field "group_reference" cannot be empty');
155
156
        // Act
157
        $this->getAclGroupRoleDataImportPlugin()->import($dataImportConfigurationTransfer);
158
    }
159
160
    /**
161
     * @return void
162
     */
163
    public function testImportImportsAclGroupRoleWithEmptyRoleReference(): void
164
    {
165
        // Arrange
166
        $dataImporterReaderConfigurationTransfer = new DataImporterReaderConfigurationTransfer();
167
        $dataImporterReaderConfigurationTransfer->setFileName(codecept_data_dir() . 'import/acl_group_role_empty_role_reference.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 ignore-call  annotation

167
        $dataImporterReaderConfigurationTransfer->setFileName(/** @scrutinizer ignore-call */ codecept_data_dir() . 'import/acl_group_role_empty_role_reference.csv');
Loading history...
168
169
        $dataImportConfigurationTransfer = (new DataImporterConfigurationTransfer())
170
            ->setReaderConfiguration($dataImporterReaderConfigurationTransfer)
171
            ->setThrowException(true);
172
173
        // Assert
174
        $this->expectException(DataImportException::class);
175
        $this->expectExceptionMessage('Field "role_reference" cannot be empty');
176
177
        // Act
178
        $this->getAclGroupRoleDataImportPlugin()->import($dataImportConfigurationTransfer);
179
    }
180
181
    /**
182
     * @return void
183
     */
184
    public function testGetImportTypeReturnsTypeOfImporter(): void
185
    {
186
        // Arrange
187
        $dataImportPlugin = $this->getAclGroupRoleDataImportPlugin();
188
189
        // Act
190
        $importType = $dataImportPlugin->getImportType();
191
192
        // Assert
193
        $this->assertEquals(AclDataImportConfig::IMPORT_TYPE_ACL_GROUP_ROLE, $importType);
194
    }
195
196
    /**
197
     * @return \Spryker\Zed\AclDataImport\Communication\Plugin\AclGroupRoleDataImportPlugin
198
     */
199
    protected function getAclGroupRoleDataImportPlugin(): AclGroupRoleDataImportPlugin
200
    {
201
        return new AclGroupRoleDataImportPlugin();
202
    }
203
}
204