|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +declare(strict_types=1); |
| 7 | + |
| 8 | +namespace Magento\Backend\Test\Unit\Block\Widget\Grid\Column\Filter; |
| 9 | + |
| 10 | +use Magento\Backend\Block\Context; |
| 11 | +use Magento\Backend\Block\Widget\Grid\Column; |
| 12 | +use Magento\Backend\Block\Widget\Grid\Column\Filter\Price; |
| 13 | +use Magento\Framework\App\RequestInterface; |
| 14 | +use Magento\Framework\DB\Helper; |
| 15 | +use Magento\Directory\Model\Currency; |
| 16 | +use Magento\Directory\Model\Currency\DefaultLocator; |
| 17 | +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; |
| 18 | +use PHPUnit\Framework\MockObject\MockObject; |
| 19 | +use PHPUnit\Framework\TestCase; |
| 20 | + |
| 21 | +class PriceTest extends TestCase |
| 22 | +{ |
| 23 | + /** @var RequestInterface|MockObject */ |
| 24 | + private $requestMock; |
| 25 | + |
| 26 | + /** @var Context|MockObject */ |
| 27 | + private $context; |
| 28 | + |
| 29 | + /** @var Helper|MockObject */ |
| 30 | + private $helper; |
| 31 | + |
| 32 | + /** @var Currency|MockObject */ |
| 33 | + private $currency; |
| 34 | + |
| 35 | + /** @var DefaultLocator|MockObject */ |
| 36 | + private $currencyLocator; |
| 37 | + |
| 38 | + /** @var Column|MockObject */ |
| 39 | + private $columnMock; |
| 40 | + |
| 41 | + /** @var Price */ |
| 42 | + private $blockPrice; |
| 43 | + |
| 44 | + protected function setUp(): void |
| 45 | + { |
| 46 | + $this->requestMock = $this->getMockForAbstractClass(RequestInterface::class); |
| 47 | + |
| 48 | + $this->context = $this->createMock(Context::class); |
| 49 | + $this->context->expects($this->any())->method('getRequest')->willReturn($this->requestMock); |
| 50 | + |
| 51 | + $this->helper = $this->createMock(Helper::class); |
| 52 | + |
| 53 | + $this->currency = $this->getMockBuilder(Currency::class) |
| 54 | + ->disableOriginalConstructor() |
| 55 | + ->setMethods(['getAnyRate']) |
| 56 | + ->getMock(); |
| 57 | + |
| 58 | + $this->currencyLocator = $this->createMock(DefaultLocator::class); |
| 59 | + |
| 60 | + $this->columnMock = $this->getMockBuilder(Column::class) |
| 61 | + ->disableOriginalConstructor() |
| 62 | + ->setMethods(['getCurrencyCode']) |
| 63 | + ->getMock(); |
| 64 | + |
| 65 | + $helper = new ObjectManager($this); |
| 66 | + |
| 67 | + $this->blockPrice = $helper->getObject(Price::class, [ |
| 68 | + 'context' => $this->context, |
| 69 | + 'resourceHelper' => $this->helper, |
| 70 | + 'currencyModel' => $this->currency, |
| 71 | + 'currencyLocator' => $this->currencyLocator |
| 72 | + ]); |
| 73 | + $this->blockPrice->setColumn($this->columnMock); |
| 74 | + } |
| 75 | + |
| 76 | + public function testGetCondition() |
| 77 | + { |
| 78 | + $this->currencyLocator->expects( |
| 79 | + $this->any() |
| 80 | + )->method( |
| 81 | + 'getDefaultCurrency' |
| 82 | + )->with( |
| 83 | + $this->requestMock |
| 84 | + )->willReturn( |
| 85 | + 'defaultCurrency' |
| 86 | + ); |
| 87 | + |
| 88 | + $this->currency->expects($this->at(0)) |
| 89 | + ->method('getAnyRate') |
| 90 | + ->with('defaultCurrency') |
| 91 | + ->willReturn(1.0); |
| 92 | + |
| 93 | + $testValue = [ |
| 94 | + 'value' => [ |
| 95 | + 'from' => '1234a', |
| 96 | + ] |
| 97 | + ]; |
| 98 | + |
| 99 | + $this->blockPrice->addData($testValue); |
| 100 | + $this->assertEquals(['from' => 1234], $this->blockPrice->getCondition()); |
| 101 | + } |
| 102 | +} |
0 commit comments