6
6
namespace Magento \AdvancedPricingImportExport \Model \Export ;
7
7
8
8
use Magento \Framework \App \Filesystem \DirectoryList ;
9
+ use Magento \TestFramework \Indexer \TestCase ;
10
+ use Magento \TestFramework \Helper \Bootstrap ;
11
+ use Magento \Framework \Filesystem ;
12
+ use Magento \AdvancedPricingImportExport \Model \Export \AdvancedPricing as ExportAdvancedPricing ;
13
+ use Magento \Catalog \Api \ProductRepositoryInterface ;
14
+ use Magento \Catalog \Model \Product ;
15
+ use Magento \ImportExport \Model \Export \Adapter \Csv as ExportAdapterCsv ;
16
+ use Magento \AdvancedPricingImportExport \Model \Import \AdvancedPricing as ImportAdvancedPricing ;
17
+ use Magento \ImportExport \Model \Import \Source \Csv as ImportSourceCsv ;
18
+ use Magento \ImportExport \Model \Import ;
9
19
10
- class AdvancedPricingTest extends \Magento \TestFramework \Indexer \TestCase
20
+ /**
21
+ * Advanced pricing test
22
+ */
23
+ class AdvancedPricingTest extends TestCase
11
24
{
12
25
/**
13
26
* @var \Magento\AdvancedPricingImportExport\Model\Export\AdvancedPricing
@@ -24,9 +37,11 @@ class AdvancedPricingTest extends \Magento\TestFramework\Indexer\TestCase
24
37
*/
25
38
protected $ fileSystem ;
26
39
40
+ // @codingStandardsIgnoreStart
27
41
public static function setUpBeforeClass ()
28
42
{
29
- $ db = \Magento \TestFramework \Helper \Bootstrap::getInstance ()->getBootstrap ()
43
+ $ db = Bootstrap::getInstance ()
44
+ ->getBootstrap ()
30
45
->getApplication ()
31
46
->getDbInstance ();
32
47
if (!$ db ->isDbDumpExists ()) {
@@ -36,16 +51,15 @@ public static function setUpBeforeClass()
36
51
37
52
parent ::setUpBeforeClass ();
38
53
}
54
+ // @codingStandardsIgnoreEnd
39
55
40
56
protected function setUp ()
41
57
{
42
58
parent ::setUp ();
43
59
44
- $ this ->objectManager = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ();
45
- $ this ->fileSystem = $ this ->objectManager ->get (\Magento \Framework \Filesystem::class);
46
- $ this ->model = $ this ->objectManager ->create (
47
- \Magento \AdvancedPricingImportExport \Model \Export \AdvancedPricing::class
48
- );
60
+ $ this ->objectManager = Bootstrap::getObjectManager ();
61
+ $ this ->fileSystem = $ this ->objectManager ->get (Filesystem::class);
62
+ $ this ->model = $ this ->objectManager ->create (ExportAdvancedPricing::class);
49
63
}
50
64
51
65
/**
@@ -56,16 +70,15 @@ protected function setUp()
56
70
*/
57
71
public function testExport ()
58
72
{
59
- $ productRepository = $ this ->objectManager ->create (
60
- \Magento \Catalog \Api \ProductRepositoryInterface::class
61
- );
73
+ $ productRepository = $ this ->objectManager ->create (ProductRepositoryInterface::class);
62
74
$ index = 0 ;
63
75
$ ids = [];
64
76
$ origPricingData = [];
65
77
$ skus = ['simple ' ];
66
78
while (isset ($ skus [$ index ])) {
67
- $ ids [$ index ] = $ productRepository ->get ($ skus [$ index ])->getId ();
68
- $ origPricingData [$ index ] = $ this ->objectManager ->create (\Magento \Catalog \Model \Product::class)
79
+ $ ids [$ index ] = $ productRepository ->get ($ skus [$ index ])
80
+ ->getId ();
81
+ $ origPricingData [$ index ] = $ this ->objectManager ->create (Product::class)
69
82
->load ($ ids [$ index ])
70
83
->getTierPrices ();
71
84
$ index ++;
@@ -80,7 +93,7 @@ public function testExport()
80
93
81
94
while ($ index > 0 ) {
82
95
$ index --;
83
- $ newPricingData = $ this ->objectManager ->create (\ Magento \ Catalog \ Model \ Product::class)
96
+ $ newPricingData = $ this ->objectManager ->create (Product::class)
84
97
->load ($ ids [$ index ])
85
98
->getTierPrices ();
86
99
$ this ->assertEquals (count ($ origPricingData [$ index ]), count ($ newPricingData ));
@@ -97,7 +110,7 @@ public function testExport()
97
110
private function assertDiscountTypes ($ exportContent )
98
111
{
99
112
$ this ->assertContains (
100
- '2.0000,8.0000 ,Fixed ' ,
113
+ '2.0000,8.000000 ,Fixed ' ,
101
114
$ exportContent
102
115
);
103
116
$ this ->assertContains (
@@ -115,16 +128,15 @@ private function assertDiscountTypes($exportContent)
115
128
*/
116
129
public function testExportMultipleWebsites ()
117
130
{
118
- $ productRepository = $ this ->objectManager ->create (
119
- \Magento \Catalog \Api \ProductRepositoryInterface::class
120
- );
131
+ $ productRepository = $ this ->objectManager ->create (ProductRepositoryInterface::class);
121
132
$ index = 0 ;
122
133
$ ids = [];
123
134
$ origPricingData = [];
124
135
$ skus = ['AdvancedPricingSimple 1 ' , 'AdvancedPricingSimple 2 ' ];
125
136
while (isset ($ skus [$ index ])) {
126
- $ ids [$ index ] = $ productRepository ->get ($ skus [$ index ])->getId ();
127
- $ origPricingData [$ index ] = $ this ->objectManager ->create (\Magento \Catalog \Model \Product::class)
137
+ $ ids [$ index ] = $ productRepository ->get ($ skus [$ index ])
138
+ ->getId ();
139
+ $ origPricingData [$ index ] = $ this ->objectManager ->create (Product::class)
128
140
->load ($ ids [$ index ])
129
141
->getTierPrices ();
130
142
$ index ++;
@@ -141,7 +153,7 @@ public function testExportMultipleWebsites()
141
153
142
154
while ($ index > 0 ) {
143
155
$ index --;
144
- $ newPricingData = $ this ->objectManager ->create (\ Magento \ Catalog \ Model \ Product::class)
156
+ $ newPricingData = $ this ->objectManager ->create (Product::class)
145
157
->load ($ ids [$ index ])
146
158
->getTierPrices ();
147
159
$ this ->assertEquals (count ($ origPricingData [$ index ]), count ($ newPricingData ));
@@ -156,10 +168,11 @@ public function testExportMultipleWebsites()
156
168
private function exportData ($ csvFile )
157
169
{
158
170
$ this ->model ->setWriter (
159
- \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()->create (
160
- \Magento \ImportExport \Model \Export \Adapter \Csv::class,
161
- ['fileSystem ' => $ this ->fileSystem , 'destination ' => $ csvFile ]
162
- )
171
+ Bootstrap::getObjectManager ()
172
+ ->create (
173
+ ExportAdapterCsv::class,
174
+ ['fileSystem ' => $ this ->fileSystem , 'destination ' => $ csvFile ]
175
+ )
163
176
);
164
177
$ exportContent = $ this ->model ->export ();
165
178
$ this ->assertNotEmpty ($ exportContent );
@@ -172,21 +185,19 @@ private function exportData($csvFile)
172
185
*/
173
186
private function importData ($ csvFile )
174
187
{
175
- /** @var \Magento\AdvancedPricingImportExport\Model\Import\AdvancedPricing $importModel */
176
- $ importModel = $ this ->objectManager ->create (
177
- \Magento \AdvancedPricingImportExport \Model \Import \AdvancedPricing::class
178
- );
188
+ /** @var ImportAdvancedPricing $importModel */
189
+ $ importModel = $ this ->objectManager ->create (ImportAdvancedPricing::class);
179
190
$ directory = $ this ->fileSystem ->getDirectoryWrite (DirectoryList::VAR_DIR );
180
191
$ source = $ this ->objectManager ->create (
181
- \ Magento \ ImportExport \ Model \ Import \ Source \Csv ::class,
192
+ ImportSourceCsv ::class,
182
193
[
183
194
'file ' => $ csvFile ,
184
195
'directory ' => $ directory
185
196
]
186
197
);
187
198
$ errors = $ importModel ->setParameters (
188
199
[
189
- 'behavior ' => \ Magento \ ImportExport \ Model \ Import::BEHAVIOR_APPEND ,
200
+ 'behavior ' => Import::BEHAVIOR_APPEND ,
190
201
'entity ' => 'advanced_pricing '
191
202
]
192
203
)->setSource (
0 commit comments