Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CarrierTest.php
Go to the documentation of this file.
1 <?php
7 
11 class CarrierTest extends \PHPUnit\Framework\TestCase
12 {
18  protected $helper;
19 
23  protected $scopeConfig;
24 
25  protected function setUp()
26  {
27  $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
28  $className = \Magento\Shipping\Helper\Carrier::class;
29  $arguments = $objectManagerHelper->getConstructArguments($className);
31  $context = $arguments['context'];
32  $this->scopeConfig = $context->getScopeConfig();
33  $this->helper = $objectManagerHelper->getObject($className, $arguments);
34  }
35 
41  public function testGetOnlineCarrierCodes($result, $carriers)
42  {
43  $this->scopeConfig->expects(
44  $this->once()
45  )->method(
46  'getValue'
47  )->with(
48  'carriers',
49  \Magento\Store\Model\ScopeInterface::SCOPE_STORE
50  )->will(
51  $this->returnValue($carriers)
52  );
53  $this->assertEquals($result, $this->helper->getOnlineCarrierCodes());
54  }
55 
62  {
63  return [
64  [[], ['carrier1' => []]],
65  [[], ['carrier1' => ['is_online' => 0]]],
66  [
67  ['carrier1'],
68  ['carrier1' => ['is_online' => 1], 'carrier2' => ['is_online' => 0]]
69  ]
70  ];
71  }
72 
73  public function testGetCarrierConfigValue()
74  {
75  $carrierCode = 'carrier1';
76  $configPath = 'title';
77  $configValue = 'some title';
78  $this->scopeConfig->expects(
79  $this->once()
80  )->method(
81  'getValue'
82  )->with(
83  sprintf('carriers/%s/%s', $carrierCode, $configPath),
84  \Magento\Store\Model\ScopeInterface::SCOPE_STORE
85  )->will(
86  $this->returnValue($configValue)
87  );
88  $this->assertEquals($configValue, $this->helper->getCarrierConfigValue($carrierCode, $configPath));
89  }
90 
91  public function testIsCountryInEU()
92  {
93  $this->scopeConfig->expects(
94  $this->exactly(2)
95  )->method(
96  'getValue'
97  )->with(
98  'general/country/eu_countries',
99  \Magento\Store\Model\ScopeInterface::SCOPE_STORE
100  )->will(
101  $this->returnValue("GB")
102  );
103 
104  $this->assertEquals(true, $this->helper->isCountryInEU("GB"));
105  $this->assertEquals(false, $this->helper->isCountryInEU("US"));
106  }
107 }
$arguments
if($currentSelectedMethod==$_code) $className
Definition: form.phtml:31