Skip to content

Commit e151888

Browse files
committed
MC-37100: Create automated test for "Create customer, when admin interface locale is en_GB"
1 parent 3c3c8ed commit e151888

File tree

2 files changed

+125
-3
lines changed
  • dev/tests/integration/testsuite/Magento

2 files changed

+125
-3
lines changed

dev/tests/integration/testsuite/Magento/Customer/Controller/Adminhtml/Index/SaveTest.php

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010
use Magento\Backend\Model\Session;
1111
use Magento\Customer\Api\CustomerNameGenerationInterface;
1212
use Magento\Customer\Api\CustomerRepositoryInterface;
13+
use Magento\Customer\Api\Data\CustomerInterface;
1314
use Magento\Customer\Model\Data\Customer as CustomerData;
1415
use Magento\Customer\Model\EmailNotification;
1516
use Magento\Framework\App\Area;
1617
use Magento\Framework\App\Request\Http as HttpRequest;
18+
use Magento\Framework\Locale\ResolverInterface;
1719
use Magento\Framework\Mail\Template\TransportBuilder;
1820
use Magento\Framework\Mail\TransportInterface;
1921
use Magento\Framework\Message\MessageInterface;
@@ -54,6 +56,12 @@ class SaveTest extends AbstractBackendController
5456
/** @var StoreManagerInterface */
5557
private $storeManager;
5658

59+
/** @var ResolverInterface */
60+
private $localeResolver;
61+
62+
/** @var CustomerInterface */
63+
private $customer;
64+
5765
/**
5866
* @inheritdoc
5967
*/
@@ -65,6 +73,19 @@ protected function setUp(): void
6573
$this->subscriberFactory = $this->_objectManager->get(SubscriberFactory::class);
6674
$this->session = $this->_objectManager->get(Session::class);
6775
$this->storeManager = $this->_objectManager->get(StoreManagerInterface::class);
76+
$this->localeResolver = $this->_objectManager->get(ResolverInterface::class);
77+
}
78+
79+
/**
80+
* @inheritdoc
81+
*/
82+
protected function tearDown(): void
83+
{
84+
if ($this->customer instanceof CustomerInterface) {
85+
$this->customerRepository->delete($this->customer);
86+
}
87+
88+
parent::tearDown();
6889
}
6990

7091
/**
@@ -418,6 +439,43 @@ public function testCreateSameEmailFormatDateError(): void
418439
$this->assertRedirect($this->stringContains($this->baseControllerUrl . 'new/key/'));
419440
}
420441

442+
/**
443+
* @return void
444+
*/
445+
public function testCreateCustomerByAdminWithLocaleGB(): void
446+
{
447+
$this->localeResolver->setLocale('en_GB');
448+
$postData = array_replace_recursive(
449+
$this->getDefaultCustomerData(),
450+
[
451+
'customer' => [
452+
CustomerData::DOB => '24/10/1990',
453+
],
454+
]
455+
);
456+
$expectedData = array_replace_recursive(
457+
$postData,
458+
[
459+
'customer' => [
460+
CustomerData::DOB => '1990-10-24',
461+
CustomerData::GENDER => '0',
462+
],
463+
]
464+
);
465+
unset($expectedData['customer']['sendemail_store_id']);
466+
$this->dispatchCustomerSave($postData);
467+
$this->assertSessionMessages(
468+
$this->equalTo([(string)__('You saved the customer.')]),
469+
MessageInterface::TYPE_SUCCESS
470+
);
471+
$this->assertRedirect($this->stringContains($this->baseControllerUrl . 'index/key/'));
472+
$this->assertCustomerData(
473+
$postData['customer'][CustomerData::EMAIL],
474+
(int)$postData['customer'][CustomerData::WEBSITE_ID],
475+
$expectedData
476+
);
477+
}
478+
421479
/**
422480
* Default values for customer creation
423481
*
@@ -496,9 +554,8 @@ private function assertCustomerData(
496554
int $customerWebsiteId,
497555
array $expectedData
498556
): void {
499-
/** @var CustomerData $customerData */
500-
$customerData = $this->customerRepository->get($customerEmail, $customerWebsiteId);
501-
$actualCustomerArray = $customerData->__toArray();
557+
$this->customer = $this->customerRepository->get($customerEmail, $customerWebsiteId);
558+
$actualCustomerArray = $this->customer->__toArray();
502559
foreach ($expectedData['customer'] as $key => $expectedValue) {
503560
$this->assertEquals(
504561
$expectedValue,
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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\Ui\Component\Form\Element\DataType;
9+
10+
use Magento\Framework\Locale\ResolverInterface;
11+
use Magento\Framework\ObjectManagerInterface;
12+
use Magento\TestFramework\Helper\Bootstrap;
13+
use PHPUnit\Framework\TestCase;
14+
15+
/**
16+
* Test for date component.
17+
*/
18+
class DateTest extends TestCase
19+
{
20+
/** @var ObjectManagerInterface */
21+
private $objectManager;
22+
23+
/** @var DateFactory */
24+
private $dateFactory;
25+
26+
/** @var ResolverInterface */
27+
private $localeResolver;
28+
29+
/**
30+
* @inheritDoc
31+
*/
32+
protected function setUp(): void
33+
{
34+
parent::setUp();
35+
36+
$this->objectManager = Bootstrap::getObjectManager();
37+
$this->dateFactory = $this->objectManager->get(DateFactory::class);
38+
$this->localeResolver = $this->objectManager->get(ResolverInterface::class);
39+
}
40+
41+
/**
42+
* @dataProvider localeDataProvider
43+
*
44+
* @param string $locale
45+
* @param string $dateFormat
46+
* @return void
47+
*/
48+
public function testDateFormat(string $locale, string $dateFormat): void
49+
{
50+
$this->localeResolver->setLocale($locale);
51+
$date = $this->dateFactory->create();
52+
$date->prepare();
53+
$this->assertEquals($dateFormat, $date->getData('config')['options']['dateFormat']);
54+
}
55+
56+
/**
57+
* @return array
58+
*/
59+
public function localeDataProvider(): array
60+
{
61+
return [
62+
['en_GB', 'dd/MM/y'], ['en_US', 'M/d/yy'],
63+
];
64+
}
65+
}

0 commit comments

Comments
 (0)