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), 2018
6
 */
7
8
9
namespace Aimeos\Controller\Common\Catalog\Import\Csv\Processor\Media;
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 => 'media.languageid',
38
			1 => 'media.label',
39
			2 => 'media.mimetype',
40
			3 => 'media.preview',
41
			4 => 'media.url',
42
			5 => 'media.status',
43
		);
44
45
		$data = array(
46
			0 => 'de',
47
			1 => 'test image',
48
			2 => 'image/jpeg',
49
			3 => 'path/to/preview',
50
			4 => 'path/to/file',
51
			5 => 1,
52
		);
53
54
		$catalog = $this->create( 'job_csv_test' );
55
56
		$object = new \Aimeos\Controller\Common\Catalog\Import\Csv\Processor\Media\Standard( $this->context, $mapping, $this->endpoint );
57
		$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...
58
59
60
		$listItems = $catalog->getListItems();
61
		$listItem = reset( $listItems );
62
63
		$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Item\\Lists\\Iface', $listItem );
64
		$this->assertEquals( 1, count( $listItems ) );
65
66
		$this->assertEquals( 1, $listItem->getStatus() );
67
		$this->assertEquals( 0, $listItem->getPosition() );
68
		$this->assertEquals( 'media', $listItem->getDomain() );
69
		$this->assertEquals( 'default', $listItem->getType() );
70
71
		$refItem = $listItem->getRefItem();
72
73
		$this->assertEquals( 1, $refItem->getStatus() );
74
		$this->assertEquals( 'default', $refItem->getType() );
75
		$this->assertEquals( 'test image', $refItem->getLabel() );
76
		$this->assertEquals( 'image/jpeg', $refItem->getMimetype() );
77
		$this->assertEquals( 'path/to/preview', $refItem->getPreview() );
78
		$this->assertEquals( 'path/to/file', $refItem->getUrl() );
79
		$this->assertEquals( 'de', $refItem->getLanguageId() );
80
	}
81
82
83
	public function testProcessMultiple()
84
	{
85
		$mapping = array(
86
			0 => 'media.url',
87
		);
88
89
		$data = array(
90
			0 => "path/to/0\npath/to/1\npath/to/2\npath/to/3",
91
		);
92
93
		$catalog = $this->create( 'job_csv_test' );
94
95
		$object = new \Aimeos\Controller\Common\Catalog\Import\Csv\Processor\Media\Standard( $this->context, $mapping, $this->endpoint );
96
		$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...
97
98
99
		$pos = 0;
100
		$listItems = $catalog->getListItems();
101
		$expected = array( 'path/to/0', 'path/to/1', 'path/to/2', 'path/to/3' );
102
103
		$this->assertEquals( 4, count( $listItems ) );
104
105
		foreach( $listItems as $listItem )
106
		{
107
			$this->assertEquals( $expected[$pos], $listItem->getRefItem()->getUrl() );
108
			$pos++;
109
		}
110
	}
111
112
113
	public function testProcessMultipleFields()
114
	{
115
		$mapping = array(
116
			0 => 'media.url',
117
			1 => 'media.url',
118
			2 => 'media.url',
119
			3 => 'media.url',
120
		);
121
122
		$data = array(
123
			0 => 'path/to/0',
124
			1 => 'path/to/1',
125
			2 => 'path/to/2',
126
			3 => 'path/to/3',
127
		);
128
129
		$catalog = $this->create( 'job_csv_test' );
130
131
		$object = new \Aimeos\Controller\Common\Catalog\Import\Csv\Processor\Media\Standard( $this->context, $mapping, $this->endpoint );
132
		$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...
133
134
135
		$pos = 0;
136
		$listItems = $catalog->getListItems();
137
138
		$this->assertEquals( 4, count( $listItems ) );
139
140
		foreach( $listItems as $listItem )
141
		{
142
			$this->assertEquals( $data[$pos], $listItem->getRefItem()->getUrl() );
143
			$pos++;
144
		}
145
	}
146
147
148
	public function testProcessUpdate()
149
	{
150
		$mapping = array(
151
			0 => 'media.url',
152
			1 => 'media.languageid',
153
		);
154
155
		$data = array(
156
			0 => 'path/to/file',
157
			1 => 'de',
158
		);
159
160
		$dataUpdate = array(
161
			0 => 'path/to/new',
162
			1 => '',
163
		);
164
165
		$catalog = $this->create( 'job_csv_test' );
166
167
		$object = new \Aimeos\Controller\Common\Catalog\Import\Csv\Processor\Media\Standard( $this->context, $mapping, $this->endpoint );
168
		$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...
169
		$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...
170
171
172
		$listItems = $catalog->getListItems();
173
		$listItem = reset( $listItems );
174
175
		$this->assertEquals( 1, count( $listItems ) );
176
		$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Item\\Lists\\Iface', $listItem );
177
178
		$this->assertEquals( 'path/to/new', $listItem->getRefItem()->getUrl() );
179
		$this->assertEquals( null, $listItem->getRefItem()->getLanguageId() );
180
	}
181
182
183
	public function testProcessDelete()
184
	{
185
		$mapping = array(
186
			0 => 'media.url',
187
		);
188
189
		$data = array(
190
			0 => '/path/to/file',
191
		);
192
193
		$catalog = $this->create( 'job_csv_test' );
194
195
		$object = new \Aimeos\Controller\Common\Catalog\Import\Csv\Processor\Media\Standard( $this->context, $mapping, $this->endpoint );
196
		$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...
197
198
		$object = new \Aimeos\Controller\Common\Catalog\Import\Csv\Processor\Media\Standard( $this->context, [], $this->endpoint );
199
		$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...
200
201
202
		$listItems = $catalog->getListItems();
203
204
		$this->assertEquals( 0, count( $listItems ) );
205
	}
206
207
208
	public function testProcessEmpty()
209
	{
210
		$mapping = array(
211
			0 => 'media.url',
212
			1 => 'media.url',
213
		);
214
215
		$data = array(
216
			0 => 'path/to/file',
217
			1 => '',
218
		);
219
220
		$catalog = $this->create( 'job_csv_test' );
221
222
		$object = new \Aimeos\Controller\Common\Catalog\Import\Csv\Processor\Media\Standard( $this->context, $mapping, $this->endpoint );
223
		$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...
224
225
226
		$listItems = $catalog->getListItems();
227
228
		$this->assertEquals( 1, count( $listItems ) );
229
	}
230
231
232
	public function testProcessListtypes()
233
	{
234
		$mapping = array(
235
			0 => 'media.url',
236
			1 => 'catalog.lists.type',
237
			2 => 'media.url',
238
			3 => 'catalog.lists.type',
239
		);
240
241
		$data = array(
242
			0 => 'path/to/file',
243
			1 => 'download',
244
			2 => 'path/to/file2',
245
			3 => 'default',
246
		);
247
248
		$this->context->getConfig()->set( 'controller/common/catalog/import/csv/processor/media/listtypes', array( 'default' ) );
249
250
		$catalog = $this->create( 'job_csv_test' );
251
252
		$object = new \Aimeos\Controller\Common\Catalog\Import\Csv\Processor\Media\Standard( $this->context, $mapping, $this->endpoint );
253
		$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...
254
255
256
		$listItems = $catalog->getListItems();
257
		$listItem = reset( $listItems );
258
259
		$this->assertEquals( 1, count( $listItems ) );
260
		$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Item\\Lists\\Iface', $listItem );
261
262
		$this->assertEquals( 'default', $listItem->getType() );
263
		$this->assertEquals( 'path/to/file2', $listItem->getRefItem()->getUrl() );
264
	}
265
266
267
	/**
268
	 * @param string $code
269
	 */
270
	protected function create( $code )
271
	{
272
		$manager = \Aimeos\MShop\Catalog\Manager\Factory::createManager( $this->context );
273
274
		$item = $manager->createItem();
275
		$item->setCode( $code );
276
277
		return $item;
278
	}
279
}