Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
PurchasedPriceTest.php
Go to the documentation of this file.
1 <?php
7 
11 
15 class PurchasedPriceTest extends \PHPUnit\Framework\TestCase
16 {
20  protected $model;
21 
26 
27  protected function setUp()
28  {
29  $objectManager = new ObjectManager($this);
30  $contextMock = $this->getMockBuilder(\Magento\Framework\View\Element\UiComponent\ContextInterface::class)
31  ->getMockForAbstractClass();
32  $processor = $this->getMockBuilder(\Magento\Framework\View\Element\UiComponent\Processor::class)
33  ->disableOriginalConstructor()
34  ->getMock();
35  $contextMock->expects($this->never())->method('getProcessor')->willReturn($processor);
36  $this->priceFormatterMock = $this->getMockForAbstractClass(
37  \Magento\Framework\Pricing\PriceCurrencyInterface::class
38  );
39  $this->model = $objectManager->getObject(
40  \Magento\Sales\Ui\Component\Listing\Column\PurchasedPrice::class,
41  ['priceFormatter' => $this->priceFormatterMock, 'context' => $contextMock]
42  );
43  }
44 
45  public function testPrepareDataSource()
46  {
47  $itemName = 'itemName';
48  $oldItemValue = 'oldItemValue';
49  $newItemValue = 'newItemValue';
50  $dataSource = [
51  'data' => [
52  'items' => [
53  [
54  $itemName => $oldItemValue,
55  'order_currency_code' => 'US'
56  ]
57  ]
58  ]
59  ];
60 
61  $this->priceFormatterMock->expects($this->once())
62  ->method('format')
63  ->with($oldItemValue, false, null, null, 'US')
64  ->willReturn($newItemValue);
65 
66  $this->model->setData('name', $itemName);
67  $dataSource = $this->model->prepareDataSource($dataSource);
68  $this->assertEquals($newItemValue, $dataSource['data']['items'][0][$itemName]);
69  }
70 }
$objectManager
Definition: bootstrap.php:17
$processor
Definition: 404.php:10