NameTest.php 3.16 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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Magento\Customer\Block\Widget;

use Magento\TestFramework\Helper\Bootstrap;

/**
 * Test \Magento\Customer\Block\Widget\Name
 * @magentoAppArea frontend
 */
class NameTest extends \PHPUnit\Framework\TestCase
{
    /** @var Name */
    protected $_block;

    protected function setUp()
    {
        $objectManager = Bootstrap::getObjectManager();
        $objectManager->get(\Magento\Framework\App\State::class)->setAreaCode('frontend');
        $this->_block = $objectManager->get(
            \Magento\Framework\View\LayoutInterface::class
        )->createBlock(
            \Magento\Customer\Block\Widget\Name::class
        );
    }

    /**
     * @magentoAppIsolation enabled
     */
    public function testToHtmlSimpleName()
    {
        /** @var \Magento\Customer\Api\Data\CustomerInterfaceFactory $customerFactory */
        $customerFactory = Bootstrap::getObjectManager()->get(
            \Magento\Customer\Api\Data\CustomerInterfaceFactory::class
        );
        $customerDataObject = $customerFactory->create();
        $customerDataObject->setFirstname('Jane');
        $customerDataObject->setLastname('Doe');
        $this->_block->setObject($customerDataObject);

        $html = $this->_block->toHtml();

        $this->assertContains('title="First&#x20;Name"', $html);
        $this->assertContains('value="Jane"', $html);
        $this->assertContains('title="Last&#x20;Name"', $html);
        $this->assertContains('value="Doe"', $html);
        $this->assertNotContains('title="Middle&#x20;Name&#x2F;Initial"', $html);
        $this->assertNotContains('title="Name&#x20;Prefix"', $html);
        $this->assertNotContains('title="Name&#x20;Suffix"', $html);
    }

    /**
     * @magentoAppIsolation enabled
     * @magentoDataFixture Magento/Customer/_files/attribute_user_fullname.php
     */
    public function testToHtmlFancyName()
    {
        /** @var \Magento\Customer\Api\Data\CustomerInterfaceFactory $customerFactory */
        $customerFactory = Bootstrap::getObjectManager()->get(
            \Magento\Customer\Api\Data\CustomerInterfaceFactory::class
        );
        $customerDataObject = $customerFactory->create();
        $customerDataObject->setPrefix(
            'Dr.'
        )->setFirstname(
            'Jane'
        )->setMiddlename(
            'Roe'
        )->setLastname(
            'Doe'
        )->setSuffix(
            'Ph.D.'
        );
        $this->_block->setObject($customerDataObject);

        $html = $this->_block->toHtml();

        $this->assertContains('title="First&#x20;Name"', $html);
        $this->assertContains('value="Jane"', $html);
        $this->assertContains('title="Last&#x20;Name"', $html);
        $this->assertContains('value="Doe"', $html);
        $this->assertContains('title="Middle&#x20;Name&#x2F;Initial"', $html);
        $this->assertContains('value="Roe"', $html);
        $this->assertContains('title="Name&#x20;Prefix"', $html);
        $this->assertContains('value="Dr."', $html);
        $this->assertContains('title="Name&#x20;Suffix"', $html);
        $this->assertContains('value="Ph.D."', $html);
    }
}