Skip to content

Commit ec86f52

Browse files
Fedex Shipping Method Configuration Fix
1 parent 704f20d commit ec86f52

File tree

2 files changed

+53
-13
lines changed

2 files changed

+53
-13
lines changed

app/code/Magento/Fedex/Model/Config/Backend/FedexUrl.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ class FedexUrl extends Value
2828
* @var Url
2929
*/
3030
private Url $url;
31-
3231
/**
3332
* @param Context $context
3433
* @param Registry $registry
@@ -61,7 +60,8 @@ public function __construct(
6160
*/
6261
public function beforeSave(): AbstractModel
6362
{
64-
$isValid = $this->url->isValid($this->getValue());
63+
$isValid = $this->url->isValid($this->getValue(), ['http', 'https']);
64+
6565
if ($isValid) {
6666
// phpcs:ignore Magento2.Functions.DiscouragedFunction
6767
$host = parse_url((string)$this->getValue(), \PHP_URL_HOST);

app/code/Magento/Fedex/Test/Unit/Model/Config/Backend/FedexUrlTest.php

Lines changed: 51 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,18 @@
88

99
namespace Magento\Fedex\Test\Unit\Model\Config\Backend;
1010

11+
use Magento\Fedex\Model\Config\Backend\FedexUrl;
12+
use Magento\Framework\App\Cache\TypeListInterface;
13+
use Magento\Framework\App\Config\ScopeConfigInterface;
14+
use Magento\Framework\Data\Collection\AbstractDb;
15+
use Magento\Framework\Event\ManagerInterface;
1116
use Magento\Framework\Exception\ValidatorException;
17+
use Magento\Framework\Model\Context;
18+
use Magento\Framework\Registry;
1219
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
13-
use Magento\Fedex\Model\Config\Backend\FedexUrl;
20+
use Magento\Framework\Validator\Url;
21+
use Magento\Rule\Model\ResourceModel\AbstractResource;
22+
use PHPUnit\Framework\MockObject\MockObject;
1423
use PHPUnit\Framework\TestCase;
1524

1625
/**
@@ -22,39 +31,70 @@ class FedexUrlTest extends TestCase
2231
/**
2332
* @var FedexUrl
2433
*/
25-
private $config;
34+
private $urlConfig;
2635

2736
/**
28-
* @return void
37+
* @var Url
2938
*/
39+
private $url;
40+
41+
/**
42+
* @var Context|MockObject
43+
*/
44+
private $contextMock;
45+
3046
protected function setUp(): void
3147
{
3248
$objectManager = new ObjectManager($this);
33-
/** @var FedexUrl $fedexUrl */
34-
$this->config = $objectManager->getObject(FedexUrl::class);
49+
$this->contextMock = $this->createMock(Context::class);
50+
$registry = $this->createMock(Registry::class);
51+
$config = $this->createMock(ScopeConfigInterface::class);
52+
$cacheTypeList = $this->createMock(TypeListInterface::class);
53+
$this->url = $this->createMock(Url::class);
54+
$resource = $this->createMock(AbstractResource::class);
55+
$resourceCollection = $this->createMock(AbstractDb::class);
56+
$eventManagerMock = $this->getMockForAbstractClass(ManagerInterface::class);
57+
$eventManagerMock->expects($this->any())->method('dispatch');
58+
$this->contextMock->expects($this->any())->method('getEventDispatcher')->willReturn($eventManagerMock);
59+
60+
$this->urlConfig = $objectManager->getObject(
61+
FedexUrl::class,
62+
[
63+
'url' => $this->url,
64+
'context' => $this->contextMock,
65+
'registry' => $registry,
66+
'config' => $config,
67+
'cacheTypeList' => $cacheTypeList,
68+
'resource' => $resource,
69+
'resourceCollection' => $resourceCollection,
70+
]
71+
);
3572
}
3673

3774
/**
3875
* @dataProvider validDataProvider
3976
* @param string|null $data The valid data
4077
* @throws ValidatorException
4178
*/
42-
public function testBeforeSave(string $data = null)
79+
public function testBeforeSave(string $data = null): void
4380
{
44-
$this->config->setValue($data);
45-
$this->config->beforeSave();
81+
$this->url->expects($this->any())->method('isValid')->willReturn(true);
82+
$this->urlConfig->setValue($data);
83+
$this->urlConfig->beforeSave();
84+
$this->assertTrue($this->url->isValid($data));
4685
}
4786

4887
/**
4988
* @dataProvider invalidDataProvider
5089
* @param string $data The invalid data
5190
*/
52-
public function testBeforeSaveErrors(string $data)
91+
public function testBeforeSaveErrors(string $data): void
5392
{
93+
$this->url->expects($this->any())->method('isValid')->willReturn(true);
5494
$this->expectException('Magento\Framework\Exception\ValidatorException');
5595
$this->expectExceptionMessage('Fedex API endpoint URL\'s must use fedex.com');
56-
$this->config->setValue($data);
57-
$this->config->beforeSave();
96+
$this->urlConfig->setValue($data);
97+
$this->urlConfig->beforeSave();
5898
}
5999

60100
/**

0 commit comments

Comments
 (0)