-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENGCOM-7825: Prefix dropdown in checkout doesn't select empty value b…
…y default if required #28238 - Merge Pull Request #28238 from engcom-Charlie/magento2:18823 - Merged commits: 1. 7aa9a9c 2. daecbb4 3. f208eae 4. e5be53f 5. 0213d58 6. e322c58
- Loading branch information
Showing
2 changed files
with
169 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
164 changes: 164 additions & 0 deletions
164
dev/tests/integration/testsuite/Magento/Customer/Model/OptionsTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Magento\Customer\Model; | ||
|
||
use Magento\Config\Model\Config\Source\Nooptreq; | ||
use Magento\Customer\Helper\Address; | ||
use Magento\Framework\App\Config\MutableScopeConfigInterface; | ||
use Magento\Framework\ObjectManagerInterface; | ||
use Magento\Store\Model\ScopeInterface; | ||
use Magento\TestFramework\Helper\Bootstrap; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* Test for \Magento\Customer\Model\Options. | ||
* @magentoDbIsolation enabled | ||
*/ | ||
class OptionsTest extends TestCase | ||
{ | ||
private const XML_PATH_SUFFIX_SHOW = 'customer/address/suffix_show'; | ||
private const XML_PATH_SUFFIX_OPTIONS = 'customer/address/suffix_options'; | ||
private const XML_PATH_PREFIX_SHOW = 'customer/address/prefix_show'; | ||
private const XML_PATH_PREFIX_OPTIONS = 'customer/address/prefix_options'; | ||
|
||
/** | ||
* @var Options | ||
*/ | ||
private $model; | ||
|
||
/** | ||
* @var ObjectManagerInterface | ||
*/ | ||
private $objectManager; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function setUp(): void | ||
{ | ||
$this->objectManager = Bootstrap::getObjectManager(); | ||
$this->model = $this->objectManager->create(Options::class); | ||
} | ||
|
||
/** | ||
* Test suffix and prefix options | ||
* | ||
* @dataProvider optionsDataProvider | ||
* | ||
* @param string $optionType | ||
* @param array $showOptionConfig | ||
* @param array $optionValuesConfig | ||
* @param array $expectedOptions | ||
* @return void | ||
*/ | ||
public function testOptions( | ||
string $optionType, | ||
array $showOptionConfig, | ||
array $optionValuesConfig, | ||
array $expectedOptions | ||
): void { | ||
$this->setConfig($showOptionConfig); | ||
$this->setConfig($optionValuesConfig); | ||
|
||
/** @var array $options */ | ||
$options = $optionType === 'prefix' | ||
? $this->model->getNamePrefixOptions() | ||
: $this->model->getNameSuffixOptions(); | ||
|
||
$this->assertEquals($expectedOptions, $options); | ||
} | ||
|
||
/** | ||
* Set config param | ||
* | ||
* @param array $data | ||
* @param string|null $scopeType | ||
* @param string|null $scopeCode | ||
* @return void | ||
*/ | ||
private function setConfig( | ||
array $data, | ||
?string $scopeType = ScopeInterface::SCOPE_STORE, | ||
?string $scopeCode = 'default' | ||
): void { | ||
$path = array_key_first($data); | ||
$this->objectManager->get(MutableScopeConfigInterface::class) | ||
->setValue($path, $data[$path], $scopeType, $scopeCode); | ||
} | ||
|
||
/** | ||
* DataProvider for testOptions() | ||
* | ||
* @return array | ||
*/ | ||
public function optionsDataProvider(): array | ||
{ | ||
$optionPrefixName = 'prefix'; | ||
$optionSuffixName = 'suffix'; | ||
$optionValues = 'v1;v2'; | ||
$expectedValues = ['v1', 'v2']; | ||
$optionValuesWithBlank = ';v1;v2'; | ||
$expectedValuesWithBlank = [' ', 'v1', 'v2']; | ||
$optionValuesWithTwoBlank = ';v1;v2;'; | ||
$expectedValuesTwoBlank = [' ', 'v1', 'v2', ' ']; | ||
|
||
return [ | ||
'prefix_required_with_blank_option' => [ | ||
$optionPrefixName, | ||
[self::XML_PATH_PREFIX_SHOW => Nooptreq::VALUE_REQUIRED], | ||
[self::XML_PATH_PREFIX_OPTIONS => $optionValuesWithBlank], | ||
$expectedValuesWithBlank, | ||
], | ||
'prefix_required' => [ | ||
$optionPrefixName, | ||
[self::XML_PATH_PREFIX_SHOW => Nooptreq::VALUE_REQUIRED], | ||
[self::XML_PATH_PREFIX_OPTIONS => $optionValues], | ||
$expectedValues, | ||
], | ||
'prefix_required_with_two_blank_option' => [ | ||
$optionPrefixName, | ||
[self::XML_PATH_PREFIX_SHOW => Nooptreq::VALUE_REQUIRED], | ||
[self::XML_PATH_PREFIX_OPTIONS => $optionValuesWithTwoBlank], | ||
$expectedValuesTwoBlank, | ||
], | ||
'prefix_optional' => [ | ||
$optionPrefixName, | ||
[self::XML_PATH_PREFIX_SHOW => Nooptreq::VALUE_OPTIONAL], | ||
[self::XML_PATH_PREFIX_OPTIONS => $optionValues], | ||
$expectedValuesWithBlank, | ||
], | ||
'suffix_optional' => [ | ||
$optionSuffixName, | ||
[self::XML_PATH_SUFFIX_SHOW => Nooptreq::VALUE_OPTIONAL], | ||
[self::XML_PATH_SUFFIX_OPTIONS => $optionValues], | ||
$expectedValuesWithBlank, | ||
], | ||
'suffix_optional_with_blank_option' => [ | ||
$optionSuffixName, | ||
[self::XML_PATH_SUFFIX_SHOW => Nooptreq::VALUE_OPTIONAL], | ||
[self::XML_PATH_SUFFIX_OPTIONS => $optionValuesWithBlank], | ||
$expectedValuesWithBlank, | ||
], | ||
'suffix_required_with_blank_option' => [ | ||
$optionSuffixName, | ||
[self::XML_PATH_SUFFIX_SHOW => Nooptreq::VALUE_OPTIONAL], | ||
[self::XML_PATH_SUFFIX_OPTIONS => $optionValuesWithBlank], | ||
$expectedValuesWithBlank, | ||
], | ||
]; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function tearDown(): void | ||
{ | ||
$this->objectManager->removeSharedInstance(Address::class); | ||
} | ||
} |