Skip to content

Commit b11dd0b

Browse files
committed
Merge remote-tracking branch 'origin/AC-15074' into spartans_pr_29082025
2 parents 1e33c35 + e343a85 commit b11dd0b

File tree

3 files changed

+120
-4
lines changed

3 files changed

+120
-4
lines changed

app/code/Magento/Sales/Model/Order.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4703,12 +4703,12 @@ private function isVisibleCustomerMiddlename(): bool
47034703
*/
47044704
private function isVisibleCustomerPrefix(): bool
47054705
{
4706-
$prefixShowValue = $this->scopeConfig->getValue(
4706+
$value = $this->scopeConfig->getValue(
47074707
'customer/address/prefix_show',
47084708
ScopeInterface::SCOPE_STORE
47094709
);
47104710

4711-
return $prefixShowValue !== Nooptreq::VALUE_NO;
4711+
return in_array($value, [Nooptreq::VALUE_OPTIONAL, Nooptreq::VALUE_REQUIRED], true);
47124712
}
47134713

47144714
/**
@@ -4718,12 +4718,12 @@ private function isVisibleCustomerPrefix(): bool
47184718
*/
47194719
private function isVisibleCustomerSuffix(): bool
47204720
{
4721-
$prefixShowValue = $this->scopeConfig->getValue(
4721+
$value = $this->scopeConfig->getValue(
47224722
'customer/address/suffix_show',
47234723
ScopeInterface::SCOPE_STORE
47244724
);
47254725

4726-
return $prefixShowValue !== Nooptreq::VALUE_NO;
4726+
return in_array($value, [Nooptreq::VALUE_OPTIONAL, Nooptreq::VALUE_REQUIRED], true);
47274727
}
47284728

47294729
//@codeCoverageIgnoreEnd

app/code/Magento/Sales/Test/Unit/Model/OrderTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
use Magento\Sales\Model\ResourceModel\Order\Status\History\CollectionFactory as HistoryCollectionFactory;
4141
use PHPUnit\Framework\MockObject\MockObject;
4242
use PHPUnit\Framework\TestCase;
43+
use Magento\Config\Model\Config\Source\Nooptreq;
4344

4445
/**
4546
* Test class for \Magento\Sales\Model\Order
@@ -439,6 +440,14 @@ public function testGetCustomerName(array $expectedData)
439440
$this->order->setCustomerMiddlename($expectedData['middle_name']);
440441
$this->order->setCustomerSuffix($expectedData['customer_suffix']);
441442
$this->order->setCustomerPrefix($expectedData['customer_prefix']);
443+
// Ensure prefix/suffix are visible to match expected strings.
444+
$this->scopeConfigMock->method('getValue')->willReturnCallback(function ($path) {
445+
if ($path === 'customer/address/prefix_show' || $path === 'customer/address/suffix_show') {
446+
return Nooptreq::VALUE_REQUIRED;
447+
}
448+
return null;
449+
});
450+
442451
$this->scopeConfigMock->expects($this->exactly($expectedData['invocation']))
443452
->method('isSetFlag')
444453
->willReturn(true);
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Sales\Model;
9+
10+
use Magento\Config\Model\Config\Source\Nooptreq;
11+
use Magento\Framework\App\Config\MutableScopeConfigInterface;
12+
use Magento\Framework\ObjectManagerInterface;
13+
use Magento\Store\Model\ScopeInterface;
14+
use Magento\TestFramework\Helper\Bootstrap;
15+
use PHPUnit\Framework\TestCase;
16+
17+
/**
18+
* Tests visibility of customer prefix/suffix via Order::getCustomerName(),
19+
* covering null (unset), empty string, optional and required config values.
20+
*
21+
* @magentoDbIsolation enabled
22+
*/
23+
class OrderPrefixSuffixVisibilityTest extends TestCase
24+
{
25+
private const XML_PATH_PREFIX_SHOW = 'customer/address/prefix_show';
26+
private const XML_PATH_SUFFIX_SHOW = 'customer/address/suffix_show';
27+
28+
/**
29+
* @var ObjectManagerInterface
30+
*/
31+
private ObjectManagerInterface $om;
32+
33+
protected function setUp(): void
34+
{
35+
$this->om = Bootstrap::getObjectManager();
36+
}
37+
38+
/**
39+
* @dataProvider visibilityCases
40+
*/
41+
public function testPrefixVisibility(?string $value, bool $setValue, bool $expectedVisible): void
42+
{
43+
// Ensure suffix never interferes in this test
44+
$this->setConfig(self::XML_PATH_SUFFIX_SHOW, Nooptreq::VALUE_NO);
45+
46+
if ($setValue) {
47+
$this->setConfig(self::XML_PATH_PREFIX_SHOW, $value);
48+
}
49+
// If not set, path remains unset (null), simulating the reported case.
50+
51+
$order = $this->makeOrder('Dr', 'John', 'Doe', 'Jr'); // suffix ignored here
52+
$expected = $expectedVisible ? 'Dr John Doe' : 'John Doe';
53+
54+
$this->assertSame($expected, $order->getCustomerName());
55+
}
56+
57+
/**
58+
* @dataProvider visibilityCases
59+
*/
60+
public function testSuffixVisibility(?string $value, bool $setValue, bool $expectedVisible): void
61+
{
62+
// Ensure prefix never interferes in this test
63+
$this->setConfig(self::XML_PATH_PREFIX_SHOW, Nooptreq::VALUE_NO);
64+
65+
if ($setValue) {
66+
$this->setConfig(self::XML_PATH_SUFFIX_SHOW, $value);
67+
}
68+
// If not set, path remains unset (null), simulating the reported case.
69+
70+
$order = $this->makeOrder('Dr', 'John', 'Doe', 'Jr'); // prefix ignored here
71+
$expected = $expectedVisible ? 'John Doe Jr' : 'John Doe';
72+
73+
$this->assertSame($expected, $order->getCustomerName());
74+
}
75+
76+
public static function visibilityCases(): array
77+
{
78+
return [
79+
// value, setValue, expectedVisible
80+
'unset_null_defaults_to_no' => [null, false, false], // path not set → null
81+
'explicit_empty_string_no' => [Nooptreq::VALUE_NO, true, false], // ''
82+
'optional_visible' => [Nooptreq::VALUE_OPTIONAL, true, true], // 'opt'
83+
'required_visible' => [Nooptreq::VALUE_REQUIRED, true, true], // 'req'
84+
];
85+
}
86+
87+
private function makeOrder(string $prefix, string $first, string $last, string $suffix): Order
88+
{
89+
/** @var Order $order */
90+
$order = $this->om->create(Order::class);
91+
$order->setCustomerPrefix($prefix);
92+
$order->setCustomerFirstname($first);
93+
$order->setCustomerLastname($last);
94+
$order->setCustomerSuffix($suffix);
95+
// Middlename left null to avoid affecting formatting.
96+
return $order;
97+
}
98+
99+
private function setConfig(
100+
string $path,
101+
?string $value,
102+
string $scope = ScopeInterface::SCOPE_STORE,
103+
string $scopeCode = 'default'
104+
): void {
105+
$this->om->get(MutableScopeConfigInterface::class)->setValue($path, $value, $scope, $scopeCode);
106+
}
107+
}

0 commit comments

Comments
 (0)