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