Skip to content

improve test AccountTest #29693

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,17 @@
use Magento\Store\Model\StoreManager;
use Magento\Store\Model\StoreManagerInterface;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\Helper\Xpath;
use Magento\TestFramework\Mail\Template\TransportBuilderMock;
use Magento\TestFramework\Request;
use Magento\TestFramework\TestCase\AbstractController;
use Magento\Theme\Controller\Result\MessagePlugin;
use PHPUnit\Framework\Constraint\StringContains;

/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class AccountTest extends \Magento\TestFramework\TestCase\AbstractController
class AccountTest extends AbstractController
{
/**
* @var TransportBuilderMock
Expand All @@ -54,9 +56,8 @@ protected function setUp(): void
*/
protected function login($customerId)
{
/** @var \Magento\Customer\Model\Session $session */
$session = Bootstrap::getObjectManager()
->get(\Magento\Customer\Model\Session::class);
/** @var Session $session */
$session = Bootstrap::getObjectManager()->get(Session::class);
$session->loginById($customerId);
}

Expand Down Expand Up @@ -148,8 +149,8 @@ public function testCreatepasswordActionWithSession()
$customer->setData('confirmation', 'confirmation');
$customer->save();

/** @var \Magento\Customer\Model\Session $customer */
$session = Bootstrap::getObjectManager()->get(\Magento\Customer\Model\Session::class);
/** @var Session $customer */
$session = Bootstrap::getObjectManager()->get(Session::class);
$session->setRpToken($token);
$session->setRpCustomerId($customer->getId());

Expand Down Expand Up @@ -404,18 +405,16 @@ public function testEditAction()
$this->assertEquals(200, $this->getResponse()->getHttpResponseCode(), $body);
$this->assertStringContainsString('<div class="field field-name-firstname required">', $body);
// Verify the password check box is not checked
$expectedString = <<<EXPECTED_HTML
<input type="checkbox" name="change_password" id="change-password" data-role="change-password" value="1"
title="Change&#x20;Password"
class="checkbox" />
EXPECTED_HTML;
$this->assertStringContainsString($expectedString, $body);
$checkboxXpath = '//input[@type="checkbox"][@name="change_password"][@id="change-password"][not (@checked)]' .
'[@data-role="change-password"][@value="1"][@title="Change Password"][@class="checkbox"]';

$this->assertEquals(1, Xpath::getElementsCountForXpath($checkboxXpath, $body));
}

/**
* @magentoDataFixture Magento/Customer/_files/customer.php
*/
public function testChangePasswordEditAction()
public function testChangePasswordEditAction(): void
{
$this->login(1);

Expand All @@ -425,12 +424,11 @@ public function testChangePasswordEditAction()
$this->assertEquals(200, $this->getResponse()->getHttpResponseCode(), $body);
$this->assertStringContainsString('<div class="field field-name-firstname required">', $body);
// Verify the password check box is checked
$expectedString = <<<EXPECTED_HTML
<input type="checkbox" name="change_password" id="change-password" data-role="change-password" value="1"
title="Change&#x20;Password"
checked="checked" class="checkbox" />
EXPECTED_HTML;
$this->assertStringContainsString($expectedString, $body);
$checkboxXpath = '//input[@type="checkbox"][@name="change_password"][@id="change-password"]' .
'[@data-role="change-password"][@value="1"][@title="Change Password"][@checked="checked"]' .
'[@class="checkbox"]';

$this->assertEquals(1, Xpath::getElementsCountForXpath($checkboxXpath, $body));
}

/**
Expand Down