|
5 | 5 | */
|
6 | 6 | namespace Magento\Catalog\Test\Unit\Model\ResourceModel\Product;
|
7 | 7 |
|
| 8 | +use Magento\Framework\DB\Sql\ColumnValueExpression; |
| 9 | + |
8 | 10 | /**
|
9 | 11 | * Unit test for product media gallery resource.
|
10 | 12 | */
|
@@ -280,200 +282,4 @@ public function testBindValueToEntityRecordExists()
|
280 | 282 | $entityId = 1;
|
281 | 283 | $this->resource->bindValueToEntity($valueId, $entityId);
|
282 | 284 | }
|
283 |
| - |
284 |
| - /** |
285 |
| - * @SuppressWarnings(PHPMD.ExcessiveMethodLength) |
286 |
| - */ |
287 |
| - public function testLoadGallery() |
288 |
| - { |
289 |
| - $productId = 5; |
290 |
| - $storeId = 1; |
291 |
| - $attributeId = 6; |
292 |
| - $getTableReturnValue = 'table'; |
293 |
| - $quoteInfoReturnValue = |
294 |
| - 'main.value_id = value.value_id AND value.store_id = ' . $storeId |
295 |
| - . ' AND value.entity_id = entity.entity_id'; |
296 |
| - $quoteDefaultInfoReturnValue = |
297 |
| - 'main.value_id = default_value.value_id AND default_value.store_id = 0' |
298 |
| - . ' AND default_value.entity_id = entity.entity_id'; |
299 |
| - |
300 |
| - $positionCheckSql = 'testchecksql'; |
301 |
| - $resultRow = [ |
302 |
| - [ |
303 |
| - 'value_id' => '1', |
304 |
| - 'file' => '/d/o/download_7.jpg', |
305 |
| - 'label' => null, |
306 |
| - 'position' => '1', |
307 |
| - 'disabled' => '0', |
308 |
| - 'label_default' => null, |
309 |
| - 'position_default' => '1', |
310 |
| - 'disabled_default' => '0', |
311 |
| - ], |
312 |
| - ]; |
313 |
| - |
314 |
| - $this->connection->expects($this->once())->method('getCheckSql')->with( |
315 |
| - 'value.position IS NULL', |
316 |
| - 'default_value.position', |
317 |
| - 'value.position' |
318 |
| - )->will($this->returnValue($positionCheckSql)); |
319 |
| - $this->connection->expects($this->once())->method('select')->will($this->returnValue($this->select)); |
320 |
| - $this->select->expects($this->at(0))->method('from')->with( |
321 |
| - [ |
322 |
| - 'main' => $getTableReturnValue, |
323 |
| - ], |
324 |
| - [ |
325 |
| - 'value_id', |
326 |
| - 'file' => 'value', |
327 |
| - 'media_type' |
328 |
| - ] |
329 |
| - )->willReturnSelf(); |
330 |
| - $this->select->expects($this->at(1))->method('joinInner')->with( |
331 |
| - ['entity' => $getTableReturnValue], |
332 |
| - 'main.value_id = entity.value_id', |
333 |
| - ['entity_id'] |
334 |
| - )->willReturnSelf(); |
335 |
| - $this->product->expects($this->at(0))->method('getData') |
336 |
| - ->with('entity_id')->willReturn($productId); |
337 |
| - $this->product->expects($this->at(1))->method('getStoreId')->will($this->returnValue($storeId)); |
338 |
| - $this->connection->expects($this->exactly(2))->method('quoteInto')->withConsecutive( |
339 |
| - ['value.store_id = ?'], |
340 |
| - ['default_value.store_id = ?'] |
341 |
| - )->willReturnOnConsecutiveCalls( |
342 |
| - 'value.store_id = ' . $storeId, |
343 |
| - 'default_value.store_id = ' . 0 |
344 |
| - ); |
345 |
| - $this->connection->expects($this->any())->method('getIfNullSql')->will( |
346 |
| - $this->returnValueMap([ |
347 |
| - [ |
348 |
| - '`value`.`label`', |
349 |
| - '`default_value`.`label`', |
350 |
| - 'IFNULL(`value`.`label`, `default_value`.`label`)' |
351 |
| - ], |
352 |
| - [ |
353 |
| - '`value`.`position`', |
354 |
| - '`default_value`.`position`', |
355 |
| - 'IFNULL(`value`.`position`, `default_value`.`position`)' |
356 |
| - ], |
357 |
| - [ |
358 |
| - '`value`.`disabled`', |
359 |
| - '`default_value`.`disabled`', |
360 |
| - 'IFNULL(`value`.`disabled`, `default_value`.`disabled`)' |
361 |
| - ] |
362 |
| - ]) |
363 |
| - ); |
364 |
| - $this->select->expects($this->at(2))->method('joinLeft')->with( |
365 |
| - ['value' => $getTableReturnValue], |
366 |
| - $quoteInfoReturnValue, |
367 |
| - [] |
368 |
| - )->willReturnSelf(); |
369 |
| - $this->select->expects($this->at(3))->method('joinLeft')->with( |
370 |
| - ['default_value' => $getTableReturnValue], |
371 |
| - $quoteDefaultInfoReturnValue, |
372 |
| - [] |
373 |
| - )->willReturnSelf(); |
374 |
| - $this->select->expects($this->at(4))->method('columns')->with([ |
375 |
| - 'label' => 'IFNULL(`value`.`label`, `default_value`.`label`)', |
376 |
| - 'position' => 'IFNULL(`value`.`position`, `default_value`.`position`)', |
377 |
| - 'disabled' => 'IFNULL(`value`.`disabled`, `default_value`.`disabled`)', |
378 |
| - 'label_default' => 'default_value.label', |
379 |
| - 'position_default' => 'default_value.position', |
380 |
| - 'disabled_default' => 'default_value.disabled' |
381 |
| - ])->willReturnSelf(); |
382 |
| - $this->select->expects($this->at(5))->method('where')->with( |
383 |
| - 'main.attribute_id = ?', |
384 |
| - $attributeId |
385 |
| - )->willReturnSelf(); |
386 |
| - $this->select->expects($this->at(6))->method('where') |
387 |
| - ->with('main.disabled = 0')->willReturnSelf(); |
388 |
| - $this->select->expects($this->at(8))->method('where') |
389 |
| - ->with('entity.entity_id = ?', $productId) |
390 |
| - ->willReturnSelf(); |
391 |
| - $this->select->expects($this->once())->method('order') |
392 |
| - ->with($positionCheckSql . ' ' . \Magento\Framework\DB\Select::SQL_ASC) |
393 |
| - ->willReturnSelf(); |
394 |
| - $this->connection->expects($this->once())->method('fetchAll') |
395 |
| - ->with($this->select) |
396 |
| - ->willReturn($resultRow); |
397 |
| - |
398 |
| - $this->assertEquals($resultRow, $this->resource->loadProductGalleryByAttributeId($this->product, $attributeId)); |
399 |
| - } |
400 |
| - |
401 |
| - public function testInsertGalleryValueInStore() |
402 |
| - { |
403 |
| - $data = [ |
404 |
| - 'value_id' => '8', |
405 |
| - 'store_id' => 0, |
406 |
| - 'provider' => '', |
407 |
| - 'url' => 'https://www.youtube.com/watch?v=abcdfghijk', |
408 |
| - 'title' => 'New Title', |
409 |
| - 'description' => 'New Description', |
410 |
| - 'metadata' => 'New metadata', |
411 |
| - ]; |
412 |
| - |
413 |
| - $this->connection->expects($this->once())->method('describeTable')->willReturn($this->fields); |
414 |
| - $this->connection->expects($this->any())->method('prepareColumnValue')->willReturnOnConsecutiveCalls( |
415 |
| - '8', |
416 |
| - 0, |
417 |
| - '', |
418 |
| - 'https://www.youtube.com/watch?v=abcdfghijk', |
419 |
| - 'New Title', |
420 |
| - 'New Description', |
421 |
| - 'New metadata' |
422 |
| - ); |
423 |
| - |
424 |
| - $this->resource->insertGalleryValueInStore($data); |
425 |
| - } |
426 |
| - |
427 |
| - public function testDeleteGalleryValueInStore() |
428 |
| - { |
429 |
| - $valueId = 4; |
430 |
| - $entityId = 6; |
431 |
| - $storeId = 1; |
432 |
| - |
433 |
| - $this->connection->expects($this->exactly(3))->method('quoteInto')->withConsecutive( |
434 |
| - ['value_id = ?', (int)$valueId], |
435 |
| - ['entity_id = ?', (int)$entityId], |
436 |
| - ['store_id = ?', (int)$storeId] |
437 |
| - )->willReturnOnConsecutiveCalls( |
438 |
| - 'value_id = ' . $valueId, |
439 |
| - 'entity_id = ' . $entityId, |
440 |
| - 'store_id = ' . $storeId |
441 |
| - ); |
442 |
| - |
443 |
| - $this->connection->expects($this->once())->method('delete')->with( |
444 |
| - 'table', |
445 |
| - 'value_id = 4 AND entity_id = 6 AND store_id = 1' |
446 |
| - )->willReturnSelf(); |
447 |
| - |
448 |
| - $this->resource->deleteGalleryValueInStore($valueId, $entityId, $storeId); |
449 |
| - } |
450 |
| - |
451 |
| - public function testCountImageUses() |
452 |
| - { |
453 |
| - $results = [ |
454 |
| - [ |
455 |
| - 'value_id' => '1', |
456 |
| - 'attribute_id' => 90, |
457 |
| - 'value' => '/d/o/download_7.jpg', |
458 |
| - 'media_type' => 'image', |
459 |
| - 'disabled' => '0', |
460 |
| - ], |
461 |
| - ]; |
462 |
| - |
463 |
| - $this->connection->expects($this->once())->method('select')->will($this->returnValue($this->select)); |
464 |
| - $this->select->expects($this->at(0))->method('from')->with( |
465 |
| - [ |
466 |
| - 'main' => 'table', |
467 |
| - ], |
468 |
| - '*' |
469 |
| - )->willReturnSelf(); |
470 |
| - $this->select->expects($this->at(1))->method('where')->with( |
471 |
| - 'value = ?', |
472 |
| - 1 |
473 |
| - )->willReturnSelf(); |
474 |
| - $this->connection->expects($this->once())->method('fetchAll') |
475 |
| - ->with($this->select) |
476 |
| - ->willReturn($results); |
477 |
| - $this->assertEquals($this->resource->countImageUses(1), count($results)); |
478 |
| - } |
479 | 285 | }
|
0 commit comments