10
10
use Magento \Backend \Model \Session ;
11
11
use Magento \Customer \Api \CustomerNameGenerationInterface ;
12
12
use Magento \Customer \Api \CustomerRepositoryInterface ;
13
+ use Magento \Customer \Api \Data \CustomerInterface ;
13
14
use Magento \Customer \Model \Data \Customer as CustomerData ;
14
15
use Magento \Customer \Model \EmailNotification ;
15
16
use Magento \Framework \App \Area ;
16
17
use Magento \Framework \App \Request \Http as HttpRequest ;
18
+ use Magento \Framework \Locale \ResolverInterface ;
17
19
use Magento \Framework \Mail \Template \TransportBuilder ;
18
20
use Magento \Framework \Mail \TransportInterface ;
19
21
use Magento \Framework \Message \MessageInterface ;
@@ -54,6 +56,12 @@ class SaveTest extends AbstractBackendController
54
56
/** @var StoreManagerInterface */
55
57
private $ storeManager ;
56
58
59
+ /** @var ResolverInterface */
60
+ private $ localeResolver ;
61
+
62
+ /** @var CustomerInterface */
63
+ private $ customer ;
64
+
57
65
/**
58
66
* @inheritdoc
59
67
*/
@@ -65,6 +73,19 @@ protected function setUp(): void
65
73
$ this ->subscriberFactory = $ this ->_objectManager ->get (SubscriberFactory::class);
66
74
$ this ->session = $ this ->_objectManager ->get (Session::class);
67
75
$ 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 ();
68
89
}
69
90
70
91
/**
@@ -418,6 +439,43 @@ public function testCreateSameEmailFormatDateError(): void
418
439
$ this ->assertRedirect ($ this ->stringContains ($ this ->baseControllerUrl . 'new/key/ ' ));
419
440
}
420
441
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
+
421
479
/**
422
480
* Default values for customer creation
423
481
*
@@ -496,9 +554,8 @@ private function assertCustomerData(
496
554
int $ customerWebsiteId ,
497
555
array $ expectedData
498
556
): 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 ();
502
559
foreach ($ expectedData ['customer ' ] as $ key => $ expectedValue ) {
503
560
$ this ->assertEquals (
504
561
$ expectedValue ,
0 commit comments