Completed
Pull Request — master (#25)
by
unknown
02:59
created

StandardTest   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 249
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 140
c 1
b 1
f 0
dl 0
loc 249
rs 10
wmc 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A testProcessUpdate() 0 32 1
A testProcessEmpty() 0 25 1
A testProcessListtypes() 0 28 1
A setUp() 0 6 1
A tearDown() 0 3 1
A testProcess() 0 43 1
A create() 0 8 1
A testProcessDelete() 0 24 1
A testProcessMultiple() 0 46 2
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2015-2020
6
 */
7
8
9
namespace Aimeos\Controller\Common\Supplier\Import\Csv\Processor\Text;
10
11
12
class StandardTest extends \PHPUnit\Framework\TestCase
13
{
14
	private $context;
15
	private $endpoint;
16
17
18
	protected function setUp() : void
19
	{
20
		\Aimeos\MShop::cache( true );
21
22
		$this->context = \TestHelperCntl::getContext();
23
		$this->endpoint = new \Aimeos\Controller\Common\Supplier\Import\Csv\Processor\Done( $this->context, [] );
24
	}
25
26
27
	protected function tearDown() : void
28
	{
29
		\Aimeos\MShop::cache( false );
30
	}
31
32
33
	public function testProcess()
34
	{
35
		$mapping = array(
36
			0 => 'text.type',
37
			1 => 'text.content',
38
			2 => 'text.label',
39
			3 => 'text.languageid',
40
			4 => 'text.status',
41
		);
42
43
		$data = array(
44
			0 => 'name',
45
			1 => 'Job CSV test',
46
			2 => 'test text',
47
			3 => 'de',
48
			4 => 1,
49
		);
50
51
		$supplier = $this->create( 'job_csv_test' );
52
53
		$object = new \Aimeos\Controller\Common\Supplier\Import\Csv\Processor\Text\Standard( $this->context, $mapping, $this->endpoint );
54
		$object->process( $supplier, $data );
55
56
57
		$listItems = $supplier->getListItems();
58
		$listItem = $listItems->first();
59
60
		$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Item\\Lists\\Iface', $listItem );
61
		$this->assertEquals( 1, count( $listItems ) );
62
63
		$this->assertEquals( 1, $listItem->getStatus() );
64
		$this->assertEquals( 0, $listItem->getPosition() );
65
		$this->assertEquals( 'text', $listItem->getDomain() );
66
		$this->assertEquals( 'default', $listItem->getType() );
67
68
		$refItem = $listItem->getRefItem();
69
70
		$this->assertEquals( 1, $refItem->getStatus() );
71
		$this->assertEquals( 'name', $refItem->getType() );
72
		$this->assertEquals( 'test text', $refItem->getLabel() );
73
		$this->assertEquals( 'Job CSV test', $refItem->getContent() );
74
		$this->assertEquals( 'de', $refItem->getLanguageId() );
75
		$this->assertEquals( 1, $refItem->getStatus() );
76
	}
77
78
79
	public function testProcessMultiple()
80
	{
81
		$mapping = array(
82
			0 => 'text.type',
83
			1 => 'text.content',
84
			2 => 'text.type',
85
			3 => 'text.content',
86
			4 => 'text.type',
87
			5 => 'text.content',
88
			6 => 'text.type',
89
			7 => 'text.content',
90
		);
91
92
		$data = array(
93
			0 => 'name',
94
			1 => 'Job CSV test',
95
			2 => 'short',
96
			3 => 'Short: Job CSV test',
97
			4 => 'long',
98
			5 => 'Long: Job CSV test',
99
			6 => 'long',
100
			7 => 'Long: Job CSV test 2',
101
		);
102
103
		$supplier = $this->create( 'job_csv_test' );
104
105
		$object = new \Aimeos\Controller\Common\Supplier\Import\Csv\Processor\Text\Standard( $this->context, $mapping, $this->endpoint );
106
		$object->process( $supplier, $data );
107
108
109
		$pos = 0;
110
		$listItems = $supplier->getListItems();
111
		$expected = array(
112
			0 => array( 'name', 'Job CSV test' ),
113
			1 => array( 'short', 'Short: Job CSV test' ),
114
			2 => array( 'long', 'Long: Job CSV test' ),
115
			3 => array( 'long', 'Long: Job CSV test 2' ),
116
		);
117
118
		$this->assertEquals( 4, count( $listItems ) );
119
120
		foreach( $listItems as $listItem )
121
		{
122
			$this->assertEquals( $expected[$pos][0], $listItem->getRefItem()->getType() );
123
			$this->assertEquals( $expected[$pos][1], $listItem->getRefItem()->getContent() );
124
			$pos++;
125
		}
126
	}
127
128
129
	public function testProcessUpdate()
130
	{
131
		$mapping = array(
132
			0 => 'text.type',
133
			1 => 'text.content',
134
		);
135
136
		$data = array(
137
			0 => 'name',
138
			1 => 'Job CSV test',
139
		);
140
141
		$dataUpdate = array(
142
			0 => 'short',
143
			1 => 'Short: Job CSV test',
144
		);
145
146
		$supplier = $this->create( 'job_csv_test' );
147
148
		$object = new \Aimeos\Controller\Common\Supplier\Import\Csv\Processor\Text\Standard( $this->context, $mapping, $this->endpoint );
149
		$object->process( $supplier, $data );
150
		$object->process( $supplier, $dataUpdate );
151
152
153
		$listItems = $supplier->getListItems();
154
		$listItem = $listItems->first();
155
156
		$this->assertEquals( 1, count( $listItems ) );
157
		$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Item\\Lists\\Iface', $listItem );
158
159
		$this->assertEquals( 'short', $listItem->getRefItem()->getType() );
160
		$this->assertEquals( 'Short: Job CSV test', $listItem->getRefItem()->getContent() );
161
	}
162
163
164
	public function testProcessDelete()
165
	{
166
		$mapping = array(
167
			0 => 'text.type',
168
			1 => 'text.content',
169
		);
170
171
		$data = array(
172
			0 => 'name',
173
			1 => 'Job CSV test',
174
		);
175
176
		$supplier = $this->create( 'job_csv_test' );
177
178
		$object = new \Aimeos\Controller\Common\Supplier\Import\Csv\Processor\Text\Standard( $this->context, $mapping, $this->endpoint );
179
		$object->process( $supplier, $data );
180
181
		$object = new \Aimeos\Controller\Common\Supplier\Import\Csv\Processor\Text\Standard( $this->context, [], $this->endpoint );
182
		$object->process( $supplier, [] );
183
184
185
		$listItems = $supplier->getListItems();
186
187
		$this->assertEquals( 0, count( $listItems ) );
188
	}
189
190
191
	public function testProcessEmpty()
192
	{
193
		$mapping = array(
194
			0 => 'text.type',
195
			1 => 'text.content',
196
			2 => 'text.type',
197
			3 => 'text.content',
198
		);
199
200
		$data = array(
201
			0 => 'name',
202
			1 => 'Job CSV test',
203
			2 => '',
204
			3 => '',
205
		);
206
207
		$supplier = $this->create( 'job_csv_test' );
208
209
		$object = new \Aimeos\Controller\Common\Supplier\Import\Csv\Processor\Text\Standard( $this->context, $mapping, $this->endpoint );
210
		$object->process( $supplier, $data );
211
212
213
		$listItems = $supplier->getListItems();
214
215
		$this->assertEquals( 1, count( $listItems ) );
216
	}
217
218
219
	public function testProcessListtypes()
220
	{
221
		$mapping = array(
222
			0 => 'text.type',
223
			1 => 'text.content',
224
			2 => 'supplier.lists.type',
225
			3 => 'text.type',
226
			4 => 'text.content',
227
			5 => 'supplier.lists.type',
228
		);
229
230
		$data = array(
231
			0 => 'name',
232
			1 => 'test name',
233
			2 => 'test',
234
			3 => 'short',
235
			4 => 'test short',
236
			5 => 'default',
237
		);
238
239
		$this->context->getConfig()->set( 'controller/common/supplier/import/csv/processor/text/listtypes', array( 'default' ) );
240
241
		$supplier = $this->create( 'job_csv_test' );
242
243
		$object = new \Aimeos\Controller\Common\Supplier\Import\Csv\Processor\Text\Standard( $this->context, $mapping, $this->endpoint );
244
245
		$this->expectException( '\Aimeos\Controller\Common\Exception' );
246
		$object->process( $supplier, $data );
247
	}
248
249
250
	/**
251
	 * @param string $code
252
	 */
253
	protected function create( $code )
254
	{
255
		$manager = \Aimeos\MShop\Supplier\Manager\Factory::create( $this->context );
256
257
		$item = $manager->createItem();
258
		$item->setCode( $code );
259
260
		return $item;
261
	}
262
}
263