Skip to content

Commit 08bbdbf

Browse files
committed
MC-19080: Incorrect behavior after shipping methods disabled
1 parent db21eb4 commit 08bbdbf

File tree

3 files changed

+120
-75
lines changed

3 files changed

+120
-75
lines changed

dev/tests/integration/testsuite/Magento/OfflineShipping/Model/CollectRatesTest.php

Lines changed: 5 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,12 @@
77

88
namespace Magento\OfflineShipping\Model;
99

10-
use Magento\Framework\DataObject;
11-
use Magento\Framework\ObjectManagerInterface;
12-
use Magento\Quote\Model\Quote\Address\RateResult\Error;
13-
use Magento\Quote\Model\Quote\Address\RateResult\Method;
14-
use Magento\Shipping\Model\Rate\Result;
15-
use Magento\Shipping\Model\Shipping;
16-
use Magento\TestFramework\Helper\Bootstrap;
17-
1810
/**
1911
* Integration tests for offline shipping carriers.
2012
* @magentoAppIsolation enabled
2113
*/
22-
class CollectRatesTest extends \PHPUnit\Framework\TestCase
14+
class CollectRatesTest extends \Magento\Shipping\Model\CollectRatesTest
2315
{
24-
/**
25-
* @var ObjectManagerInterface
26-
*/
27-
private $objectManager;
28-
29-
/**
30-
* @var Shipping
31-
*/
32-
protected $shipping;
33-
3416
/**
3517
* @var string
3618
*/
@@ -41,28 +23,16 @@ class CollectRatesTest extends \PHPUnit\Framework\TestCase
4123
*/
4224
protected $errorMessage = 'This shipping method is not available. To use this shipping method, please contact us.';
4325

44-
/**
45-
* @inheritdoc
46-
*/
47-
protected function setUp()
48-
{
49-
$this->objectManager = Bootstrap::getObjectManager();
50-
$this->shipping = $this->objectManager->get(Shipping::class);
51-
}
52-
5326
/**
5427
* @magentoConfigFixture default_store carriers/flatrate/active 1
5528
* @magentoConfigFixture default_store carriers/flatrate/sallowspecific 1
5629
* @magentoConfigFixture default_store carriers/flatrate/specificcountry UK
5730
* @magentoConfigFixture default_store carriers/flatrate/showmethod 1
5831
*/
32+
// phpcs:ignore Generic.CodeAnalysis.UselessOverridingMethod
5933
public function testCollectRatesWhenShippingCarrierIsAvailableAndNotApplicable()
6034
{
61-
$result = $this->shipping->collectRatesByAddress($this->getAddress(), $this->carrier);
62-
$rate = $this->getRate($result->getResult());
63-
64-
static::assertEquals($this->carrier, $rate->getData('carrier'));
65-
static::assertEquals($this->errorMessage, $rate->getData('error_message'));
35+
parent::testCollectRatesWhenShippingCarrierIsAvailableAndNotApplicable();
6636
}
6737

6838
/**
@@ -71,48 +41,9 @@ public function testCollectRatesWhenShippingCarrierIsAvailableAndNotApplicable()
7141
* @magentoConfigFixture default_store carriers/flatrate/specificcountry UK
7242
* @magentoConfigFixture default_store carriers/flatrate/showmethod 1
7343
*/
44+
// phpcs:ignore Generic.CodeAnalysis.UselessOverridingMethod
7445
public function testCollectRatesWhenShippingCarrierIsNotAvailableAndNotApplicable()
7546
{
76-
$result = $this->shipping->collectRatesByAddress($this->getAddress(), $this->carrier);
77-
$rate = $this->getRate($result->getResult());
78-
79-
static::assertNull($rate);
80-
}
81-
82-
/**
83-
* @return DataObject
84-
*/
85-
private function getAddress(): DataObject
86-
{
87-
$address = $this->objectManager->create(
88-
DataObject::class,
89-
[
90-
'data' => [
91-
'region_id' => 'CA',
92-
'postcode' => '11111',
93-
'lastname' => 'John',
94-
'firstname' => 'Doe',
95-
'street' => 'Some street',
96-
'city' => 'Los Angeles',
97-
'email' => 'john.doe@example.com',
98-
'telephone' => '11111111',
99-
'country_id' => 'US',
100-
'item_qty' => 1,
101-
],
102-
]
103-
);
104-
105-
return $address;
106-
}
107-
108-
/**
109-
* @param Result $result
110-
* @return Method|Error
111-
*/
112-
private function getRate(Result $result)
113-
{
114-
$rates = $result->getAllRates();
115-
116-
return array_pop($rates);
47+
parent::testCollectRatesWhenShippingCarrierIsNotAvailableAndNotApplicable();
11748
}
11849
}
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
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\Shipping\Model;
9+
10+
use Magento\Framework\DataObject;
11+
use Magento\Framework\ObjectManagerInterface;
12+
use Magento\Quote\Model\Quote\Address\RateResult\Error;
13+
use Magento\Quote\Model\Quote\Address\RateResult\Method;
14+
use Magento\Shipping\Model\Rate\Result;
15+
use Magento\TestFramework\Helper\Bootstrap;
16+
17+
/**
18+
* Integration tests for shipping carriers.
19+
*/
20+
class CollectRatesTest extends \PHPUnit\Framework\TestCase
21+
{
22+
23+
/**
24+
* @var ObjectManagerInterface
25+
*/
26+
private $objectManager;
27+
28+
/**
29+
* @var Shipping
30+
*/
31+
protected $shipping;
32+
33+
/**
34+
* @var string
35+
*/
36+
protected $carrier = '';
37+
38+
/**
39+
* @var string
40+
*/
41+
protected $errorMessage = '';
42+
43+
/**
44+
* @inheritdoc
45+
*/
46+
protected function setUp()
47+
{
48+
if (empty($this->carrier) || empty($this->errorMessage)) {
49+
$this->markTestSkipped('Required fields are empty');
50+
}
51+
$this->objectManager = Bootstrap::getObjectManager();
52+
$this->shipping = $this->objectManager->get(Shipping::class);
53+
}
54+
55+
/**
56+
* @return void
57+
*/
58+
public function testCollectRatesWhenShippingCarrierIsAvailableAndNotApplicable()
59+
{
60+
$result = $this->shipping->collectRatesByAddress($this->getAddress(), $this->carrier);
61+
$rate = $this->getRate($result->getResult());
62+
63+
static::assertEquals($this->carrier, $rate->getData('carrier'));
64+
static::assertEquals($this->errorMessage, $rate->getData('error_message'));
65+
}
66+
67+
/**
68+
* @return void
69+
*/
70+
public function testCollectRatesWhenShippingCarrierIsNotAvailableAndNotApplicable()
71+
{
72+
$result = $this->shipping->collectRatesByAddress($this->getAddress(), $this->carrier);
73+
$rate = $this->getRate($result->getResult());
74+
75+
static::assertNull($rate);
76+
}
77+
78+
/**
79+
* @return DataObject
80+
*/
81+
private function getAddress(): DataObject
82+
{
83+
$address = $this->objectManager->create(
84+
DataObject::class,
85+
[
86+
'data' => [
87+
'region_id' => 'CA',
88+
'postcode' => '11111',
89+
'lastname' => 'John',
90+
'firstname' => 'Doe',
91+
'street' => 'Some street',
92+
'city' => 'Los Angeles',
93+
'email' => 'john.doe@example.com',
94+
'telephone' => '11111111',
95+
'country_id' => 'US',
96+
'item_qty' => 1,
97+
],
98+
]
99+
);
100+
101+
return $address;
102+
}
103+
104+
/**
105+
* @param Result $result
106+
* @return Method|Error
107+
*/
108+
private function getRate(Result $result)
109+
{
110+
$rates = $result->getAllRates();
111+
112+
return array_pop($rates);
113+
}
114+
}

dev/tests/integration/testsuite/Magento/Ups/Model/CollectRatesTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* Integration tests for online shipping carriers.
1212
* @magentoAppIsolation enabled
1313
*/
14-
class CollectRatesTest extends \Magento\OfflineShipping\Model\CollectRatesTest
14+
class CollectRatesTest extends \Magento\Shipping\Model\CollectRatesTest
1515
{
1616
/**
1717
* @var string

0 commit comments

Comments
 (0)