|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © 2013-2017 Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +namespace Magento\Customer\Controller\Account; |
| 7 | + |
| 8 | +use Magento\TestFramework\Helper\Bootstrap; |
| 9 | + |
| 10 | +/** |
| 11 | + * @magentoDataFixture Magento/Customer/_files/customer_date_attribute.php |
| 12 | + */ |
| 13 | +class CreatePostTest extends \Magento\TestFramework\TestCase\AbstractController |
| 14 | +{ |
| 15 | + const DOB = '1991-12-31'; |
| 16 | + const EXPECTED_DOB = '1991-12-31'; |
| 17 | + const EXPECTED_DATE = '2017-12-25 00:00:00'; |
| 18 | + |
| 19 | + /** |
| 20 | + * @var CreatePost |
| 21 | + */ |
| 22 | + private $model; |
| 23 | + |
| 24 | + protected function setUp() |
| 25 | + { |
| 26 | + $this->model = Bootstrap::getObjectManager()->create(CreatePost::class); |
| 27 | + } |
| 28 | + |
| 29 | + /** |
| 30 | + * @param string $dob |
| 31 | + * @param string $date |
| 32 | + * @param string $expectedDob |
| 33 | + * @param string $expectedDate |
| 34 | + * @param string $locale |
| 35 | + * @param string $email |
| 36 | + * @dataProvider getDate |
| 37 | + * @magentoDbIsolation enabled |
| 38 | + */ |
| 39 | + public function testCustomerSaveWithDateAttributes($dob, $date, $expectedDob, $expectedDate, $locale, $email) |
| 40 | + { |
| 41 | + $objectManager = Bootstrap::getObjectManager(); |
| 42 | + $objectManager->get('Magento\Framework\Locale\ResolverInterface')->setLocale($locale); |
| 43 | + |
| 44 | + /** @var $repository \Magento\Customer\Api\CustomerRepositoryInterface */ |
| 45 | + $repository = $objectManager->create('Magento\Customer\Api\CustomerRepositoryInterface'); |
| 46 | + $customer = $objectManager->create('Magento\Customer\Api\Data\CustomerInterface'); |
| 47 | + |
| 48 | + /** @var \Magento\Customer\Api\Data\CustomerInterface $customer */ |
| 49 | + $customer->setWebsiteId(1) |
| 50 | + ->setEmail($email) |
| 51 | + ->setGroupId(1) |
| 52 | + ->setStoreId(1) |
| 53 | + ->setFirstname('John') |
| 54 | + ->setLastname('Smith') |
| 55 | + ->setDefaultBilling(1) |
| 56 | + ->setDefaultShipping(1) |
| 57 | + ->setTaxvat('12') |
| 58 | + ->setGender(0) |
| 59 | + ->setDob($dob) |
| 60 | + ->setCustomAttribute('date', $date); |
| 61 | + $repository->save($customer, 'password'); |
| 62 | + |
| 63 | + $customer = $repository->get($email); |
| 64 | + $customerDob = $customer->getDob(); |
| 65 | + $customerDate = $customer->getCustomAttribute('date')->getValue(); |
| 66 | + $this->assertEquals($expectedDob, $customerDob); |
| 67 | + $this->assertEquals($expectedDate, $customerDate); |
| 68 | + } |
| 69 | + |
| 70 | + public function getDate() |
| 71 | + { |
| 72 | + return [ |
| 73 | + [self::DOB, '12/25/2017', self::EXPECTED_DOB, SELF::EXPECTED_DATE, 'en_US', 'customer1@example.com'], |
| 74 | + [self::DOB, '25/12/2017', self::EXPECTED_DOB, SELF::EXPECTED_DATE, 'fr_FR', 'customer2@example.com'], |
| 75 | + [self::DOB, '25/12/2017', self::EXPECTED_DOB, SELF::EXPECTED_DATE, 'ar_KW', 'customer3@example.com'], |
| 76 | + ]; |
| 77 | + } |
| 78 | +} |
0 commit comments