ImageProviderTest.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Checkout\Test\Unit\Model\Cart;
  7. class ImageProviderTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /**
  10. * @var \Magento\Checkout\Model\Cart\ImageProvider
  11. */
  12. private $model;
  13. /**
  14. * @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Quote\Api\CartItemRepositoryInterface
  15. */
  16. private $itemRepositoryMock;
  17. /**
  18. * @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Checkout\CustomerData\ItemPoolInterface
  19. */
  20. private $itemPoolMock;
  21. /**
  22. * @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Checkout\CustomerData\DefaultItem
  23. */
  24. private $customerItem;
  25. protected function setUp()
  26. {
  27. $this->itemRepositoryMock = $this->createMock(\Magento\Quote\Api\CartItemRepositoryInterface::class);
  28. $this->itemPoolMock = $this->createMock(\Magento\Checkout\CustomerData\ItemPoolInterface::class);
  29. $this->customerItem = $this->getMockBuilder(\Magento\Checkout\CustomerData\DefaultItem::class)
  30. ->disableOriginalConstructor()
  31. ->getMock();
  32. $this->model = new \Magento\Checkout\Model\Cart\ImageProvider(
  33. $this->itemRepositoryMock,
  34. $this->itemPoolMock,
  35. $this->customerItem
  36. );
  37. }
  38. public function testGetImages()
  39. {
  40. $cartId = 42;
  41. $itemId = 74;
  42. $itemData = ['product_image' => 'Magento.png', 'random' => '3.1415926535'];
  43. $itemMock = $this->createMock(\Magento\Quote\Model\Quote\Item::class);
  44. $itemMock->expects($this->once())->method('getItemId')->willReturn($itemId);
  45. $expectedResult = [$itemId => $itemData['product_image']];
  46. $this->itemRepositoryMock->expects($this->once())->method('getList')->with($cartId)->willReturn([$itemMock]);
  47. $this->customerItem->expects($this->once())->method('getItemData')->with($itemMock)->willReturn($itemData);
  48. $this->assertEquals($expectedResult, $this->model->getImages($cartId));
  49. }
  50. }