Passed
Push — master ( 417598...532336 )
by Aimeos
03:26
created

StandardTest::get()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2015-2021
6
 */
7
8
9
namespace Aimeos\Controller\Common\Product\Import\Csv\Processor\Catalog;
10
11
12
class StandardTest extends \PHPUnit\Framework\TestCase
13
{
14
	private $context;
15
	private $endpoint;
16
	private $product;
17
18
19
	protected function setUp() : void
20
	{
21
		\Aimeos\MShop::cache( true );
22
23
		$this->context = \TestHelperCntl::context();
24
		$this->product = \Aimeos\MShop\Product\Manager\Factory::create( $this->context )->create();
25
		$this->endpoint = new \Aimeos\Controller\Common\Product\Import\Csv\Processor\Done( $this->context, [] );
26
	}
27
28
29
	protected function tearDown() : void
30
	{
31
		\Aimeos\MShop::cache( false );
32
	}
33
34
35
	public function testProcess()
36
	{
37
		$mapping = array(
38
			0 => 'product.lists.type',
39
			1 => 'catalog.code',
40
			2 => 'product.lists.type',
41
			3 => 'catalog.code',
42
		);
43
44
		$data = array(
45
			0 => 'default',
46
			1 => 'cafe',
47
			2 => 'promotion',
48
			3 => 'cafe',
49
		);
50
51
		$object = new \Aimeos\Controller\Common\Product\Import\Csv\Processor\Catalog\Standard( $this->context, $mapping, $this->endpoint );
52
		$object->process( $this->product, $data );
53
54
		$pos = 0;
55
		$listItems = $this->product->getListItems();
56
		$expected = array(
57
			array( 'default', 'job_csv_prod' ),
58
			array( 'promotion', 'job_csv_prod' ),
59
		);
60
61
		$this->assertEquals( 2, count( $listItems ) );
62
63
		foreach( $listItems as $listItem )
64
		{
65
			$this->assertEquals( 1, $listItem->getStatus() );
66
			$this->assertEquals( 'catalog', $listItem->getDomain() );
67
			$this->assertEquals( $expected[$pos][0], $listItem->getType() );
68
			$this->assertGreaterThan( 0, $listItem->getRefId() );
69
			$pos++;
70
		}
71
	}
72
73
74
	public function testProcessMultiple()
75
	{
76
		$mapping = array(
77
			0 => 'product.lists.type',
78
			1 => 'catalog.code',
79
			2 => 'product.lists.type',
80
			3 => 'catalog.code',
81
		);
82
83
		$data = array(
84
			0 => 'default',
85
			1 => "cafe\ntea",
86
			2 => 'promotion',
87
			3 => "cafe\ntea",
88
		);
89
90
		$object = new \Aimeos\Controller\Common\Product\Import\Csv\Processor\Catalog\Standard( $this->context, $mapping, $this->endpoint );
91
		$object->process( $this->product, $data );
92
93
94
		$pos = 0;
95
		$listItems = $this->product->getListItems();
96
		$types = ['default', 'default', 'promotion', 'promotion'];
97
98
		$this->assertEquals( 4, count( $listItems ) );
99
100
		foreach( $listItems as $listItem )
101
		{
102
			$this->assertEquals( 1, $listItem->getStatus() );
103
			$this->assertEquals( 'catalog', $listItem->getDomain() );
104
			$this->assertEquals( $types[$pos], $listItem->getType() );
105
			$this->assertGreaterThan( 0, $listItem->getRefId() );
106
			$pos++;
107
		}
108
	}
109
110
111
	public function testProcessUpdate()
112
	{
113
		$mapping = array(
114
			0 => 'product.lists.type',
115
			1 => 'catalog.code',
116
		);
117
118
		$data = array(
119
			0 => 'default',
120
			1 => 'cafe',
121
		);
122
123
		$dataUpdate = array(
124
			0 => 'promotion',
125
			1 => 'cafe',
126
		);
127
128
		$object = new \Aimeos\Controller\Common\Product\Import\Csv\Processor\Catalog\Standard( $this->context, $mapping, $this->endpoint );
129
		$object->process( $this->product, $data );
130
		$object->process( $this->product, $dataUpdate );
131
132
		$listItems = $this->product->getListItems();
133
		$listItem = $listItems->first();
134
135
		$this->assertEquals( 1, count( $listItems ) );
136
		$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Item\\Lists\\Iface', $listItem );
137
		$this->assertGreaterThan( 0, $listItem->getRefId() );
138
	}
139
140
141
	public function testProcessDelete()
142
	{
143
		$mapping = array(
144
			0 => 'product.lists.type',
145
			1 => 'catalog.code',
146
		);
147
148
		$data = array(
149
			0 => 'default',
150
			1 => 'cafe',
151
		);
152
153
		$object = new \Aimeos\Controller\Common\Product\Import\Csv\Processor\Catalog\Standard( $this->context, $mapping, $this->endpoint );
154
		$object->process( $this->product, $data );
155
156
		$object = new \Aimeos\Controller\Common\Product\Import\Csv\Processor\Catalog\Standard( $this->context, [], $this->endpoint );
157
		$object->process( $this->product, [] );
158
159
		$listItems = $this->product->getListItems();
160
161
		$this->assertEquals( 0, count( $listItems ) );
162
	}
163
164
165
	public function testProcessEmpty()
166
	{
167
		$mapping = array(
168
			0 => 'product.lists.type',
169
			1 => 'catalog.code',
170
			2 => 'product.lists.type',
171
			3 => 'catalog.code',
172
		);
173
174
		$data = array(
175
			0 => '',
176
			1 => '',
177
			2 => 'default',
178
			3 => 'cafe',
179
		);
180
181
		$object = new \Aimeos\Controller\Common\Product\Import\Csv\Processor\Catalog\Standard( $this->context, $mapping, $this->endpoint );
182
		$object->process( $this->product, $data );
183
184
		$listItems = $this->product->getListItems();
185
186
		$this->assertEquals( 1, count( $listItems ) );
187
	}
188
189
190
	public function testProcessListtypes()
191
	{
192
		$mapping = array(
193
			0 => 'product.lists.type',
194
			1 => 'catalog.code',
195
			2 => 'product.lists.type',
196
			3 => 'catalog.code',
197
		);
198
199
		$data = array(
200
			0 => 'promotion',
201
			1 => 'cafe',
202
			2 => 'default',
203
			3 => 'cafe',
204
		);
205
206
		$this->context->config()->set( 'controller/common/product/import/csv/processor/catalog/listtypes', array( 'default' ) );
207
208
		$object = new \Aimeos\Controller\Common\Product\Import\Csv\Processor\Catalog\Standard( $this->context, $mapping, $this->endpoint );
209
210
		$this->expectException( '\Aimeos\Controller\Common\Exception' );
211
		$object->process( $this->product, $data );
212
	}
213
}
214