Skip to content

Commit 1f6fcc1

Browse files
committed
AC-15415 : Potential performance issue on loading shipping methods
1 parent 3f0f689 commit 1f6fcc1

File tree

1 file changed

+82
-1
lines changed

1 file changed

+82
-1
lines changed

app/code/Magento/Shipping/Test/Unit/Model/Config/Source/AllmethodsTest.php

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public function testToOptionArrayGetActiveCarriers(array $expectedArray): void
9696
->willReturn($expectedArray['allowedMethods']);
9797
$this->assertEquals([$expectedArray['expected_result']], $this->allmethods->toOptionArray(true));
9898
}
99-
99+
100100
/**
101101
* Returns providers data for test
102102
*
@@ -122,4 +122,85 @@ public static function getCarriersMethodsProvider(): array
122122
]
123123
];
124124
}
125+
126+
/**
127+
* Ensures carriers with no allowed methods are skipped entirely
128+
*
129+
* @return void
130+
*/
131+
public function testSkipsCarrierWhenNoAllowedMethods(): void
132+
{
133+
$this->shippingConfig->expects($this->once())
134+
->method('getAllCarriers')
135+
->willReturn(['flatrate' => $this->carriersMock]);
136+
137+
$this->carriersMock->expects($this->once())
138+
->method('getAllowedMethods')
139+
->willReturn(null);
140+
141+
$result = $this->allmethods->toOptionArray(false);
142+
143+
$this->assertSame([
144+
['value' => '', 'label' => ''],
145+
], $result);
146+
}
147+
148+
/**
149+
* Ensures a proper entry is added for a valid method
150+
*
151+
* @return void
152+
*/
153+
public function testAddsMethodEntryForValidMethod(): void
154+
{
155+
$this->shippingConfig->expects($this->once())
156+
->method('getActiveCarriers')
157+
->willReturn(['flatrate' => $this->carriersMock]);
158+
159+
$this->carriersMock->expects($this->once())
160+
->method('getAllowedMethods')
161+
->willReturn(['fixed' => 'Fixed Rate']);
162+
163+
$this->scopeConfig->expects($this->once())
164+
->method('getValue')
165+
->with('carriers/flatrate/title', \Magento\Store\Model\ScopeInterface::SCOPE_STORE)
166+
->willReturn('Flat Rate');
167+
168+
$result = $this->allmethods->toOptionArray(true);
169+
170+
$this->assertArrayHasKey('flatrate', $result);
171+
$this->assertSame('Flat Rate', $result['flatrate']['label']);
172+
$this->assertSame([
173+
[
174+
'value' => 'flatrate_fixed',
175+
'label' => '[flatrate] Fixed Rate',
176+
]
177+
], $result['flatrate']['value']);
178+
}
179+
180+
/**
181+
* Ensures null/empty method codes are not added
182+
*
183+
* @return void
184+
*/
185+
public function testSkipsNullAndEmptyMethodCodes(): void
186+
{
187+
$this->shippingConfig->expects($this->once())
188+
->method('getAllCarriers')
189+
->willReturn(['flatrate' => $this->carriersMock]);
190+
191+
$this->carriersMock->expects($this->once())
192+
->method('getAllowedMethods')
193+
->willReturn([null => 'Null Title', '' => 'Empty Title']);
194+
195+
$this->scopeConfig->expects($this->once())
196+
->method('getValue')
197+
->with('carriers/flatrate/title', \Magento\Store\Model\ScopeInterface::SCOPE_STORE)
198+
->willReturn('Flat Rate');
199+
200+
$result = $this->allmethods->toOptionArray(false);
201+
202+
$this->assertArrayHasKey('flatrate', $result);
203+
$this->assertSame('Flat Rate', $result['flatrate']['label']);
204+
$this->assertSame([], $result['flatrate']['value']);
205+
}
125206
}

0 commit comments

Comments
 (0)