CreatePostTest.php 1.99 KB
Newer Older
Ketan's avatar
Ketan committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Magento\Customer\Controller\Account;

use Magento\TestFramework\Helper\Bootstrap;

/**
 * @magentoAppArea adminhtml
 */
class CreatePostTest extends \Magento\TestFramework\TestCase\AbstractController
{
    const EXPECTED_DOB = '1991-12-31';
    const EXPECTED_DATE = '2017-12-25 00:00:00';

    /**
     * @var CreatePost
     */
    private $model;

    protected function setUp()
    {
        $this->model = Bootstrap::getObjectManager()->create(CreatePost::class);
    }

    /**
     * @magentoDbIsolation enabled
     * @magentoDataFixture Magento/Customer/_files/date_attribute.php
     * @magentoDataFixture Magento/Customer/_files/customer_date_attribute.php
     */
    public function testCustomerSaveWithDateAttributes()
    {
        $objectManager = Bootstrap::getObjectManager();

        /** @var $repository \Magento\Customer\Api\CustomerRepositoryInterface */
        $repository = $objectManager->create('Magento\Customer\Api\CustomerRepositoryInterface');
        $customer1 = $repository->get('john.doe1@ex.com', 1);
        $customerDob = $customer1->getDob();
        $customerDate = $customer1->getCustomAttribute('date')->getValue();
        $this->assertEquals(self::EXPECTED_DOB, $customerDob);
        $this->assertEquals(self::EXPECTED_DATE, $customerDate);

        $customer2 = $repository->get('john.doe2@ex.com', 1);
        $customerDob = $customer2->getDob();
        $customerDate = $customer2->getCustomAttribute('date')->getValue();
        $this->assertEquals(self::EXPECTED_DOB, $customerDob);
        $this->assertEquals(self::EXPECTED_DATE, $customerDate);

        $customer3 = $repository->get('john.doe3@ex.com', 1);
        $customerDob = $customer3->getDob();
        $customerDate = $customer3->getCustomAttribute('date')->getValue();
        $this->assertEquals(self::EXPECTED_DOB, $customerDob);
        $this->assertEquals(self::EXPECTED_DATE, $customerDate);
    }
}