RendererTest.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Weee\Test\Unit\Block\Item\Price;
  7. use Magento\Weee\Model\Tax as WeeeDisplayConfig;
  8. class RendererTest extends \PHPUnit\Framework\TestCase
  9. {
  10. /**
  11. * @var \Magento\Weee\Block\Item\Price\Renderer
  12. */
  13. protected $renderer;
  14. /**
  15. * @var \Magento\Weee\Helper\Data|\PHPUnit_Framework_MockObject_MockObject
  16. */
  17. protected $weeeHelper;
  18. /**
  19. * @var \Magento\Directory\Model\PriceCurrency|\PHPUnit_Framework_MockObject_MockObject
  20. */
  21. protected $priceCurrency;
  22. /**
  23. * @var \Magento\Quote\Model\Quote\Item|\PHPUnit_Framework_MockObject_MockObject
  24. */
  25. protected $item;
  26. const STORE_ID = 'store_id';
  27. const ZONE = 'zone';
  28. protected function setUp()
  29. {
  30. $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  31. $this->weeeHelper = $this->getMockBuilder(\Magento\Weee\Helper\Data::class)
  32. ->disableOriginalConstructor()
  33. ->setMethods([
  34. 'isEnabled',
  35. 'typeOfDisplay',
  36. 'getWeeeTaxInclTax',
  37. 'getRowWeeeTaxInclTax',
  38. 'getBaseRowWeeeTaxInclTax',
  39. 'getBaseWeeeTaxInclTax',
  40. ])
  41. ->getMock();
  42. $this->priceCurrency = $this->getMockBuilder(\Magento\Directory\Model\PriceCurrency::class)
  43. ->disableOriginalConstructor()
  44. ->setMethods(['format'])
  45. ->getMock();
  46. $this->item = $this->getMockBuilder(\Magento\Quote\Model\Quote\Item::class)
  47. ->disableOriginalConstructor()
  48. ->setMethods([
  49. '__wakeup',
  50. 'getWeeeTaxAppliedAmount',
  51. 'getPriceInclTax',
  52. 'getRowTotalInclTax',
  53. 'getCalculationPrice',
  54. 'getRowTotal',
  55. 'getWeeeTaxAppliedRowAmount',
  56. 'getStoreId',
  57. 'getBaseRowTotalInclTax',
  58. 'getBaseRowTotal',
  59. 'getBaseWeeeTaxAppliedRowAmnt',
  60. 'getBasePrice',
  61. 'getBaseWeeeTaxAppliedAmount',
  62. 'getBaseWeeeTaxInclTax',
  63. 'getBasePriceInclTax',
  64. 'getQtyOrdered'
  65. ])
  66. ->getMock();
  67. $this->item->expects($this->any())
  68. ->method('getStoreId')
  69. ->will($this->returnValue(self::STORE_ID));
  70. $this->renderer = $objectManager->getObject(
  71. \Magento\Weee\Block\Item\Price\Renderer::class,
  72. [
  73. 'weeeHelper' => $this->weeeHelper,
  74. 'priceCurrency' => $this->priceCurrency,
  75. ]
  76. );
  77. $this->renderer->setItem($this->item);
  78. $this->renderer->setZone(self::ZONE);
  79. }
  80. /**
  81. * @param bool $isWeeeEnabled
  82. * @param bool $showWeeeDetails
  83. * @param bool $hasWeeeAmount
  84. * @param bool $expectedValue
  85. * @dataProvider displayPriceWithWeeeDetailsDataProvider
  86. */
  87. public function testDisplayPriceWithWeeeDetails(
  88. $isWeeeEnabled,
  89. $showWeeeDetails,
  90. $hasWeeeAmount,
  91. $expectedValue
  92. ) {
  93. $this->weeeHelper->expects($this->once())
  94. ->method('isEnabled')
  95. ->will($this->returnValue($isWeeeEnabled));
  96. $this->weeeHelper->expects($this->any())
  97. ->method('typeOfDisplay')
  98. ->with(
  99. [WeeeDisplayConfig::DISPLAY_INCL_DESCR, WeeeDisplayConfig::DISPLAY_EXCL_DESCR_INCL],
  100. self::ZONE,
  101. self::STORE_ID
  102. )->will($this->returnValue($showWeeeDetails));
  103. $this->item->expects($this->any())
  104. ->method('getWeeeTaxAppliedAmount')
  105. ->will($this->returnValue($hasWeeeAmount));
  106. $this->assertEquals($expectedValue, $this->renderer->displayPriceWithWeeeDetails());
  107. }
  108. /**
  109. * @return array
  110. */
  111. public function displayPriceWithWeeeDetailsDataProvider()
  112. {
  113. $data = [
  114. 'weee_disabled_true_true' => [
  115. 'isWeeeEnabled' => false,
  116. 'showWeeeDetails' => true,
  117. 'hasWeeeAmount' => true,
  118. 'expectedValue' => false,
  119. ],
  120. 'weee_disabled_true_false' => [
  121. 'isWeeeEnabled' => false,
  122. 'showWeeeDetails' => true,
  123. 'hasWeeeAmount' => false,
  124. 'expectedValue' => false,
  125. ],
  126. 'weee_disabled_false_true' => [
  127. 'isWeeeEnabled' => false,
  128. 'showWeeeDetails' => false,
  129. 'hasWeeeAmount' => true,
  130. 'expectedValue' => false,
  131. ],
  132. 'weee_disabled_false_false' => [
  133. 'isWeeeEnabled' => false,
  134. 'showWeeeDetails' => false,
  135. 'hasWeeeAmount' => false,
  136. 'expectedValue' => false,
  137. ],
  138. 'weee_enabled_showdetail_true' => [
  139. 'isWeeeEnabled' => true,
  140. 'showWeeeDetails' => true,
  141. 'hasWeeeAmount' => true,
  142. 'expectedValue' => true,
  143. ],
  144. 'weee_enabled_showdetail_string_zero_false' => [
  145. 'isWeeeEnabled' => true,
  146. 'showWeeeDetails' => true,
  147. 'hasWeeeAmount' => "0.0000",
  148. 'expectedValue' => false,
  149. ],
  150. 'weee_enabled_showdetail_false' => [
  151. 'isWeeeEnabled' => true,
  152. 'showWeeeDetails' => true,
  153. 'hasWeeeAmount' => false,
  154. 'expectedValue' => false,
  155. ],
  156. 'weee_enabled_not_showing_detail_true' => [
  157. 'isWeeeEnabled' => true,
  158. 'showWeeeDetails' => false,
  159. 'hasWeeeAmount' => true,
  160. 'expectedValue' => false,
  161. ],
  162. 'weee_enabled_not_showing_detail_false' => [
  163. 'isWeeeEnabled' => true,
  164. 'showWeeeDetails' => false,
  165. 'hasWeeeAmount' => false,
  166. 'expectedValue' => false,
  167. ],
  168. ];
  169. return $data;
  170. }
  171. /**
  172. * @param $priceInclTax
  173. * @param $weeeTaxInclTax
  174. * @param $weeeEnabled
  175. * @param $includeWeee
  176. * @param $expectedValue
  177. * @dataProvider getDisplayPriceDataProvider
  178. */
  179. public function testGetUnitDisplayPriceInclTax(
  180. $priceInclTax,
  181. $weeeTaxInclTax,
  182. $weeeEnabled,
  183. $includeWeee,
  184. $expectedValue
  185. ) {
  186. $this->weeeHelper->expects($this->once())
  187. ->method('isEnabled')
  188. ->will($this->returnValue($weeeEnabled));
  189. $this->weeeHelper->expects($this->any())
  190. ->method('getWeeeTaxInclTax')
  191. ->with($this->item)
  192. ->will($this->returnValue($weeeTaxInclTax));
  193. $this->item->expects($this->once())
  194. ->method('getPriceInclTax')
  195. ->will($this->returnValue($priceInclTax));
  196. $this->weeeHelper->expects($this->any())
  197. ->method('typeOfDisplay')
  198. ->with([WeeeDisplayConfig::DISPLAY_INCL_DESCR, WeeeDisplayConfig::DISPLAY_INCL], self::ZONE)
  199. ->will($this->returnValue($includeWeee));
  200. $this->assertEquals($expectedValue, $this->renderer->getUnitDisplayPriceInclTax());
  201. }
  202. /**
  203. * @param $basePriceInclTax
  204. * @param $baseWeeeTaxInclTax
  205. * @param $weeeEnabled
  206. * @param $includeWeee
  207. * @param $expectedValue
  208. * @dataProvider getDisplayPriceDataProvider
  209. */
  210. public function testGetBaseUnitDisplayPriceInclTax(
  211. $basePriceInclTax,
  212. $baseWeeeTaxInclTax,
  213. $weeeEnabled,
  214. $includeWeee,
  215. $expectedValue
  216. ) {
  217. $this->weeeHelper->expects($this->once())
  218. ->method('isEnabled')
  219. ->will($this->returnValue($weeeEnabled));
  220. $this->weeeHelper->expects($this->any())
  221. ->method('getBaseWeeeTaxInclTax')
  222. ->with($this->item)
  223. ->will($this->returnValue($baseWeeeTaxInclTax));
  224. $this->item->expects($this->once())
  225. ->method('getBasePriceInclTax')
  226. ->will($this->returnValue($basePriceInclTax));
  227. $this->weeeHelper->expects($this->any())
  228. ->method('typeOfDisplay')
  229. ->with([WeeeDisplayConfig::DISPLAY_INCL_DESCR, WeeeDisplayConfig::DISPLAY_INCL], self::ZONE)
  230. ->will($this->returnValue($includeWeee));
  231. $this->assertEquals($expectedValue, $this->renderer->getBaseUnitDisplayPriceInclTax());
  232. }
  233. /**
  234. * @param $priceExclTax
  235. * @param $weeeTaxExclTax
  236. * @param $weeeEnabled
  237. * @param $includeWeee
  238. * @param $expectedValue
  239. * @dataProvider getDisplayPriceDataProvider
  240. */
  241. public function testGetUnitDisplayPriceExclTax(
  242. $priceExclTax,
  243. $weeeTaxExclTax,
  244. $weeeEnabled,
  245. $includeWeee,
  246. $expectedValue
  247. ) {
  248. $this->weeeHelper->expects($this->once())
  249. ->method('isEnabled')
  250. ->will($this->returnValue($weeeEnabled));
  251. $this->item->expects($this->any())
  252. ->method('getWeeeTaxAppliedAmount')
  253. ->will($this->returnValue($weeeTaxExclTax));
  254. $this->item->expects($this->once())
  255. ->method('getCalculationPrice')
  256. ->will($this->returnValue($priceExclTax));
  257. $this->weeeHelper->expects($this->any())
  258. ->method('typeOfDisplay')
  259. ->with([WeeeDisplayConfig::DISPLAY_INCL_DESCR, WeeeDisplayConfig::DISPLAY_INCL], self::ZONE)
  260. ->will($this->returnValue($includeWeee));
  261. $this->assertEquals($expectedValue, $this->renderer->getUnitDisplayPriceExclTax());
  262. }
  263. /**
  264. * @param $basePriceExclTax
  265. * @param $baseWeeeTaxExclTax
  266. * @param $weeeEnabled
  267. * @param $includeWeee
  268. * @param $expectedValue
  269. * @dataProvider getDisplayPriceDataProvider
  270. */
  271. public function testGetBaseUnitDisplayPriceExclTax(
  272. $basePriceExclTax,
  273. $baseWeeeTaxExclTax,
  274. $weeeEnabled,
  275. $includeWeee,
  276. $expectedValue
  277. ) {
  278. $this->weeeHelper->expects($this->once())
  279. ->method('isEnabled')
  280. ->will($this->returnValue($weeeEnabled));
  281. $this->item->expects($this->any())
  282. ->method('getBaseWeeeTaxAppliedAmount')
  283. ->will($this->returnValue($baseWeeeTaxExclTax));
  284. $this->item->expects($this->once())
  285. ->method('getBaseRowTotal')
  286. ->will($this->returnValue($basePriceExclTax));
  287. $this->item->expects($this->once())
  288. ->method('getQtyOrdered')
  289. ->will($this->returnValue(1));
  290. $this->weeeHelper->expects($this->any())
  291. ->method('typeOfDisplay')
  292. ->with([WeeeDisplayConfig::DISPLAY_INCL_DESCR, WeeeDisplayConfig::DISPLAY_INCL], self::ZONE)
  293. ->will($this->returnValue($includeWeee));
  294. $this->assertEquals($expectedValue, $this->renderer->getBaseUnitDisplayPriceExclTax());
  295. }
  296. /**
  297. * @param $rowTotal
  298. * @param $rowWeeeTaxExclTax
  299. * @param $weeeEnabled
  300. * @param $includeWeee
  301. * @param $expectedValue
  302. * @dataProvider getDisplayPriceDataProvider
  303. */
  304. public function testGetRowDisplayPriceExclTax(
  305. $rowTotal,
  306. $rowWeeeTaxExclTax,
  307. $weeeEnabled,
  308. $includeWeee,
  309. $expectedValue
  310. ) {
  311. $this->weeeHelper->expects($this->once())
  312. ->method('isEnabled')
  313. ->will($this->returnValue($weeeEnabled));
  314. $this->item->expects($this->any())
  315. ->method('getWeeeTaxAppliedRowAmount')
  316. ->will($this->returnValue($rowWeeeTaxExclTax));
  317. $this->item->expects($this->once())
  318. ->method('getRowTotal')
  319. ->will($this->returnValue($rowTotal));
  320. $this->weeeHelper->expects($this->any())
  321. ->method('typeOfDisplay')
  322. ->with([WeeeDisplayConfig::DISPLAY_INCL_DESCR, WeeeDisplayConfig::DISPLAY_INCL], self::ZONE)
  323. ->will($this->returnValue($includeWeee));
  324. $this->assertEquals($expectedValue, $this->renderer->getRowDisplayPriceExclTax());
  325. }
  326. /**
  327. * @param $baseRowTotal
  328. * @param $baseRowWeeeTaxExclTax
  329. * @param $weeeEnabled
  330. * @param $includeWeee
  331. * @param $expectedValue
  332. * @dataProvider getDisplayPriceDataProvider
  333. */
  334. public function testGetBaseRowDisplayPriceExclTax(
  335. $baseRowTotal,
  336. $baseRowWeeeTaxExclTax,
  337. $weeeEnabled,
  338. $includeWeee,
  339. $expectedValue
  340. ) {
  341. $this->weeeHelper->expects($this->once())
  342. ->method('isEnabled')
  343. ->will($this->returnValue($weeeEnabled));
  344. $this->item->expects($this->any())
  345. ->method('getBaseWeeeTaxAppliedRowAmnt')
  346. ->will($this->returnValue($baseRowWeeeTaxExclTax));
  347. $this->item->expects($this->once())
  348. ->method('getBaseRowTotal')
  349. ->will($this->returnValue($baseRowTotal));
  350. $this->weeeHelper->expects($this->any())
  351. ->method('typeOfDisplay')
  352. ->with([WeeeDisplayConfig::DISPLAY_INCL_DESCR, WeeeDisplayConfig::DISPLAY_INCL], self::ZONE)
  353. ->will($this->returnValue($includeWeee));
  354. $this->assertEquals($expectedValue, $this->renderer->getBaseRowDisplayPriceExclTax());
  355. }
  356. /**
  357. * @param $rowTotalInclTax
  358. * @param $rowWeeeTaxInclTax
  359. * @param $weeeEnabled
  360. * @param $includeWeee
  361. * @param $expectedValue
  362. * @dataProvider getDisplayPriceDataProvider
  363. */
  364. public function testGetRowDisplayPriceInclTax(
  365. $rowTotalInclTax,
  366. $rowWeeeTaxInclTax,
  367. $weeeEnabled,
  368. $includeWeee,
  369. $expectedValue
  370. ) {
  371. $this->weeeHelper->expects($this->once())
  372. ->method('isEnabled')
  373. ->will($this->returnValue($weeeEnabled));
  374. $this->weeeHelper->expects($this->any())
  375. ->method('getRowWeeeTaxInclTax')
  376. ->with($this->item)
  377. ->will($this->returnValue($rowWeeeTaxInclTax));
  378. $this->item->expects($this->once())
  379. ->method('getRowTotalInclTax')
  380. ->will($this->returnValue($rowTotalInclTax));
  381. $this->weeeHelper->expects($this->any())
  382. ->method('typeOfDisplay')
  383. ->with([WeeeDisplayConfig::DISPLAY_INCL_DESCR, WeeeDisplayConfig::DISPLAY_INCL], self::ZONE)
  384. ->will($this->returnValue($includeWeee));
  385. $this->assertEquals($expectedValue, $this->renderer->getRowDisplayPriceInclTax());
  386. }
  387. /**
  388. * @param $baseRowTotalInclTax
  389. * @param $baseRowWeeeTaxInclTax
  390. * @param $weeeEnabled
  391. * @param $includeWeee
  392. * @param $expectedValue
  393. * @dataProvider getDisplayPriceDataProvider
  394. */
  395. public function testGetBaseRowDisplayPriceInclTax(
  396. $baseRowTotalInclTax,
  397. $baseRowWeeeTaxInclTax,
  398. $weeeEnabled,
  399. $includeWeee,
  400. $expectedValue
  401. ) {
  402. $this->weeeHelper->expects($this->once())
  403. ->method('isEnabled')
  404. ->will($this->returnValue($weeeEnabled));
  405. $this->weeeHelper->expects($this->any())
  406. ->method('getBaseRowWeeeTaxInclTax')
  407. ->with($this->item)
  408. ->will($this->returnValue($baseRowWeeeTaxInclTax));
  409. $this->item->expects($this->once())
  410. ->method('getBaseRowTotalInclTax')
  411. ->will($this->returnValue($baseRowTotalInclTax));
  412. $this->weeeHelper->expects($this->any())
  413. ->method('typeOfDisplay')
  414. ->with([WeeeDisplayConfig::DISPLAY_INCL_DESCR, WeeeDisplayConfig::DISPLAY_INCL], self::ZONE)
  415. ->will($this->returnValue($includeWeee));
  416. $this->assertEquals($expectedValue, $this->renderer->getBaseRowDisplayPriceInclTax());
  417. }
  418. /**
  419. * @return array
  420. */
  421. public function getDisplayPriceDataProvider()
  422. {
  423. $data = [
  424. 'weee_disabled_true' => [
  425. 'price' => 100,
  426. 'weee' => 10,
  427. 'weee_enabled' => false,
  428. 'include_weee' => true,
  429. 'expected_value' => 100,
  430. ],
  431. 'weee_disabled_false' => [
  432. 'price' => 100,
  433. 'weee' => 10,
  434. 'weee_enabled' => false,
  435. 'include_weee' => false,
  436. 'expected_value' => 100,
  437. ],
  438. 'weee_enabled_include_weee' => [
  439. 'price' => 100,
  440. 'weee' => 10,
  441. 'weee_enabled' => true,
  442. 'include_weee' => true,
  443. 'expected_value' => 110,
  444. ],
  445. 'weee_enabled_not_include_weee' => [
  446. 'price' => 100,
  447. 'weee' => 10,
  448. 'weee_enabled' => true,
  449. 'include_weee' => false,
  450. 'expected_value' => 100,
  451. ],
  452. ];
  453. return $data;
  454. }
  455. /**
  456. * @param $priceInclTax
  457. * @param $weeeTaxInclTax
  458. * @param $weeeEnabled
  459. * @param $expectedValue
  460. * @dataProvider getFinalDisplayPriceDataProvider
  461. */
  462. public function testGetFinalUnitDisplayPriceInclTax(
  463. $priceInclTax,
  464. $weeeTaxInclTax,
  465. $weeeEnabled,
  466. $expectedValue
  467. ) {
  468. $this->weeeHelper->expects($this->once())
  469. ->method('isEnabled')
  470. ->will($this->returnValue($weeeEnabled));
  471. $this->weeeHelper->expects($this->any())
  472. ->method('getWeeeTaxInclTax')
  473. ->with($this->item)
  474. ->will($this->returnValue($weeeTaxInclTax));
  475. $this->item->expects($this->once())
  476. ->method('getPriceInclTax')
  477. ->will($this->returnValue($priceInclTax));
  478. $this->assertEquals($expectedValue, $this->renderer->getFinalUnitDisplayPriceInclTax());
  479. }
  480. /**
  481. * @param $basePriceInclTax
  482. * @param $baseWeeeTaxInclTax
  483. * @param $weeeEnabled
  484. * @param $expectedValue
  485. * @dataProvider getFinalDisplayPriceDataProvider
  486. */
  487. public function testGetBaseFinalUnitDisplayPriceInclTax(
  488. $basePriceInclTax,
  489. $baseWeeeTaxInclTax,
  490. $weeeEnabled,
  491. $expectedValue
  492. ) {
  493. $this->weeeHelper->expects($this->once())
  494. ->method('isEnabled')
  495. ->will($this->returnValue($weeeEnabled));
  496. $this->weeeHelper->expects($this->any())
  497. ->method('getBaseWeeeTaxInclTax')
  498. ->with($this->item)
  499. ->will($this->returnValue($baseWeeeTaxInclTax));
  500. $this->item->expects($this->once())
  501. ->method('getBasePriceInclTax')
  502. ->will($this->returnValue($basePriceInclTax));
  503. $this->assertEquals($expectedValue, $this->renderer->getBaseFinalUnitDisplayPriceInclTax());
  504. }
  505. /**
  506. * @param $priceExclTax
  507. * @param $weeeTaxExclTax
  508. * @param $weeeEnabled
  509. * @param $expectedValue
  510. * @dataProvider getFinalDisplayPriceDataProvider
  511. */
  512. public function testGetFinalUnitDisplayPriceExclTax(
  513. $priceExclTax,
  514. $weeeTaxExclTax,
  515. $weeeEnabled,
  516. $expectedValue
  517. ) {
  518. $this->weeeHelper->expects($this->once())
  519. ->method('isEnabled')
  520. ->will($this->returnValue($weeeEnabled));
  521. $this->item->expects($this->any())
  522. ->method('getWeeeTaxAppliedAmount')
  523. ->will($this->returnValue($weeeTaxExclTax));
  524. $this->item->expects($this->once())
  525. ->method('getCalculationPrice')
  526. ->will($this->returnValue($priceExclTax));
  527. $this->assertEquals($expectedValue, $this->renderer->getFinalUnitDisplayPriceExclTax());
  528. }
  529. /**
  530. * @param $basePriceExclTax
  531. * @param $baseWeeeTaxExclTax
  532. * @param $weeeEnabled
  533. * @param $expectedValue
  534. * @dataProvider getFinalDisplayPriceDataProvider
  535. */
  536. public function testGetBaseFinalUnitDisplayPriceExclTax(
  537. $basePriceExclTax,
  538. $baseWeeeTaxExclTax,
  539. $weeeEnabled,
  540. $expectedValue
  541. ) {
  542. $this->weeeHelper->expects($this->once())
  543. ->method('isEnabled')
  544. ->will($this->returnValue($weeeEnabled));
  545. $this->item->expects($this->any())
  546. ->method('getBaseWeeeTaxAppliedAmount')
  547. ->will($this->returnValue($baseWeeeTaxExclTax));
  548. $this->item->expects($this->once())
  549. ->method('getBaseRowTotal')
  550. ->will($this->returnValue($basePriceExclTax));
  551. $this->item->expects($this->once())
  552. ->method('getQtyOrdered')
  553. ->will($this->returnValue(1));
  554. $this->assertEquals($expectedValue, $this->renderer->getBaseFinalUnitDisplayPriceExclTax());
  555. }
  556. /**
  557. * @param $rowTotal
  558. * @param $rowWeeeTaxExclTax
  559. * @param $weeeEnabled
  560. * @param $expectedValue
  561. * @dataProvider getFinalDisplayPriceDataProvider
  562. */
  563. public function testGetFianlRowDisplayPriceExclTax(
  564. $rowTotal,
  565. $rowWeeeTaxExclTax,
  566. $weeeEnabled,
  567. $expectedValue
  568. ) {
  569. $this->weeeHelper->expects($this->once())
  570. ->method('isEnabled')
  571. ->will($this->returnValue($weeeEnabled));
  572. $this->item->expects($this->any())
  573. ->method('getWeeeTaxAppliedRowAmount')
  574. ->will($this->returnValue($rowWeeeTaxExclTax));
  575. $this->item->expects($this->once())
  576. ->method('getRowTotal')
  577. ->will($this->returnValue($rowTotal));
  578. $this->assertEquals($expectedValue, $this->renderer->getFinalRowDisplayPriceExclTax());
  579. }
  580. /**
  581. * @param $baseRowTotal
  582. * @param $baseRowWeeeTaxExclTax
  583. * @param $weeeEnabled
  584. * @param $expectedValue
  585. * @dataProvider getFinalDisplayPriceDataProvider
  586. */
  587. public function testGetBaseFianlRowDisplayPriceExclTax(
  588. $baseRowTotal,
  589. $baseRowWeeeTaxExclTax,
  590. $weeeEnabled,
  591. $expectedValue
  592. ) {
  593. $this->weeeHelper->expects($this->once())
  594. ->method('isEnabled')
  595. ->will($this->returnValue($weeeEnabled));
  596. $this->item->expects($this->any())
  597. ->method('getBaseWeeeTaxAppliedRowAmnt')
  598. ->will($this->returnValue($baseRowWeeeTaxExclTax));
  599. $this->item->expects($this->once())
  600. ->method('getBaseRowTotal')
  601. ->will($this->returnValue($baseRowTotal));
  602. $this->assertEquals($expectedValue, $this->renderer->getBaseFinalRowDisplayPriceExclTax());
  603. }
  604. /**
  605. * @param $rowTotalInclTax
  606. * @param $rowWeeeTaxInclTax
  607. * @param $weeeEnabled
  608. * @param $expectedValue
  609. * @dataProvider getFinalDisplayPriceDataProvider
  610. */
  611. public function testGetFinalRowDisplayPriceInclTax(
  612. $rowTotalInclTax,
  613. $rowWeeeTaxInclTax,
  614. $weeeEnabled,
  615. $expectedValue
  616. ) {
  617. $this->weeeHelper->expects($this->once())
  618. ->method('isEnabled')
  619. ->will($this->returnValue($weeeEnabled));
  620. $this->weeeHelper->expects($this->any())
  621. ->method('getRowWeeeTaxInclTax')
  622. ->with($this->item)
  623. ->will($this->returnValue($rowWeeeTaxInclTax));
  624. $this->item->expects($this->once())
  625. ->method('getRowTotalInclTax')
  626. ->will($this->returnValue($rowTotalInclTax));
  627. $this->assertEquals($expectedValue, $this->renderer->getFinalRowDisplayPriceInclTax());
  628. }
  629. /**
  630. * @param $baseRowTotalInclTax
  631. * @param $baseRowWeeeTaxInclTax
  632. * @param $weeeEnabled
  633. * @param $expectedValue
  634. * @dataProvider getFinalDisplayPriceDataProvider
  635. */
  636. public function testGetBaseFinalRowDisplayPriceInclTax(
  637. $baseRowTotalInclTax,
  638. $baseRowWeeeTaxInclTax,
  639. $weeeEnabled,
  640. $expectedValue
  641. ) {
  642. $this->weeeHelper->expects($this->once())
  643. ->method('isEnabled')
  644. ->will($this->returnValue($weeeEnabled));
  645. $this->weeeHelper->expects($this->any())
  646. ->method('getBaseRowWeeeTaxInclTax')
  647. ->with($this->item)
  648. ->will($this->returnValue($baseRowWeeeTaxInclTax));
  649. $this->item->expects($this->once())
  650. ->method('getBaseRowTotalInclTax')
  651. ->will($this->returnValue($baseRowTotalInclTax));
  652. $this->assertEquals($expectedValue, $this->renderer->getBaseFinalRowDisplayPriceInclTax());
  653. }
  654. /**
  655. * @return array
  656. */
  657. public function getFinalDisplayPriceDataProvider()
  658. {
  659. $data = [
  660. 'weee_disabled_true' => [
  661. 'price' => 100,
  662. 'weee' => 10,
  663. 'weee_enabled' => false,
  664. 'expected_value' => 100,
  665. ],
  666. 'weee_enabled_include_weee' => [
  667. 'price' => 100,
  668. 'weee' => 10,
  669. 'weee_enabled' => true,
  670. 'expected_value' => 110,
  671. ],
  672. ];
  673. return $data;
  674. }
  675. public function testGetTotalAmount()
  676. {
  677. $rowTotal = 100;
  678. $taxAmount = 10;
  679. $discountTaxCompensationAmount = 2;
  680. $discountAmount = 20;
  681. $weeeAmount = 5;
  682. $expectedValue = 97;
  683. $itemMock = $this->getMockBuilder(\Magento\Sales\Model\Order\Item::class)
  684. ->disableOriginalConstructor()
  685. ->setMethods(
  686. [
  687. 'getRowTotal',
  688. 'getTaxAmount',
  689. 'getDiscountTaxCompensationAmount',
  690. 'getDiscountAmount',
  691. '__wakeup'
  692. ]
  693. )
  694. ->getMock();
  695. $itemMock->expects($this->once())
  696. ->method('getRowTotal')
  697. ->will($this->returnValue($rowTotal));
  698. $itemMock->expects($this->once())
  699. ->method('getTaxAmount')
  700. ->will($this->returnValue($taxAmount));
  701. $itemMock->expects($this->once())
  702. ->method('getDiscountTaxCompensationAmount')
  703. ->will($this->returnValue($discountTaxCompensationAmount));
  704. $itemMock->expects($this->once())
  705. ->method('getDiscountAmount')
  706. ->will($this->returnValue($discountAmount));
  707. $this->weeeHelper->expects($this->once())
  708. ->method('getRowWeeeTaxInclTax')
  709. ->with($itemMock)
  710. ->will($this->returnValue($weeeAmount));
  711. $this->assertEquals($expectedValue, $this->renderer->getTotalAmount($itemMock));
  712. }
  713. public function testGetBaseTotalAmount()
  714. {
  715. $baseRowTotal = 100;
  716. $baseTaxAmount = 10;
  717. $baseDiscountTaxCompensationAmount = 2;
  718. $baseDiscountAmount = 20;
  719. $baseWeeeAmount = 5;
  720. $expectedValue = $baseRowTotal + $baseTaxAmount + $baseDiscountTaxCompensationAmount -
  721. $baseDiscountAmount + $baseWeeeAmount;
  722. $itemMock = $this->getMockBuilder(\Magento\Sales\Model\Order\Item::class)
  723. ->disableOriginalConstructor()
  724. ->setMethods(
  725. [
  726. 'getBaseRowTotal',
  727. 'getBaseTaxAmount',
  728. 'getBaseDiscountTaxCompensationAmount',
  729. 'getBaseDiscountAmount',
  730. '__wakeup'
  731. ]
  732. )
  733. ->getMock();
  734. $itemMock->expects($this->once())
  735. ->method('getBaseRowTotal')
  736. ->will($this->returnValue($baseRowTotal));
  737. $itemMock->expects($this->once())
  738. ->method('getBaseTaxAmount')
  739. ->will($this->returnValue($baseTaxAmount));
  740. $itemMock->expects($this->once())
  741. ->method('getBaseDiscountTaxCompensationAmount')
  742. ->will($this->returnValue($baseDiscountTaxCompensationAmount));
  743. $itemMock->expects($this->once())
  744. ->method('getBaseDiscountAmount')
  745. ->will($this->returnValue($baseDiscountAmount));
  746. $this->weeeHelper->expects($this->once())
  747. ->method('getBaseRowWeeeTaxInclTax')
  748. ->with($itemMock)
  749. ->will($this->returnValue($baseWeeeAmount));
  750. $this->assertEquals($expectedValue, $this->renderer->getBaseTotalAmount($itemMock));
  751. }
  752. }