TotalsTest.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\Sales\Test\Unit\Block\Order;
  8. use Magento\Framework\Registry;
  9. use Magento\Sales\Block\Order\Totals;
  10. use Magento\Sales\Model\Order;
  11. use Magento\Sales\Model\Order\Total;
  12. class TotalsTest extends \PHPUnit\Framework\TestCase
  13. {
  14. /**
  15. * @var \Magento\Sales\Block\Order\Totals
  16. */
  17. protected $block;
  18. /**
  19. * @var \Magento\Framework\View\Element\Template\Context|\PHPUnit_Framework_MockObject_MockObject
  20. */
  21. protected $context;
  22. protected function setUp()
  23. {
  24. $this->context = $this->createMock(\Magento\Framework\View\Element\Template\Context::class);
  25. $this->block = new Totals($this->context, new Registry);
  26. $this->block->setOrder($this->createMock(Order::class));
  27. }
  28. public function testApplySortOrder()
  29. {
  30. $this->block->addTotal(new Total(['code' => 'one']), 'last');
  31. $this->block->addTotal(new Total(['code' => 'two']), 'last');
  32. $this->block->addTotal(new Total(['code' => 'three']), 'last');
  33. $this->block->applySortOrder(
  34. [
  35. 'one' => 10,
  36. 'two' => 30,
  37. 'three' => 20,
  38. ]
  39. );
  40. $this->assertEqualsSorted(
  41. [
  42. 'one' => new Total(['code' => 'one']),
  43. 'three' => new Total(['code' => 'three']),
  44. 'two' => new Total(['code' => 'two']),
  45. ],
  46. $this->block->getTotals()
  47. );
  48. }
  49. /**
  50. * @param array $expected
  51. * @param array $actual
  52. */
  53. private function assertEqualsSorted(array $expected, array $actual)
  54. {
  55. $this->assertEquals($expected, $actual, 'Array contents should be equal.');
  56. $this->assertEquals(array_keys($expected), array_keys($actual), 'Array sort order should be equal.');
  57. }
  58. }