22
22
use Magento \Store \Model \StoreManager ;
23
23
use Magento \Store \Model \StoreManagerInterface ;
24
24
use Magento \TestFramework \Helper \Bootstrap ;
25
+ use Magento \TestFramework \Helper \Xpath ;
25
26
use Magento \TestFramework \Mail \Template \TransportBuilderMock ;
26
27
use Magento \TestFramework \Request ;
28
+ use Magento \TestFramework \TestCase \AbstractController ;
27
29
use Magento \Theme \Controller \Result \MessagePlugin ;
28
30
use PHPUnit \Framework \Constraint \StringContains ;
29
31
30
32
/**
31
33
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
32
34
*/
33
- class AccountTest extends \ Magento \ TestFramework \ TestCase \ AbstractController
35
+ class AccountTest extends AbstractController
34
36
{
35
37
/**
36
38
* @var TransportBuilderMock
@@ -54,9 +56,8 @@ protected function setUp(): void
54
56
*/
55
57
protected function login ($ customerId )
56
58
{
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);
60
61
$ session ->loginById ($ customerId );
61
62
}
62
63
@@ -148,8 +149,8 @@ public function testCreatepasswordActionWithSession()
148
149
$ customer ->setData ('confirmation ' , 'confirmation ' );
149
150
$ customer ->save ();
150
151
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);
153
154
$ session ->setRpToken ($ token );
154
155
$ session ->setRpCustomerId ($ customer ->getId ());
155
156
@@ -404,18 +405,16 @@ public function testEditAction()
404
405
$ this ->assertEquals (200 , $ this ->getResponse ()->getHttpResponseCode (), $ body );
405
406
$ this ->assertStringContainsString ('<div class="field field-name-firstname required"> ' , $ body );
406
407
// 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 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 ));
413
412
}
414
413
415
414
/**
416
415
* @magentoDataFixture Magento/Customer/_files/customer.php
417
416
*/
418
- public function testChangePasswordEditAction ()
417
+ public function testChangePasswordEditAction (): void
419
418
{
420
419
$ this ->login (1 );
421
420
@@ -425,12 +424,11 @@ public function testChangePasswordEditAction()
425
424
$ this ->assertEquals (200 , $ this ->getResponse ()->getHttpResponseCode (), $ body );
426
425
$ this ->assertStringContainsString ('<div class="field field-name-firstname required"> ' , $ body );
427
426
// 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 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 ));
434
432
}
435
433
436
434
/**
0 commit comments