Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
MsrpPriceTest.php
Go to the documentation of this file.
1 <?php
8 
10 
14 class MsrpPriceTest extends \PHPUnit\Framework\TestCase
15 {
19  protected $object;
20 
24  protected $helper;
25 
29  protected $saleableItem;
30 
34  protected $price;
35 
39  protected $priceInfo;
40 
44  protected $calculator;
45 
49  protected $config;
50 
54  protected $priceCurrencyMock;
55 
56  protected function setUp()
57  {
58  $this->saleableItem = $this->createPartialMock(
59  \Magento\Catalog\Model\Product::class,
60  ['getPriceInfo', '__wakeup']
61  );
62 
63  $this->priceInfo = $this->createMock(\Magento\Framework\Pricing\PriceInfo\Base::class);
64  $this->price = $this->createMock(\Magento\Catalog\Pricing\Price\BasePrice::class);
65 
66  $this->priceInfo->expects($this->any())
67  ->method('getAdjustments')
68  ->will($this->returnValue([]));
69 
70  $this->saleableItem->expects($this->any())
71  ->method('getPriceInfo')
72  ->will($this->returnValue($this->priceInfo));
73 
74  $this->priceInfo->expects($this->any())
75  ->method('getPrice')
76  ->with($this->equalTo('base_price'))
77  ->will($this->returnValue($this->price));
78 
79  $this->calculator = $this->getMockBuilder(\Magento\Framework\Pricing\Adjustment\Calculator::class)
80  ->disableOriginalConstructor()
81  ->getMock();
82 
83  $this->helper = $this->createPartialMock(
84  \Magento\Msrp\Helper\Data::class,
85  ['isShowPriceOnGesture', 'getMsrpPriceMessage', 'canApplyMsrp']
86  );
87  $this->config = $this->createPartialMock(\Magento\Msrp\Model\Config::class, ['isEnabled']);
88 
89  $this->priceCurrencyMock = $this->createMock(\Magento\Framework\Pricing\PriceCurrencyInterface::class);
90 
91  $this->object = new \Magento\Msrp\Pricing\Price\MsrpPrice(
92  $this->saleableItem,
94  $this->calculator,
95  $this->priceCurrencyMock,
96  $this->helper,
97  $this->config
98  );
99  }
100 
102  {
103  $this->helper->expects($this->once())
104  ->method('isShowPriceOnGesture')
105  ->with($this->equalTo($this->saleableItem))
106  ->will($this->returnValue(true));
107 
108  $this->assertTrue($this->object->isShowPriceOnGesture());
109  }
110 
112  {
113  $this->helper->expects($this->once())
114  ->method('isShowPriceOnGesture')
115  ->with($this->equalTo($this->saleableItem))
116  ->will($this->returnValue(false));
117 
118  $this->assertFalse($this->object->isShowPriceOnGesture());
119  }
120 
121  public function testGetMsrpPriceMessage()
122  {
123  $expectedMessage = 'test';
124  $this->helper->expects($this->once())
125  ->method('getMsrpPriceMessage')
126  ->with($this->equalTo($this->saleableItem))
127  ->will($this->returnValue($expectedMessage));
128 
129  $this->assertEquals($expectedMessage, $this->object->getMsrpPriceMessage());
130  }
131 
132  public function testIsMsrpEnabled()
133  {
134  $this->config->expects($this->once())
135  ->method('isEnabled')
136  ->will($this->returnValue(true));
137 
138  $this->assertTrue($this->object->isMsrpEnabled());
139  }
140 
141  public function testCanApplyMsrp()
142  {
143  $this->helper->expects($this->once())
144  ->method('canApplyMsrp')
145  ->with($this->equalTo($this->saleableItem))
146  ->will($this->returnValue(true));
147 
148  $this->assertTrue($this->object->canApplyMsrp($this->saleableItem));
149  }
150 }