Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ValidationMessageTest.php
Go to the documentation of this file.
1 <?php
7 
9 
10 class ValidationMessageTest extends \PHPUnit\Framework\TestCase
11 {
15  private $model;
16 
20  private $scopeConfigMock;
21 
25  private $storeManagerMock;
26 
31  private $currencyMock;
32 
36  private $priceHelperMock;
37 
38  protected function setUp()
39  {
40  $this->scopeConfigMock = $this->createMock(\Magento\Framework\App\Config\ScopeConfigInterface::class);
41  $this->storeManagerMock = $this->createMock(\Magento\Store\Model\StoreManagerInterface::class);
42  $this->currencyMock = $this->createMock(\Magento\Framework\Locale\CurrencyInterface::class);
43  $this->priceHelperMock = $this->createMock(\Magento\Framework\Pricing\Helper\Data::class);
44 
45  $this->model = new \Magento\Quote\Model\Quote\Validator\MinimumOrderAmount\ValidationMessage(
46  $this->scopeConfigMock,
47  $this->storeManagerMock,
48  $this->currencyMock,
49  $this->priceHelperMock
50  );
51  }
52 
53  public function testGetMessage()
54  {
55  $minimumAmount = 20;
56  $minimumAmountCurrency = '$20';
57  $this->scopeConfigMock->expects($this->at(0))
58  ->method('getValue')
59  ->with('sales/minimum_order/description', \Magento\Store\Model\ScopeInterface::SCOPE_STORE)
60  ->willReturn(null);
61 
62  $this->scopeConfigMock->expects($this->at(1))
63  ->method('getValue')
64  ->with('sales/minimum_order/amount', \Magento\Store\Model\ScopeInterface::SCOPE_STORE)
65  ->willReturn($minimumAmount);
66 
67  $this->priceHelperMock->expects($this->once())
68  ->method('currency')
69  ->with($minimumAmount, true, false)
70  ->will($this->returnValue($minimumAmountCurrency));
71 
72  $this->assertEquals(__('Minimum order amount is %1', $minimumAmountCurrency), $this->model->getMessage());
73  }
74  public function testGetConfigMessage()
75  {
76  $configMessage = 'config_message';
77  $this->scopeConfigMock->expects($this->once())
78  ->method('getValue')
79  ->with('sales/minimum_order/description', \Magento\Store\Model\ScopeInterface::SCOPE_STORE)
80  ->willReturn($configMessage);
81 
82  $message = $this->model->getMessage();
83 
84  $this->assertEquals(Phrase::class, get_class($message));
85  $this->assertEquals($configMessage, $message->__toString());
86  }
87 }
__()
Definition: __.php:13
$message