Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DataTest.php
Go to the documentation of this file.
1 <?php
8 
12 class DataTest extends \PHPUnit\Framework\TestCase
13 {
17  protected $helper;
18 
22  protected $priceCurrencyMock;
23 
27  protected $productMock;
28 
29  protected function setUp()
30  {
31  $this->priceCurrencyMock = $this->createMock(\Magento\Framework\Pricing\PriceCurrencyInterface::class);
32  $this->productMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class)
33  ->disableOriginalConstructor()
34  ->setMethods(['getMsrp', 'getPriceInfo', '__wakeup'])
35  ->getMock();
36 
37  $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
38 
39  $this->helper = $objectManager->getObject(
40  \Magento\Msrp\Helper\Data::class,
41  [
42  'priceCurrency' => $this->priceCurrencyMock,
43  ]
44  );
45  }
46 
47  public function testIsMinimalPriceLessMsrp()
48  {
49  $msrp = 120;
50  $convertedFinalPrice = 200;
51  $this->priceCurrencyMock->expects($this->any())
52  ->method('convertAndRound')
53  ->will(
54  $this->returnCallback(
55  function ($arg) {
56  return round(2 * $arg, 2);
57  }
58  )
59  );
60 
61  $finalPriceMock = $this->getMockBuilder(\Magento\Catalog\Pricing\Price\FinalPrice::class)
62  ->disableOriginalConstructor()
63  ->getMock();
64  $finalPriceMock->expects($this->any())
65  ->method('getValue')
66  ->will($this->returnValue($convertedFinalPrice));
67 
68  $priceInfoMock = $this->getMockBuilder(\Magento\Framework\Pricing\PriceInfo\Base::class)
69  ->disableOriginalConstructor()
70  ->getMock();
71  $priceInfoMock->expects($this->once())
72  ->method('getPrice')
73  ->with(\Magento\Catalog\Pricing\Price\FinalPrice::PRICE_CODE)
74  ->will($this->returnValue($finalPriceMock));
75 
76  $this->productMock->expects($this->any())
77  ->method('getMsrp')
78  ->will($this->returnValue($msrp));
79  $this->productMock->expects($this->any())
80  ->method('getPriceInfo')
81  ->will($this->returnValue($priceInfoMock));
82 
83  $result = $this->helper->isMinimalPriceLessMsrp($this->productMock);
84  $this->assertTrue($result, "isMinimalPriceLessMsrp returned incorrect value");
85  }
86 }
$objectManager
Definition: bootstrap.php:17