Skip to content

Commit af54db3

Browse files
improve test
1 parent eb50002 commit af54db3

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

dev/tests/integration/testsuite/Magento/Customer/Controller/AccountTest.php

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,17 @@
2222
use Magento\Store\Model\StoreManager;
2323
use Magento\Store\Model\StoreManagerInterface;
2424
use Magento\TestFramework\Helper\Bootstrap;
25+
use Magento\TestFramework\Helper\Xpath;
2526
use Magento\TestFramework\Mail\Template\TransportBuilderMock;
2627
use Magento\TestFramework\Request;
28+
use Magento\TestFramework\TestCase\AbstractController;
2729
use Magento\Theme\Controller\Result\MessagePlugin;
2830
use PHPUnit\Framework\Constraint\StringContains;
2931

3032
/**
3133
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
3234
*/
33-
class AccountTest extends \Magento\TestFramework\TestCase\AbstractController
35+
class AccountTest extends AbstractController
3436
{
3537
/**
3638
* @var TransportBuilderMock
@@ -54,9 +56,8 @@ protected function setUp(): void
5456
*/
5557
protected function login($customerId)
5658
{
57-
/** @var \Magento\Customer\Model\Session $session */
58-
$session = Bootstrap::getObjectManager()
59-
->get(\Magento\Customer\Model\Session::class);
59+
/** @var Session $session */
60+
$session = Bootstrap::getObjectManager()->get(Session::class);
6061
$session->loginById($customerId);
6162
}
6263

@@ -148,8 +149,8 @@ public function testCreatepasswordActionWithSession()
148149
$customer->setData('confirmation', 'confirmation');
149150
$customer->save();
150151

151-
/** @var \Magento\Customer\Model\Session $customer */
152-
$session = Bootstrap::getObjectManager()->get(\Magento\Customer\Model\Session::class);
152+
/** @var Session $customer */
153+
$session = Bootstrap::getObjectManager()->get(Session::class);
153154
$session->setRpToken($token);
154155
$session->setRpCustomerId($customer->getId());
155156

@@ -404,18 +405,16 @@ public function testEditAction()
404405
$this->assertEquals(200, $this->getResponse()->getHttpResponseCode(), $body);
405406
$this->assertStringContainsString('<div class="field field-name-firstname required">', $body);
406407
// Verify the password check box is not checked
407-
$expectedString = <<<EXPECTED_HTML
408-
<input type="checkbox" name="change_password" id="change-password" data-role="change-password" value="1"
409-
title="Change&#x20;Password"
410-
class="checkbox" />
411-
EXPECTED_HTML;
412-
$this->assertStringContainsString($expectedString, $body);
408+
$checkboxXpath = '//input[@type="checkbox"][@name="change_password"][@id="change-password"][not (@checked)]' .
409+
'[@data-role="change-password"][@value="1"][@title="Change Password"][@class="checkbox"]';
410+
411+
$this->assertEquals(1, Xpath::getElementsCountForXpath($checkboxXpath, $body));
413412
}
414413

415414
/**
416415
* @magentoDataFixture Magento/Customer/_files/customer.php
417416
*/
418-
public function testChangePasswordEditAction()
417+
public function testChangePasswordEditAction(): void
419418
{
420419
$this->login(1);
421420

@@ -425,12 +424,11 @@ public function testChangePasswordEditAction()
425424
$this->assertEquals(200, $this->getResponse()->getHttpResponseCode(), $body);
426425
$this->assertStringContainsString('<div class="field field-name-firstname required">', $body);
427426
// Verify the password check box is checked
428-
$expectedString = <<<EXPECTED_HTML
429-
<input type="checkbox" name="change_password" id="change-password" data-role="change-password" value="1"
430-
title="Change&#x20;Password"
431-
checked="checked" class="checkbox" />
432-
EXPECTED_HTML;
433-
$this->assertStringContainsString($expectedString, $body);
427+
$checkboxXpath = '//input[@type="checkbox"][@name="change_password"][@id="change-password"]' .
428+
'[@data-role="change-password"][@value="1"][@title="Change Password"][@checked="checked"]' .
429+
'[@class="checkbox"]';
430+
431+
$this->assertEquals(1, Xpath::getElementsCountForXpath($checkboxXpath, $body));
434432
}
435433

436434
/**

0 commit comments

Comments
 (0)