Issues (3641)

Plugin/AclGroupDataImportPluginTest.php (2 issues)

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\DataImporterConfigurationTransfer;
12
use Generated\Shared\Transfer\DataImporterReaderConfigurationTransfer;
13
use Generated\Shared\Transfer\DataImporterReportTransfer;
14
use Generated\Shared\Transfer\GroupCriteriaTransfer;
15
use Spryker\Zed\AclDataImport\AclDataImportConfig;
16
use Spryker\Zed\AclDataImport\Communication\Plugin\AclGroupDataImportPlugin;
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 AclGroupDataImportPluginTest
28
 * Add your own group annotations below this line
29
 */
30
class AclGroupDataImportPluginTest extends Unit
31
{
32
    /**
33
     * @var int
34
     */
35
    protected const EXPECTED_IMPORT_COUNT = 2;
36
37
    /**
38
     * @var string
39
     */
40
    protected const ACL_GROUP_NAME_1 = 'Foo group';
41
42
    /**
43
     * @var string
44
     */
45
    protected const ACL_GROUP_NAME_2 = 'Bar group';
46
47
    /**
48
     * @var \SprykerTest\Zed\AclRoleDataImport\AclDataImportCommunicationTester
49
     */
50
    protected $tester;
51
52
    /**
53
     * @return void
54
     */
55
    public function testImportImportsAclGroup(): void
56
    {
57
        // Arrange
58
        $this->tester->deleteGroups((
59
            new GroupCriteriaTransfer())->setNames([static::ACL_GROUP_NAME_1, static::ACL_GROUP_NAME_2]));
60
61
        $dataImporterReaderConfigurationTransfer = new DataImporterReaderConfigurationTransfer();
62
        $dataImporterReaderConfigurationTransfer->setFileName(codecept_data_dir() . 'import/acl_group.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

62
        $dataImporterReaderConfigurationTransfer->setFileName(/** @scrutinizer ignore-call */ codecept_data_dir() . 'import/acl_group.csv');
Loading history...
63
64
        $dataImportConfigurationTransfer = (new DataImporterConfigurationTransfer())
65
            ->setReaderConfiguration($dataImporterReaderConfigurationTransfer);
66
67
        // Act
68
        $dataImportPlugin = $this->getAclGroupDataImportPlugin();
69
        $dataImporterReportTransfer = $dataImportPlugin->import($dataImportConfigurationTransfer);
70
71
        // Assert
72
        $this->assertInstanceOf(DataImporterReportTransfer::class, $dataImporterReportTransfer);
73
        $this->assertTrue($dataImporterReportTransfer->getIsSuccess());
74
        $this->assertSame(static::EXPECTED_IMPORT_COUNT, $dataImporterReportTransfer->getImportedDataSetCount());
75
    }
76
77
    /**
78
     * @return void
79
     */
80
    public function testImportImportsAclGroupWithEmptyName(): void
81
    {
82
        // Arrange
83
        $dataImporterReaderConfigurationTransfer = new DataImporterReaderConfigurationTransfer();
84
        $dataImporterReaderConfigurationTransfer->setFileName(codecept_data_dir() . 'import/acl_group_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 ignore-call  annotation

84
        $dataImporterReaderConfigurationTransfer->setFileName(/** @scrutinizer ignore-call */ codecept_data_dir() . 'import/acl_group_empty_name.csv');
Loading history...
85
86
        $dataImportConfigurationTransfer = (new DataImporterConfigurationTransfer())
87
            ->setReaderConfiguration($dataImporterReaderConfigurationTransfer)
88
            ->setThrowException(true);
89
90
        // Assert
91
        $this->expectException(DataImportException::class);
92
        $this->expectExceptionMessage('Field "name" cannot be empty');
93
94
        // Act
95
        $this->getAclGroupDataImportPlugin()->import($dataImportConfigurationTransfer);
96
    }
97
98
    /**
99
     * @return void
100
     */
101
    public function testGetImportTypeReturnsTypeOfImporter(): void
102
    {
103
        // Arrange
104
        $dataImportPlugin = $this->getAclGroupDataImportPlugin();
105
106
        // Act
107
        $importType = $dataImportPlugin->getImportType();
108
109
        // Assert
110
        $this->assertEquals(AclDataImportConfig::IMPORT_TYPE_ACL_GROUP, $importType);
111
    }
112
113
    /**
114
     * @return \Spryker\Zed\AclDataImport\Communication\Plugin\AclGroupDataImportPlugin
115
     */
116
    protected function getAclGroupDataImportPlugin(): AclGroupDataImportPlugin
117
    {
118
        return new AclGroupDataImportPlugin();
119
    }
120
}
121