WeeeTest.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Weee\Test\Unit\Model\Total\Invoice;
  7. use Magento\Framework\Serialize\Serializer\Json;
  8. class WeeeTest extends \PHPUnit\Framework\TestCase
  9. {
  10. /**
  11. * @var \Magento\Weee\Model\Total\Invoice\Weee
  12. */
  13. protected $model;
  14. /**
  15. * @var \Magento\Sales\Model\Order|\PHPUnit_Framework_MockObject_MockObject
  16. */
  17. protected $order;
  18. /**
  19. * @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
  20. */
  21. protected $objectManager;
  22. /**
  23. * @var \Magento\Sales\Model\Order\Invoice|\PHPUnit_Framework_MockObject_MockObject
  24. */
  25. protected $invoice;
  26. /**
  27. * @var \Magento\Weee\Helper\Data|\PHPUnit_Framework_MockObject_MockObject
  28. */
  29. protected $weeeData;
  30. protected function setUp()
  31. {
  32. $this->weeeData = $this->getMockBuilder(\Magento\Weee\Helper\Data::class)
  33. ->setMethods(
  34. [
  35. 'getRowWeeeTaxInclTax',
  36. 'getBaseRowWeeeTaxInclTax',
  37. 'getWeeeAmountInvoiced',
  38. 'getBaseWeeeAmountInvoiced',
  39. 'getWeeeTaxAmountInvoiced',
  40. 'getBaseWeeeTaxAmountInvoiced',
  41. 'getApplied',
  42. 'setApplied',
  43. 'includeInSubtotal',
  44. ]
  45. )->disableOriginalConstructor()
  46. ->getMock();
  47. $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  48. $serializer = $this->objectManager->getObject(Json::class);
  49. /** @var \Magento\Sales\Model\Order\Invoice\Total\Tax $model */
  50. $this->model = $this->objectManager->getObject(
  51. \Magento\Weee\Model\Total\Invoice\Weee::class,
  52. [
  53. 'weeeData' => $this->weeeData,
  54. 'serializer' => $serializer
  55. ]
  56. );
  57. $this->order = $this->createPartialMock(\Magento\Sales\Model\Order::class, [
  58. '__wakeup'
  59. ]);
  60. $this->invoice = $this->createPartialMock(\Magento\Sales\Model\Order\Invoice::class, [
  61. 'getAllItems',
  62. 'getOrder',
  63. 'roundPrice',
  64. 'isLast',
  65. 'getStore',
  66. '__wakeup',
  67. ]);
  68. $this->invoice->expects($this->atLeastOnce())->method('getOrder')->will($this->returnValue($this->order));
  69. }
  70. /**
  71. * @param $orderData
  72. */
  73. private function setupOrder($orderData)
  74. {
  75. //Set up order mock
  76. foreach ($orderData['data_fields'] as $key => $value) {
  77. $this->order->setData($key, $value);
  78. }
  79. }
  80. /**
  81. * @param array $orderData
  82. * @param array $invoiceData
  83. * @param array $expectedResults
  84. * @dataProvider collectDataProvider
  85. */
  86. public function testCollect($orderData, $invoiceData, $expectedResults)
  87. {
  88. $roundingDelta = [];
  89. $this->setupOrder($orderData);
  90. //Set up weeeData mock
  91. $this->weeeData->expects($this->once())
  92. ->method('includeInSubtotal')
  93. ->will($this->returnValue($invoiceData['include_in_subtotal']));
  94. //Set up invoice mock
  95. /** @var \Magento\Sales\Model\Order\Invoice\Item[] $invoiceItems */
  96. $invoiceItems = [];
  97. foreach ($invoiceData['items'] as $itemKey => $invoiceItemData) {
  98. $invoiceItems[$itemKey] = $this->getInvoiceItem($invoiceItemData);
  99. }
  100. $this->invoice->expects($this->once())
  101. ->method('getAllItems')
  102. ->will($this->returnValue($invoiceItems));
  103. $this->invoice->expects($this->once())
  104. ->method('isLast')
  105. ->will($this->returnValue($invoiceData['is_last']));
  106. foreach ($invoiceData['data_fields'] as $key => $value) {
  107. $this->invoice->setData($key, $value);
  108. }
  109. $this->invoice->expects($this->any())
  110. ->method('roundPrice')
  111. ->will($this->returnCallback(
  112. function ($price, $type) use (&$roundingDelta) {
  113. if (!isset($roundingDelta[$type])) {
  114. $roundingDelta[$type] = 0;
  115. }
  116. $roundedPrice = round($price + $roundingDelta[$type], 2);
  117. $roundingDelta[$type] = $price - $roundedPrice;
  118. return $roundedPrice;
  119. }
  120. ));
  121. $this->model->collect($this->invoice);
  122. //verify invoice data
  123. foreach ($expectedResults['invoice_data'] as $key => $value) {
  124. $this->assertEquals($value, $this->invoice->getData($key), 'Invoice data field '.$key.' is incorrect');
  125. }
  126. //verify invoice item data
  127. foreach ($expectedResults['invoice_items'] as $itemKey => $itemData) {
  128. $invoiceItem = $invoiceItems[$itemKey];
  129. foreach ($itemData as $key => $value) {
  130. if ($key == 'tax_ratio') {
  131. $taxRatio = json_decode($invoiceItem->getData($key), true);
  132. $this->assertEquals($value['weee'], $taxRatio['weee'], "Tax ratio is incorrect");
  133. } else {
  134. $this->assertEquals(
  135. $value,
  136. $invoiceItem->getData($key),
  137. 'Invoice item field '.$key.' is incorrect'
  138. );
  139. }
  140. }
  141. }
  142. }
  143. /**
  144. * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  145. * @return array
  146. */
  147. public function collectDataProvider()
  148. {
  149. $result = [];
  150. // 3 item_1, $100 with $weee, 8.25 tax rate, full invoice
  151. $result['complete_invoice'] = [
  152. 'order_data' => [
  153. 'previous_invoices' => [
  154. ],
  155. 'data_fields' => [
  156. 'shipping_tax_amount' => 1.24,
  157. 'base_shipping_tax_amount' => 1.24,
  158. 'shipping_discount_tax_compensation_amount' => 0,
  159. 'base_shipping_discount_tax_compensation_amount' => 0,
  160. 'tax_amount' => 16.09,
  161. 'tax_invoiced' => 0,
  162. 'base_tax_amount' => 16.09,
  163. 'base_tax_amount_invoiced' => 0,
  164. 'subtotal' => '300',
  165. 'base_subtotal' => '300',
  166. ],
  167. ],
  168. 'invoice_data' => [
  169. 'items' => [
  170. 'item_1' => [
  171. 'order_item' => [
  172. 'qty_ordered' => 3,
  173. 'weee_tax_applied_row_amount' => 30,
  174. 'base_weee_tax_applied_row_amnt' => 30,
  175. 'row_weee_tax_incl_tax' => 32.47,
  176. 'base_row_weee_tax_incl_tax' => 32.47,
  177. 'weee_amount_invoiced' => 0,
  178. 'base_weee_amount_invoiced' => 0,
  179. 'weee_tax_amount_invoiced' => 0,
  180. 'base_weee_tax_amount_invoiced' => 0,
  181. 'applied_weee' => [
  182. [
  183. 'title' => 'recycling_fee',
  184. 'base_row_amount' => 30,
  185. 'row_amount' => 30,
  186. 'base_row_amount_incl_tax' => 32.47,
  187. 'row_amount_incl_tax' => 32.47,
  188. ],
  189. ],
  190. 'applied_weee_updated' => [
  191. 'base_row_amount_invoiced' => 30,
  192. 'row_amount_invoiced' => 30,
  193. 'base_tax_amount_invoiced' => 2.47,
  194. 'tax_amount_invoiced' => 2.47,
  195. ],
  196. 'qty_invoiced' => 0,
  197. ],
  198. 'is_last' => true,
  199. 'data_fields' => [
  200. 'qty' => 3,
  201. 'applied_weee' => [
  202. [
  203. ],
  204. ],
  205. ],
  206. ],
  207. ],
  208. 'is_last' => true,
  209. 'include_in_subtotal' => false,
  210. 'data_fields' => [
  211. 'grand_total' => 181.09,
  212. 'base_grand_total' => 181.09,
  213. 'subtotal' => 300,
  214. 'base_subtotal' => 300,
  215. 'subtotal_incl_tax' => 314.85,
  216. 'base_subtotal_incl_tax' => 314.85,
  217. 'tax_amount' => 16.09,
  218. 'base_tax_amount' => 16.09,
  219. ],
  220. ],
  221. 'expected_results' => [
  222. 'invoice_items' => [
  223. 'item_1' => [
  224. 'applied_weee' => [
  225. [
  226. 'title' => 'recycling_fee',
  227. 'base_row_amount' => 30,
  228. 'row_amount' => 30,
  229. 'base_row_amount_incl_tax' => 32.47,
  230. 'row_amount_incl_tax' => 32.47,
  231. ],
  232. ],
  233. 'weee_tax_applied_row_amount' => 30,
  234. 'base_weee_tax_applied_row_amount' => 30,
  235. 'tax_ratio' => ["weee" => 1.0],
  236. ],
  237. ],
  238. 'invoice_data' => [
  239. 'grand_total' => 211.09,
  240. 'base_grand_total' => 211.09,
  241. 'tax_amount' => 16.09,
  242. 'base_tax_amount' => 16.09,
  243. 'subtotal' => 300,
  244. 'base_subtotal' => 300,
  245. 'subtotal_incl_tax' => 344.85,
  246. 'base_subtotal_incl_tax' => 344.85,
  247. ],
  248. ],
  249. ];
  250. // 3 item_1, $100 with $weee, 8.25 tax rate, partial invoice, invoice qty=2
  251. $result['partial_invoice'] = [
  252. 'order_data' => [
  253. 'previous_invoices' => [
  254. ],
  255. 'data_fields' => [
  256. 'shipping_tax_amount' => 1.24,
  257. 'base_shipping_tax_amount' => 1.24,
  258. 'shipping_discount_tax_compensation_amount' => 0,
  259. 'base_shipping_discount_tax_compensation_amount' => 0,
  260. 'tax_amount' => 16.09,
  261. 'tax_invoiced' => 0,
  262. 'base_tax_amount' => 16.09,
  263. 'base_tax_amount_invoiced' => 0,
  264. 'subtotal' => '300',
  265. 'base_subtotal' => '300',
  266. ],
  267. ],
  268. 'invoice_data' => [
  269. 'items' => [
  270. 'item_1' => [
  271. 'order_item' => [
  272. 'qty_ordered' => 3,
  273. 'weee_tax_applied_row_amount' => 30,
  274. 'base_weee_tax_applied_row_amnt' => 30,
  275. 'row_weee_tax_incl_tax' => 32.47,
  276. 'base_row_weee_tax_incl_tax' => 32.47,
  277. 'weee_amount_invoiced' => 0,
  278. 'base_weee_amount_invoiced' => 0,
  279. 'weee_tax_amount_invoiced' => 0,
  280. 'base_weee_tax_amount_invoiced' => 0,
  281. 'applied_weee' => [
  282. [
  283. 'title' => 'recycling_fee',
  284. 'base_row_amount' => 30,
  285. 'row_amount' => 30,
  286. 'base_row_amount_incl_tax' => 32.47,
  287. 'row_amount_incl_tax' => 32.47,
  288. ],
  289. ],
  290. 'applied_weee_updated' => [
  291. 'base_row_amount_invoiced' => 30,
  292. 'row_amount_invoiced' => 30,
  293. 'base_tax_amount_invoiced' => 2.47,
  294. 'tax_amount_invoiced' => 2.47,
  295. ],
  296. 'qty_invoiced' => 0,
  297. ],
  298. 'is_last' => false,
  299. 'data_fields' => [
  300. 'qty' => 2,
  301. 'applied_weee' => [
  302. [
  303. ],
  304. ],
  305. ],
  306. ],
  307. ],
  308. 'is_last' => false,
  309. 'include_in_subtotal' => false,
  310. 'data_fields' => [
  311. 'grand_total' => 124.49,
  312. 'base_grand_total' => 124.49,
  313. 'subtotal' => 200,
  314. 'base_subtotal' => 200,
  315. 'subtotal_incl_tax' => 216.5,
  316. 'base_subtotal_incl_tax' => 216.5,
  317. 'tax_amount' => 9.49,
  318. 'base_tax_amount' => 9.49,
  319. ],
  320. ],
  321. 'expected_results' => [
  322. 'invoice_items' => [
  323. 'item_1' => [
  324. 'applied_weee' => [
  325. [
  326. 'title' => 'recycling_fee',
  327. 'base_row_amount' => 20,
  328. 'row_amount' => 20,
  329. 'base_row_amount_incl_tax' => 21.65,
  330. 'row_amount_incl_tax' => 21.65,
  331. ],
  332. ],
  333. 'tax_ratio' => ['weee' => 1.65 / 2.47],
  334. 'weee_tax_applied_row_amount' => 20,
  335. 'base_weee_tax_applied_row_amount' => 20,
  336. ],
  337. ],
  338. 'invoice_data' => [
  339. 'grand_total' => 146.14,
  340. 'base_grand_total' => 146.14,
  341. 'tax_amount' => 11.14,
  342. 'base_tax_amount' => 11.14,
  343. 'subtotal' => 200,
  344. 'base_subtotal' => 200,
  345. 'subtotal_incl_tax' => 238.15,
  346. 'base_subtotal_incl_tax' => 238.15,
  347. ],
  348. ],
  349. ];
  350. // 3 item_1, $100 with $weee, 8.25 tax rate, partial invoice: one item invoiced
  351. // invoice another item
  352. $result['second_partial_invoice'] = [
  353. 'order_data' => [
  354. 'previous_invoices' => [
  355. ],
  356. 'data_fields' => [
  357. 'shipping_tax_amount' => 1.24,
  358. 'base_shipping_tax_amount' => 1.24,
  359. 'shipping_discount_tax_compensation_amount' => 0,
  360. 'base_shipping_discount_tax_compensation_amount' => 0,
  361. 'tax_amount' => 16.09,
  362. 'tax_invoiced' => 0,
  363. 'base_tax_amount' => 16.09,
  364. 'base_tax_amount_invoiced' => 0,
  365. 'subtotal' => '300',
  366. 'base_subtotal' => '300',
  367. ],
  368. ],
  369. 'invoice_data' => [
  370. 'items' => [
  371. 'item_1' => [
  372. 'order_item' => [
  373. 'qty_ordered' => 3,
  374. 'weee_tax_applied_row_amount' => 30,
  375. 'base_weee_tax_applied_row_amnt' => 30,
  376. 'row_weee_tax_incl_tax' => 32.47,
  377. 'base_row_weee_tax_incl_tax' => 32.47,
  378. 'weee_amount_invoiced' => 0,
  379. 'base_weee_amount_invoiced' => 0,
  380. 'weee_tax_amount_invoiced' => 0,
  381. 'base_weee_tax_amount_invoiced' => 0,
  382. 'applied_weee' => [
  383. [
  384. 'title' => 'recycling_fee',
  385. 'base_row_amount' => 30,
  386. 'row_amount' => 30,
  387. 'base_row_amount_incl_tax' => 32.47,
  388. 'row_amount_incl_tax' => 32.47,
  389. ],
  390. ],
  391. 'applied_weee_updated' => [
  392. 'base_row_amount_invoiced' => 30,
  393. 'row_amount_invoiced' => 30,
  394. 'base_tax_amount_invoiced' => 2.47,
  395. 'tax_amount_invoiced' => 2.47,
  396. ],
  397. 'qty_invoiced' => 1,
  398. ],
  399. 'is_last' => false,
  400. 'data_fields' => [
  401. 'qty' => 1,
  402. 'applied_weee' => [
  403. [
  404. ],
  405. ],
  406. ],
  407. ],
  408. ],
  409. 'is_last' => false,
  410. 'include_in_subtotal' => false,
  411. 'data_fields' => [
  412. 'grand_total' => 54.13,
  413. 'base_grand_total' => 54.13,
  414. 'tax_amount' => 4.13,
  415. 'base_tax_amount' => 4.13,
  416. 'subtotal' => 100,
  417. 'base_subtotal' => 100,
  418. 'subtotal_incl_tax' => 108.25,
  419. 'base_subtotal_incl_tax' => 108.25,
  420. ],
  421. ],
  422. 'expected_results' => [
  423. 'invoice_items' => [
  424. 'item_1' => [
  425. 'applied_weee' => [
  426. [
  427. 'title' => 'recycling_fee',
  428. 'base_row_amount' => 10,
  429. 'row_amount' => 10,
  430. 'base_row_amount_incl_tax' => 10.82,
  431. 'row_amount_incl_tax' => 10.82,
  432. ],
  433. ],
  434. 'tax_ratio' => ['weee' => 0.82 / 2.47],
  435. 'weee_tax_applied_row_amount' => 10,
  436. 'base_weee_tax_applied_row_amount' => 10,
  437. ],
  438. ],
  439. 'invoice_data' => [
  440. 'grand_total' => 64.95,
  441. 'base_grand_total' => 64.95,
  442. 'tax_amount' => 4.95,
  443. 'base_tax_amount' => 4.95,
  444. 'subtotal' => 100,
  445. 'base_subtotal' => 100,
  446. 'subtotal_incl_tax' => 119.07,
  447. 'base_subtotal_incl_tax' => 119.07,
  448. ],
  449. ],
  450. ];
  451. // 3 item_1, $100 with $weee, 8.25 tax rate, partial invoice: two item invoiced
  452. // invoice another item
  453. $result['last_partial_invoice'] = [
  454. 'order_data' => [
  455. 'previous_invoices' => [
  456. ],
  457. 'data_fields' => [
  458. 'shipping_tax_amount' => 1.24,
  459. 'base_shipping_tax_amount' => 1.24,
  460. 'shipping_discount_tax_compensation_amount' => 0,
  461. 'base_shipping_discount_tax_compensation_amount' => 0,
  462. 'tax_amount' => 16.09,
  463. 'tax_invoiced' => 11.14,
  464. 'base_tax_amount' => 16.09,
  465. 'base_tax_invoiced' => 11.14,
  466. 'subtotal' => '300',
  467. 'base_subtotal' => '300',
  468. ],
  469. ],
  470. 'invoice_data' => [
  471. 'items' => [
  472. 'item_1' => [
  473. 'order_item' => [
  474. 'qty_ordered' => 3,
  475. 'weee_tax_applied_row_amount' => 30,
  476. 'base_weee_tax_applied_row_amnt' => 30,
  477. 'row_weee_tax_incl_tax' => 32.47,
  478. 'base_row_weee_tax_incl_tax' => 32.47,
  479. 'weee_amount_invoiced' => 20,
  480. 'base_weee_amount_invoiced' => 20,
  481. 'weee_tax_amount_invoiced' => 1.64,
  482. 'base_weee_tax_amount_invoiced' => 1.64,
  483. 'applied_weee' => [
  484. [
  485. 'title' => 'recycling_fee',
  486. 'base_row_amount' => 30,
  487. 'row_amount' => 30,
  488. 'base_row_amount_incl_tax' => 32.47,
  489. 'row_amount_incl_tax' => 32.47,
  490. ],
  491. ],
  492. 'applied_weee_updated' => [
  493. 'base_row_amount_invoiced' => 30,
  494. 'row_amount_invoiced' => 30,
  495. 'base_tax_amount_invoiced' => 2.47,
  496. 'tax_amount_invoiced' => 2.47,
  497. ],
  498. 'qty_invoiced' => 2,
  499. ],
  500. 'is_last' => true,
  501. 'data_fields' => [
  502. 'qty' => 1,
  503. 'applied_weee' => [
  504. [
  505. ],
  506. ],
  507. ],
  508. ],
  509. ],
  510. 'is_last' => true,
  511. 'include_in_subtotal' => false,
  512. 'data_fields' => [
  513. 'grand_total' => 54.95,
  514. 'base_grand_total' => 54.95,
  515. 'tax_amount' => 4.95,
  516. 'base_tax_amount' => 4.95,
  517. 'subtotal' => 100,
  518. 'base_subtotal' => 100,
  519. 'subtotal_incl_tax' => 104.95,
  520. 'base_subtotal_incl_tax' => 104.95,
  521. ],
  522. ],
  523. 'expected_results' => [
  524. 'invoice_items' => [
  525. 'item_1' => [
  526. 'applied_weee' => [
  527. [
  528. 'title' => 'recycling_fee',
  529. 'base_row_amount' => 10,
  530. 'row_amount' => 10,
  531. 'base_row_amount_incl_tax' => 10.82,
  532. 'row_amount_incl_tax' => 10.82,
  533. ],
  534. ],
  535. 'tax_ratio' => ['weee' => 0.83 / 2.47],
  536. 'weee_tax_applied_row_amount' => 10,
  537. 'base_weee_tax_applied_row_amount' => 10,
  538. ],
  539. ],
  540. 'invoice_data' => [
  541. 'grand_total' => 64.95,
  542. 'base_grand_total' => 64.95,
  543. 'tax_amount' => 4.95,
  544. 'base_tax_amount' => 4.95,
  545. 'subtotal' => 100,
  546. 'base_subtotal' => 100,
  547. 'subtotal_incl_tax' => 114.95,
  548. 'base_subtotal_incl_tax' => 114.95,
  549. ],
  550. ],
  551. ];
  552. // 3 item_1, $100 with $weee, 8.25 tax rate. Invoicing qty 0.
  553. $result['zero_invoice'] = [
  554. 'order_data' => [
  555. 'previous_invoices' => [
  556. ],
  557. 'data_fields' => [
  558. 'shipping_tax_amount' => 1.24,
  559. 'base_shipping_tax_amount' => 1.24,
  560. 'shipping_discount_tax_compensation_amount' => 0,
  561. 'base_shipping_discount_tax_compensation_amount' => 0,
  562. 'tax_amount' => 16.09,
  563. 'tax_invoiced' => 0,
  564. 'base_tax_amount' => 16.09,
  565. 'base_tax_amount_invoiced' => 0,
  566. 'subtotal' => '300',
  567. 'base_subtotal' => '300',
  568. ],
  569. ],
  570. 'invoice_data' => [
  571. 'items' => [
  572. 'item_1' => [
  573. 'order_item' => [
  574. 'qty_ordered' => 3,
  575. 'weee_tax_applied_row_amount' => 30,
  576. 'base_weee_tax_applied_row_amnt' => 30,
  577. 'row_weee_tax_incl_tax' => 32.47,
  578. 'base_row_weee_tax_incl_tax' => 32.47,
  579. 'weee_amount_invoiced' => 0,
  580. 'base_weee_amount_invoiced' => 0,
  581. 'weee_tax_amount_invoiced' => 0,
  582. 'base_weee_tax_amount_invoiced' => 0,
  583. 'applied_weee' => [
  584. [
  585. 'title' => 'recycling_fee',
  586. 'base_row_amount' => 30,
  587. 'row_amount' => 30,
  588. 'base_row_amount_incl_tax' => 32.47,
  589. 'row_amount_incl_tax' => 32.47,
  590. ],
  591. ],
  592. 'applied_weee_updated' => [
  593. 'base_row_amount_invoiced' => 30,
  594. 'row_amount_invoiced' => 30,
  595. 'base_tax_amount_invoiced' => 2.47,
  596. 'tax_amount_invoiced' => 2.47,
  597. ],
  598. 'qty_invoiced' => 0,
  599. ],
  600. 'is_last' => true,
  601. 'data_fields' => [
  602. 'qty' => 0,
  603. 'applied_weee' => [
  604. [
  605. ],
  606. ],
  607. ],
  608. ],
  609. ],
  610. 'is_last' => true,
  611. 'include_in_subtotal' => false,
  612. 'data_fields' => [
  613. 'grand_total' => 181.09,
  614. 'base_grand_total' => 181.09,
  615. 'subtotal' => 300,
  616. 'base_subtotal' => 300,
  617. 'subtotal_incl_tax' => 314.85,
  618. 'base_subtotal_incl_tax' => 314.85,
  619. 'tax_amount' => 16.09,
  620. 'base_tax_amount' => 16.09,
  621. ],
  622. ],
  623. 'expected_results' => [
  624. 'invoice_items' => [
  625. 'item_1' => [
  626. 'applied_weee' => [
  627. [
  628. 'title' => 'recycling_fee',
  629. 'base_row_amount' => 0,
  630. 'row_amount' => 0,
  631. 'base_row_amount_incl_tax' => 0,
  632. 'row_amount_incl_tax' => 0,
  633. ],
  634. ],
  635. ],
  636. ],
  637. 'invoice_data' => [
  638. 'subtotal' => 300,
  639. 'base_subtotal' => 300,
  640. ],
  641. ],
  642. ];
  643. return $result;
  644. }
  645. /**
  646. * @param $invoiceItemData array
  647. * @return \Magento\Sales\Model\Order\Invoice\Item|\PHPUnit_Framework_MockObject_MockObject
  648. */
  649. protected function getInvoiceItem($invoiceItemData)
  650. {
  651. /** @var \Magento\Sales\Model\Order\Item|\PHPUnit_Framework_MockObject_MockObject $orderItem */
  652. $orderItem = $this->createPartialMock(\Magento\Sales\Model\Order\Item::class, [
  653. 'isDummy',
  654. '__wakeup'
  655. ]);
  656. foreach ($invoiceItemData['order_item'] as $key => $value) {
  657. $orderItem->setData($key, $value);
  658. }
  659. $this->weeeData->expects($this->once())
  660. ->method('getRowWeeeTaxInclTax')
  661. ->with($orderItem)
  662. ->will($this->returnValue($orderItem->getRowWeeeTaxInclTax()));
  663. $this->weeeData->expects($this->once())
  664. ->method('getBaseRowWeeeTaxInclTax')
  665. ->with($orderItem)
  666. ->will($this->returnValue($orderItem->getBaseRowWeeeTaxInclTax()));
  667. if ($invoiceItemData['is_last']) {
  668. $this->weeeData->expects($this->once())
  669. ->method('getWeeeAmountInvoiced')
  670. ->with($orderItem)
  671. ->will($this->returnValue($orderItem->getWeeeAmountInvoiced()));
  672. $this->weeeData->expects($this->once())
  673. ->method('getBaseWeeeAmountInvoiced')
  674. ->with($orderItem)
  675. ->will($this->returnValue($orderItem->getBaseWeeeAmountInvoiced()));
  676. $this->weeeData->expects($this->once())
  677. ->method('getWeeeTaxAmountInvoiced')
  678. ->with($orderItem)
  679. ->will($this->returnValue($orderItem->getWeeeTaxAmountInvoiced()));
  680. $this->weeeData->expects($this->once())
  681. ->method('getBaseWeeeTaxAmountInvoiced')
  682. ->with($orderItem)
  683. ->will($this->returnValue($orderItem->getBaseWeeeTaxAmountInvoiced()));
  684. }
  685. /** @var \Magento\Sales\Model\Order\Invoice\Item|\PHPUnit_Framework_MockObject_MockObject $invoiceItem */
  686. $invoiceItem = $this->createPartialMock(\Magento\Sales\Model\Order\Invoice\Item::class, [
  687. 'getOrderItem',
  688. 'isLast',
  689. '__wakeup'
  690. ]);
  691. $invoiceItem->expects($this->any())->method('getOrderItem')->will($this->returnValue($orderItem));
  692. $invoiceItem->expects($this->any())
  693. ->method('isLast')
  694. ->will($this->returnValue($invoiceItemData['is_last']));
  695. foreach ($invoiceItemData['data_fields'] as $key => $value) {
  696. $invoiceItem->setData($key, $value);
  697. }
  698. $this->weeeData->expects($this->any())
  699. ->method('getApplied')
  700. ->will($this->returnCallback(
  701. function ($item) {
  702. return $item->getAppliedWeee();
  703. }
  704. ));
  705. $this->weeeData->expects($this->any())
  706. ->method('setApplied')
  707. ->will($this->returnCallback(
  708. function ($item, $weee) {
  709. return $item->setAppliedWeee($weee);
  710. }
  711. ));
  712. return $invoiceItem;
  713. }
  714. }