init
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Customer\Block\Form;
|
||||
|
||||
use Magento\Customer\Model\Session;
|
||||
use Magento\Framework\View\LayoutInterface;
|
||||
use Magento\Framework\View\Element\ButtonLockManager;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Helper\Xpath;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @magentoAppArea frontend
|
||||
* @magentoDbIsolation enabled
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
*/
|
||||
class EditTest extends TestCase
|
||||
{
|
||||
private const SAVE_BUTTON_XPATH = '//*[@id="form-validate"]//*[@type="submit"]';
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @var LayoutInterface
|
||||
*/
|
||||
private $layout;
|
||||
|
||||
/**
|
||||
* @var Edit
|
||||
*/
|
||||
private $block;
|
||||
|
||||
/** @var Session */
|
||||
private $customerSession;
|
||||
|
||||
/**
|
||||
* @inheirtDoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->layout = $this->objectManager->get(LayoutInterface::class);
|
||||
$this->customerSession = $this->objectManager->get(Session::class);
|
||||
$this->block = $this->layout->createBlock(Edit::class);
|
||||
$this->block->setTemplate('Magento_Customer::form/edit.phtml');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testCustomerEditButton(): void
|
||||
{
|
||||
$code = 'customer_edit';
|
||||
$buttonLock = $this->getMockBuilder(\Magento\ReCaptchaUi\Model\ButtonLock::class)
|
||||
->disableOriginalConstructor()
|
||||
->disableAutoload()
|
||||
->setMethods(['isDisabled', 'getCode'])
|
||||
->getMock();
|
||||
$buttonLock->expects($this->atLeastOnce())->method('getCode')->willReturn($code);
|
||||
$buttonLock->expects($this->atLeastOnce())->method('isDisabled')->willReturn(false);
|
||||
$buttonLockManager = $this->objectManager->create(
|
||||
ButtonLockManager::class,
|
||||
['buttonLockPool' => ['customer_edit_form_submit' => $buttonLock]]
|
||||
);
|
||||
$this->block->setButtonLockManager($buttonLockManager);
|
||||
|
||||
$this->customerSession->loginById(1);
|
||||
$result = $this->block->toHtml();
|
||||
$this->assertFalse($buttonLockManager->isDisabled($code));
|
||||
$this->assertEquals(
|
||||
1,
|
||||
Xpath::getElementsCountForXpath(self::SAVE_BUTTON_XPATH, $result),
|
||||
'Customer Edit Button wasn\'t found in the page'
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Customer\Block\Form;
|
||||
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Framework\View\LayoutInterface;
|
||||
use Magento\Framework\View\Element\ButtonLockManager;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Helper\Xpath;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Class checks login form view
|
||||
*
|
||||
* @magentoAppArea frontend
|
||||
*/
|
||||
class LoginTest extends TestCase
|
||||
{
|
||||
private const EMAIL_LABEL_XPATH = "//label[@for='email']/span[contains(text(), 'Email')]";
|
||||
private const PASSWORD_LABEL_XPATH = "//label[@for='pass' ]/span[contains(text(), 'Password')]";
|
||||
private const EMAIL_INPUT_XPATH = "//input[@name ='login[username]' and contains(@data-validate,'required:true')"
|
||||
. "and contains(@data-validate, \"'validate-email':true\")]";
|
||||
private const PASSWORD_INPUT_XPATH = "//input[@name='login[password]'"
|
||||
. "and contains(@data-validate,'required:true')]";
|
||||
private const SIGN_IN_BUTTON_XPATH = "//button[@type='submit']/span[contains(text(), 'Sign In')]";
|
||||
private const FORGOT_PASSWORD_LINK_PATH = "//a[contains(@href, 'customer/account/forgotpassword')]"
|
||||
. "/span[contains(text(), 'Forgot Your Password?')] ";
|
||||
|
||||
/** @var ObjectManagerInterface */
|
||||
private $objectManager;
|
||||
|
||||
/** @var LayoutInterface */
|
||||
private $layout;
|
||||
|
||||
/** @var Login */
|
||||
private $block;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->layout = $this->objectManager->get(LayoutInterface::class);
|
||||
|
||||
$code = 'customer_login_form_submit';
|
||||
$buttonLock = $this->getMockBuilder(\Magento\ReCaptchaUi\Model\ButtonLock::class)
|
||||
->disableOriginalConstructor()
|
||||
->disableAutoload()
|
||||
->setMethods(['isDisabled', 'getCode'])
|
||||
->getMock();
|
||||
$buttonLock->expects($this->any())->method('getCode')->willReturn($code);
|
||||
$buttonLock->expects($this->any())->method('isDisabled')->willReturn(false);
|
||||
$buttonLockManager = $this->objectManager->create(
|
||||
ButtonLockManager::class,
|
||||
['buttonLockPool' => [$code => $buttonLock]]
|
||||
);
|
||||
|
||||
$this->block = $this->layout->createBlock(Login::class);
|
||||
$this->block->setTemplate('Magento_Customer::form/login.phtml');
|
||||
$this->block->setButtonLockManager($buttonLockManager);
|
||||
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testLoginForm(): void
|
||||
{
|
||||
$result = $this->block->toHtml();
|
||||
$this->assertEquals(
|
||||
1,
|
||||
Xpath::getElementsCountForXpath(self::EMAIL_LABEL_XPATH, $result),
|
||||
'Email label does not exist on the page'
|
||||
);
|
||||
$this->assertEquals(
|
||||
1,
|
||||
Xpath::getElementsCountForXpath(self::PASSWORD_LABEL_XPATH, $result),
|
||||
'Password label does not exist on the page'
|
||||
);
|
||||
$this->assertEquals(
|
||||
1,
|
||||
Xpath::getElementsCountForXpath(self::EMAIL_INPUT_XPATH, $result),
|
||||
'Email input does not exist on the page'
|
||||
);
|
||||
$this->assertEquals(
|
||||
1,
|
||||
Xpath::getElementsCountForXpath(self::PASSWORD_INPUT_XPATH, $result),
|
||||
'Password input does not exist on the page'
|
||||
);
|
||||
$this->assertEquals(
|
||||
1,
|
||||
Xpath::getElementsCountForXpath(self::SIGN_IN_BUTTON_XPATH, $result),
|
||||
'Sign in button does not exist on the page'
|
||||
);
|
||||
$this->assertEquals(
|
||||
1,
|
||||
Xpath::getElementsCountForXpath(self::FORGOT_PASSWORD_LINK_PATH, $result),
|
||||
'Forgot password link does not exist on the page'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoConfigFixture current_store customer/password/autocomplete_on_storefront 1
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAutocompletePasswordEnabled(): void
|
||||
{
|
||||
$this->assertFalse($this->block->isAutocompleteDisabled());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoConfigFixture current_store customer/password/autocomplete_on_storefront 0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAutocompletePasswordDisabled(): void
|
||||
{
|
||||
$this->assertTrue($this->block->isAutocompleteDisabled());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,223 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Customer\Block\Form;
|
||||
|
||||
use Magento\Customer\Block\DataProviders\AddressAttributeData;
|
||||
use Magento\Customer\ViewModel\Address\RegionProvider;
|
||||
use Magento\Framework\View\Element\Template;
|
||||
use Magento\Framework\View\Element\ButtonLockManager;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/**
|
||||
* Test class for \Magento\Customer\Block\Form\Register
|
||||
*
|
||||
* @magentoAppArea frontend
|
||||
*/
|
||||
class RegisterTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDbIsolation enabled
|
||||
* @return void
|
||||
*/
|
||||
public function testCompanyDefault(): void
|
||||
{
|
||||
/** @var \Magento\Customer\Block\Widget\Company $block */
|
||||
$block = Bootstrap::getObjectManager()->create(Register::class)
|
||||
->setTemplate('Magento_Customer::form/register.phtml')
|
||||
->setShowAddressFields(true);
|
||||
$this->setAttributeDataProvider($block);
|
||||
$this->setRegionProvider($block);
|
||||
$this->setButtonLockManager($block);
|
||||
|
||||
$this->assertStringContainsString('title="Company"', $block->toHtml());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDbIsolation enabled
|
||||
* @return void
|
||||
*/
|
||||
public function testTelephoneDefault(): void
|
||||
{
|
||||
/** @var \Magento\Customer\Block\Widget\Company $block */
|
||||
$block = Bootstrap::getObjectManager()->create(Register::class)
|
||||
->setTemplate('Magento_Customer::form/register.phtml')
|
||||
->setShowAddressFields(true);
|
||||
$this->setAttributeDataProvider($block);
|
||||
$this->setRegionProvider($block);
|
||||
$this->setButtonLockManager($block);
|
||||
|
||||
$this->assertStringContainsString('title="Phone Number"', $block->toHtml());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDbIsolation enabled
|
||||
* @return void
|
||||
*/
|
||||
public function testFaxDefault(): void
|
||||
{
|
||||
/** @var \Magento\Customer\Block\Widget\Company $block */
|
||||
$block = Bootstrap::getObjectManager()->create(Register::class)
|
||||
->setTemplate('Magento_Customer::form/register.phtml')
|
||||
->setShowAddressFields(true);
|
||||
$this->setAttributeDataProvider($block);
|
||||
$this->setRegionProvider($block);
|
||||
$this->setButtonLockManager($block);
|
||||
|
||||
$this->assertStringNotContainsString('title="Fax"', $block->toHtml());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDbIsolation enabled
|
||||
* @return void
|
||||
*/
|
||||
public function testCompanyDisabled(): void
|
||||
{
|
||||
/** @var \Magento\Customer\Model\Attribute $model */
|
||||
$model = Bootstrap::getObjectManager()->create(
|
||||
\Magento\Customer\Model\Attribute::class
|
||||
);
|
||||
$model->loadByCode('customer_address', 'company')->setIsVisible('0');
|
||||
$model->save();
|
||||
|
||||
/** @var \Magento\Customer\Block\Widget\Company $block */
|
||||
$block = Bootstrap::getObjectManager()->create(Register::class)
|
||||
->setTemplate('Magento_Customer::form/register.phtml')
|
||||
->setShowAddressFields(true);
|
||||
$this->setAttributeDataProvider($block);
|
||||
$this->setRegionProvider($block);
|
||||
$this->setButtonLockManager($block);
|
||||
|
||||
$this->assertStringNotContainsString('title="Company"', $block->toHtml());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDbIsolation enabled
|
||||
* @return void
|
||||
*/
|
||||
public function testTelephoneDisabled(): void
|
||||
{
|
||||
/** @var \Magento\Customer\Model\Attribute $model */
|
||||
$model = Bootstrap::getObjectManager()->create(
|
||||
\Magento\Customer\Model\Attribute::class
|
||||
);
|
||||
$model->loadByCode('customer_address', 'telephone')->setIsVisible('0');
|
||||
$model->save();
|
||||
|
||||
/** @var \Magento\Customer\Block\Widget\Company $block */
|
||||
$block = Bootstrap::getObjectManager()->create(Register::class)
|
||||
->setTemplate('Magento_Customer::form/register.phtml')
|
||||
->setShowAddressFields(true);
|
||||
$this->setAttributeDataProvider($block);
|
||||
$this->setRegionProvider($block);
|
||||
$this->setButtonLockManager($block);
|
||||
|
||||
$this->assertStringNotContainsString('title="Phone Number"', $block->toHtml());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDbIsolation enabled
|
||||
* @return void
|
||||
*/
|
||||
public function testFaxEnabled(): void
|
||||
{
|
||||
/** @var \Magento\Customer\Model\Attribute $model */
|
||||
$model = Bootstrap::getObjectManager()->create(
|
||||
\Magento\Customer\Model\Attribute::class
|
||||
);
|
||||
$model->loadByCode('customer_address', 'fax')->setIsVisible('1');
|
||||
$model->save();
|
||||
|
||||
/** @var \Magento\Customer\Block\Widget\Company $block */
|
||||
$block = Bootstrap::getObjectManager()->create(Register::class)
|
||||
->setTemplate('Magento_Customer::form/register.phtml')
|
||||
->setShowAddressFields(true);
|
||||
$this->setAttributeDataProvider($block);
|
||||
$this->setRegionProvider($block);
|
||||
$this->setButtonLockManager($block);
|
||||
|
||||
$this->assertStringContainsString('title="Fax"', $block->toHtml());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Customer/_files/attribute_city_store_label_address.php
|
||||
*/
|
||||
public function testCityWithStoreLabel(): void
|
||||
{
|
||||
/** @var \Magento\Customer\Block\Form\Register $block */
|
||||
$block = Bootstrap::getObjectManager()->create(Register::class)
|
||||
->setTemplate('Magento_Customer::form/register.phtml')
|
||||
->setShowAddressFields(true);
|
||||
$this->setAttributeDataProvider($block);
|
||||
$this->setRegionProvider($block);
|
||||
$this->setButtonLockManager($block);
|
||||
|
||||
$this->assertStringNotContainsString('title="City"', $block->toHtml());
|
||||
$this->assertStringContainsString('title="Suburb"', $block->toHtml());
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
/** @var \Magento\Eav\Model\Config $eavConfig */
|
||||
$eavConfig = Bootstrap::getObjectManager()->get(\Magento\Eav\Model\Config::class);
|
||||
$eavConfig->clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set attribute data provider.
|
||||
*
|
||||
* @param Template $block
|
||||
* @return void
|
||||
*/
|
||||
private function setAttributeDataProvider(Template $block): void
|
||||
{
|
||||
$attributeData = Bootstrap::getObjectManager()->get(AddressAttributeData::class);
|
||||
$block->setAttributeData($attributeData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Region Provider View Model.
|
||||
*
|
||||
* @param Template $block
|
||||
* @return void
|
||||
*/
|
||||
private function setRegionProvider(Template $block): void
|
||||
{
|
||||
$regionProvider = Bootstrap::getObjectManager()->create(RegionProvider::class);
|
||||
$block->setRegionProvider($regionProvider);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Button Lock Manager View Model
|
||||
*
|
||||
* @param Template $block
|
||||
* @return void
|
||||
*/
|
||||
private function setButtonLockManager(Template $block): void
|
||||
{
|
||||
$code = 'customer_create_form_submit';
|
||||
$buttonLock = $this->getMockBuilder(\Magento\ReCaptchaUi\Model\ButtonLock::class)
|
||||
->disableOriginalConstructor()
|
||||
->disableAutoload()
|
||||
->setMethods(['isDisabled', 'getCode'])
|
||||
->getMock();
|
||||
$buttonLock->expects($this->any())->method('getCode')->willReturn($code);
|
||||
$buttonLock->expects($this->any())->method('isDisabled')->willReturn(false);
|
||||
$buttonLockManager = Bootstrap::getObjectManager()->create(
|
||||
ButtonLockManager::class,
|
||||
['buttonLockPool' => [$code => $buttonLock]]
|
||||
);
|
||||
$block->setButtonLockManager($buttonLockManager);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user