Completed
Push — master ( 0ed5fa...41d654 )
by Aimeos
02:01
created

StandardTest::delete()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2015-2017
6
 */
7
8
9
namespace Aimeos\Controller\Common\Catalog\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()
19
	{
20
		\Aimeos\MShop\Factory::setCache( true );
21
22
		$this->context = \TestHelperCntl::getContext();
23
		$this->endpoint = new \Aimeos\Controller\Common\Catalog\Import\Csv\Processor\Done( $this->context, [] );
24
	}
25
26
27
	protected function tearDown()
28
	{
29
		\Aimeos\MShop\Factory::setCache( false );
30
		\Aimeos\MShop\Factory::clear();
31
	}
32
33
34
	public function testProcess()
35
	{
36
		$mapping = array(
37
			0 => 'text.type',
38
			1 => 'text.content',
39
			2 => 'text.label',
40
			3 => 'text.languageid',
41
			4 => 'text.status',
42
		);
43
44
		$data = array(
45
			0 => 'name',
46
			1 => 'Job CSV test',
47
			2 => 'test text',
48
			3 => 'de',
49
			4 => 1,
50
		);
51
52
		$catalog = $this->create( 'job_csv_test' );
53
54
		$object = new \Aimeos\Controller\Common\Catalog\Import\Csv\Processor\Text\Standard( $this->context, $mapping, $this->endpoint );
55
		$object->process( $catalog, $data );
0 ignored issues
show
Documentation introduced by
$catalog is of type object<Aimeos\MShop\Attribute\Item\Iface>, but the function expects a object<Aimeos\MShop\Catalog\Item\Iface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
56
57
58
		$listItems = $catalog->getListItems();
59
		$listItem = reset( $listItems );
60
61
		$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Item\\Lists\\Iface', $listItem );
62
		$this->assertEquals( 1, count( $listItems ) );
63
64
		$this->assertEquals( 1, $listItem->getStatus() );
65
		$this->assertEquals( 0, $listItem->getPosition() );
66
		$this->assertEquals( 'text', $listItem->getDomain() );
67
		$this->assertEquals( 'default', $listItem->getType() );
68
69
		$refItem = $listItem->getRefItem();
70
71
		$this->assertEquals( 1, $refItem->getStatus() );
72
		$this->assertEquals( 'name', $refItem->getType() );
73
		$this->assertEquals( 'test text', $refItem->getLabel() );
74
		$this->assertEquals( 'Job CSV test', $refItem->getContent() );
75
		$this->assertEquals( 'de', $refItem->getLanguageId() );
76
		$this->assertEquals( 1, $refItem->getStatus() );
77
	}
78
79
80
	public function testProcessMultiple()
81
	{
82
		$mapping = array(
83
			0 => 'text.type',
84
			1 => 'text.content',
85
			2 => 'text.type',
86
			3 => 'text.content',
87
			4 => 'text.type',
88
			5 => 'text.content',
89
			6 => 'text.type',
90
			7 => 'text.content',
91
		);
92
93
		$data = array(
94
			0 => 'name',
95
			1 => 'Job CSV test',
96
			2 => 'short',
97
			3 => 'Short: Job CSV test',
98
			4 => 'long',
99
			5 => 'Long: Job CSV test',
100
			6 => 'long',
101
			7 => 'Long: Job CSV test 2',
102
		);
103
104
		$catalog = $this->create( 'job_csv_test' );
105
106
		$object = new \Aimeos\Controller\Common\Catalog\Import\Csv\Processor\Text\Standard( $this->context, $mapping, $this->endpoint );
107
		$object->process( $catalog, $data );
0 ignored issues
show
Documentation introduced by
$catalog is of type object<Aimeos\MShop\Attribute\Item\Iface>, but the function expects a object<Aimeos\MShop\Catalog\Item\Iface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
108
109
110
		$pos = 0;
111
		$listItems = $catalog->getListItems();
112
		$expected = array(
113
			0 => array( 'name', 'Job CSV test' ),
114
			1 => array( 'short', 'Short: Job CSV test' ),
115
			2 => array( 'long', 'Long: Job CSV test' ),
116
			3 => array( 'long', 'Long: Job CSV test 2' ),
117
		);
118
119
		$this->assertEquals( 4, count( $listItems ) );
120
121
		foreach( $listItems as $listItem )
122
		{
123
			$this->assertEquals( $expected[$pos][0], $listItem->getRefItem()->getType() );
124
			$this->assertEquals( $expected[$pos][1], $listItem->getRefItem()->getContent() );
125
			$pos++;
126
		}
127
	}
128
129
130
	public function testProcessUpdate()
131
	{
132
		$mapping = array(
133
			0 => 'text.type',
134
			1 => 'text.content',
135
		);
136
137
		$data = array(
138
			0 => 'name',
139
			1 => 'Job CSV test',
140
		);
141
142
		$dataUpdate = array(
143
			0 => 'short',
144
			1 => 'Short: Job CSV test',
145
		);
146
147
		$catalog = $this->create( 'job_csv_test' );
148
149
		$object = new \Aimeos\Controller\Common\Catalog\Import\Csv\Processor\Text\Standard( $this->context, $mapping, $this->endpoint );
150
		$object->process( $catalog, $data );
0 ignored issues
show
Documentation introduced by
$catalog is of type object<Aimeos\MShop\Attribute\Item\Iface>, but the function expects a object<Aimeos\MShop\Catalog\Item\Iface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
151
		$object->process( $catalog, $dataUpdate );
0 ignored issues
show
Documentation introduced by
$catalog is of type object<Aimeos\MShop\Attribute\Item\Iface>, but the function expects a object<Aimeos\MShop\Catalog\Item\Iface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
152
153
154
		$listItems = $catalog->getListItems();
155
		$listItem = reset( $listItems );
156
157
		$this->assertEquals( 1, count( $listItems ) );
158
		$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Item\\Lists\\Iface', $listItem );
159
160
		$this->assertEquals( 'short', $listItem->getRefItem()->getType() );
161
		$this->assertEquals( 'Short: Job CSV test', $listItem->getRefItem()->getContent() );
162
	}
163
164
165
	public function testProcessDelete()
166
	{
167
		$mapping = array(
168
			0 => 'text.type',
169
			1 => 'text.content',
170
		);
171
172
		$data = array(
173
			0 => 'name',
174
			1 => 'Job CSV test',
175
		);
176
177
		$catalog = $this->create( 'job_csv_test' );
178
179
		$object = new \Aimeos\Controller\Common\Catalog\Import\Csv\Processor\Text\Standard( $this->context, $mapping, $this->endpoint );
180
		$object->process( $catalog, $data );
0 ignored issues
show
Documentation introduced by
$catalog is of type object<Aimeos\MShop\Attribute\Item\Iface>, but the function expects a object<Aimeos\MShop\Catalog\Item\Iface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
181
182
		$object = new \Aimeos\Controller\Common\Catalog\Import\Csv\Processor\Text\Standard( $this->context, [], $this->endpoint );
183
		$object->process( $catalog, [] );
0 ignored issues
show
Documentation introduced by
$catalog is of type object<Aimeos\MShop\Attribute\Item\Iface>, but the function expects a object<Aimeos\MShop\Catalog\Item\Iface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
184
185
186
		$listItems = $catalog->getListItems();
187
188
		$this->assertEquals( 0, count( $listItems ) );
189
	}
190
191
192
	public function testProcessEmpty()
193
	{
194
		$mapping = array(
195
			0 => 'text.type',
196
			1 => 'text.content',
197
			2 => 'text.type',
198
			3 => 'text.content',
199
		);
200
201
		$data = array(
202
			0 => 'name',
203
			1 => 'Job CSV test',
204
			2 => '',
205
			3 => '',
206
		);
207
208
		$catalog = $this->create( 'job_csv_test' );
209
210
		$object = new \Aimeos\Controller\Common\Catalog\Import\Csv\Processor\Text\Standard( $this->context, $mapping, $this->endpoint );
211
		$object->process( $catalog, $data );
0 ignored issues
show
Documentation introduced by
$catalog is of type object<Aimeos\MShop\Attribute\Item\Iface>, but the function expects a object<Aimeos\MShop\Catalog\Item\Iface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
212
213
214
		$listItems = $catalog->getListItems();
215
216
		$this->assertEquals( 1, count( $listItems ) );
217
	}
218
219
220
	public function testProcessListtypes()
221
	{
222
		$mapping = array(
223
			0 => 'text.type',
224
			1 => 'text.content',
225
			2 => 'catalog.lists.type',
226
			3 => 'text.type',
227
			4 => 'text.content',
228
			5 => 'catalog.lists.type',
229
		);
230
231
		$data = array(
232
			0 => 'name',
233
			1 => 'test name',
234
			2 => 'test',
235
			3 => 'short',
236
			4 => 'test short',
237
			5 => 'default',
238
		);
239
240
		$this->context->getConfig()->set( 'controller/common/catalog/import/csv/processor/text/listtypes', array( 'default' ) );
241
242
		$catalog = $this->create( 'job_csv_test' );
243
244
		$object = new \Aimeos\Controller\Common\Catalog\Import\Csv\Processor\Text\Standard( $this->context, $mapping, $this->endpoint );
245
		$object->process( $catalog, $data );
0 ignored issues
show
Documentation introduced by
$catalog is of type object<Aimeos\MShop\Attribute\Item\Iface>, but the function expects a object<Aimeos\MShop\Catalog\Item\Iface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
246
247
248
		$listItems = $catalog->getListItems();
249
		$listItem = reset( $listItems );
250
251
		$this->assertEquals( 1, count( $listItems ) );
252
		$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Item\\Lists\\Iface', $listItem );
253
254
		$this->assertEquals( 'default', $listItem->getType() );
255
		$this->assertEquals( 'short', $listItem->getRefItem()->getType() );
256
		$this->assertEquals( 'test short', $listItem->getRefItem()->getContent() );
257
	}
258
259
260
	/**
261
	 * @param string $code
262
	 */
263
	protected function create( $code )
264
	{
265
		$manager = \Aimeos\MShop\Catalog\Manager\Factory::createManager( $this->context );
266
267
		$item = $manager->createItem();
268
		$item->setCode( $code );
269
270
		return $item;
271
	}
272
}