CarrierTest.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Shipping\Test\Unit\Helper;
  7. /**
  8. * Carrier helper test
  9. */
  10. class CarrierTest extends \PHPUnit\Framework\TestCase
  11. {
  12. /**
  13. * Shipping Carrier helper
  14. *
  15. * @var \Magento\Shipping\Helper\Carrier
  16. */
  17. protected $helper;
  18. /**
  19. * @var \PHPUnit_Framework_MockObject_MockObject
  20. */
  21. protected $scopeConfig;
  22. protected function setUp()
  23. {
  24. $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  25. $className = \Magento\Shipping\Helper\Carrier::class;
  26. $arguments = $objectManagerHelper->getConstructArguments($className);
  27. /** @var \Magento\Framework\App\Helper\Context $context */
  28. $context = $arguments['context'];
  29. $this->scopeConfig = $context->getScopeConfig();
  30. $this->helper = $objectManagerHelper->getObject($className, $arguments);
  31. }
  32. /**
  33. * @param array $result
  34. * @param array $carriers
  35. * @dataProvider getOnlineCarrierCodesDataProvider
  36. */
  37. public function testGetOnlineCarrierCodes($result, $carriers)
  38. {
  39. $this->scopeConfig->expects(
  40. $this->once()
  41. )->method(
  42. 'getValue'
  43. )->with(
  44. 'carriers',
  45. \Magento\Store\Model\ScopeInterface::SCOPE_STORE
  46. )->will(
  47. $this->returnValue($carriers)
  48. );
  49. $this->assertEquals($result, $this->helper->getOnlineCarrierCodes());
  50. }
  51. /**
  52. * Data provider
  53. *
  54. * @return array
  55. */
  56. public function getOnlineCarrierCodesDataProvider()
  57. {
  58. return [
  59. [[], ['carrier1' => []]],
  60. [[], ['carrier1' => ['is_online' => 0]]],
  61. [
  62. ['carrier1'],
  63. ['carrier1' => ['is_online' => 1], 'carrier2' => ['is_online' => 0]]
  64. ]
  65. ];
  66. }
  67. public function testGetCarrierConfigValue()
  68. {
  69. $carrierCode = 'carrier1';
  70. $configPath = 'title';
  71. $configValue = 'some title';
  72. $this->scopeConfig->expects(
  73. $this->once()
  74. )->method(
  75. 'getValue'
  76. )->with(
  77. sprintf('carriers/%s/%s', $carrierCode, $configPath),
  78. \Magento\Store\Model\ScopeInterface::SCOPE_STORE
  79. )->will(
  80. $this->returnValue($configValue)
  81. );
  82. $this->assertEquals($configValue, $this->helper->getCarrierConfigValue($carrierCode, $configPath));
  83. }
  84. public function testIsCountryInEU()
  85. {
  86. $this->scopeConfig->expects(
  87. $this->exactly(2)
  88. )->method(
  89. 'getValue'
  90. )->with(
  91. 'general/country/eu_countries',
  92. \Magento\Store\Model\ScopeInterface::SCOPE_STORE
  93. )->will(
  94. $this->returnValue("GB")
  95. );
  96. $this->assertEquals(true, $this->helper->isCountryInEU("GB"));
  97. $this->assertEquals(false, $this->helper->isCountryInEU("US"));
  98. }
  99. }