@@ -610,4 +610,104 @@ public function testIsResetPasswordLinkTokenExpiredIsNotExpiredToken()
610
610
$ this ->userDataMock ->expects ($ this ->once ())->method ('getResetPasswordLinkExpirationPeriod ' )->willReturn (1 );
611
611
$ this ->assertFalse ($ this ->model ->isResetPasswordLinkTokenExpired ());
612
612
}
613
+
614
+ public function testCheckPasswordChangeEqualToCurrent ()
615
+ {
616
+ /** @var $validatorMock \Magento\Framework\Validator\DataObject|\PHPUnit_Framework_MockObject_MockObject */
617
+ $ validatorMock = $ this ->getMockBuilder ('Magento\Framework\Validator\DataObject ' )
618
+ ->disableOriginalConstructor ()
619
+ ->setMethods ([])
620
+ ->getMock ();
621
+ $ this ->validatorObjectFactoryMock ->expects ($ this ->once ())->method ('create ' )->willReturn ($ validatorMock );
622
+ $ this ->validationRulesMock ->expects ($ this ->once ())
623
+ ->method ('addUserInfoRules ' )
624
+ ->with ($ validatorMock );
625
+ $ validatorMock ->expects ($ this ->once ())->method ('isValid ' )->willReturn (true );
626
+
627
+ $ newPassword = "NEWmYn3wpassw0rd " ;
628
+ $ oldPassword = "OLDmYn3wpassw0rd " ;
629
+ $ this ->model ->setPassword ($ newPassword )
630
+ ->setId (1 )
631
+ ->setOrigData ('password ' , $ oldPassword );
632
+ $ this ->encryptorMock ->expects ($ this ->once ())
633
+ ->method ('isValidHash ' )
634
+ ->with ($ newPassword , $ oldPassword )
635
+ ->willReturn (true );
636
+ $ result = $ this ->model ->validate ();
637
+ $ this ->assertInternalType ('array ' , $ result );
638
+ $ this ->assertCount (1 , $ result );
639
+ $ this ->assertContains ("Sorry, but this password has already been used. " , (string )$ result [0 ]);
640
+ }
641
+
642
+ public function testCheckPasswordChangeEqualToPrevious ()
643
+ {
644
+ /** @var $validatorMock \Magento\Framework\Validator\DataObject|\PHPUnit_Framework_MockObject_MockObject */
645
+ $ validatorMock = $ this ->getMockBuilder ('Magento\Framework\Validator\DataObject ' )
646
+ ->disableOriginalConstructor ()
647
+ ->setMethods ([])
648
+ ->getMock ();
649
+ $ this ->validatorObjectFactoryMock ->expects ($ this ->once ())->method ('create ' )->willReturn ($ validatorMock );
650
+ $ this ->validationRulesMock ->expects ($ this ->once ())
651
+ ->method ('addUserInfoRules ' )
652
+ ->with ($ validatorMock );
653
+ $ validatorMock ->expects ($ this ->once ())->method ('isValid ' )->willReturn (true );
654
+
655
+ $ newPassword = "NEWmYn3wpassw0rd " ;
656
+ $ newPasswordHash = "new password hash " ;
657
+ $ oldPassword = "OLDmYn3wpassw0rd " ;
658
+ $ this ->model ->setPassword ($ newPassword )
659
+ ->setId (1 )
660
+ ->setOrigData ('password ' , $ oldPassword );
661
+ $ this ->encryptorMock ->expects ($ this ->once ())
662
+ ->method ('isValidHash ' )
663
+ ->with ($ newPassword , $ oldPassword )
664
+ ->willReturn (false );
665
+
666
+ $ this ->encryptorMock ->expects ($ this ->once ())
667
+ ->method ('getHash ' )
668
+ ->with ($ newPassword , false )
669
+ ->willReturn ($ newPasswordHash );
670
+
671
+ $ this ->resourceMock ->expects ($ this ->once ())->method ('getOldPasswords ' )->willReturn (['hash1 ' , $ newPasswordHash ]);
672
+
673
+ $ result = $ this ->model ->validate ();
674
+ $ this ->assertInternalType ('array ' , $ result );
675
+ $ this ->assertCount (1 , $ result );
676
+ $ this ->assertContains ("Sorry, but this password has already been used. " , (string )$ result [0 ]);
677
+ }
678
+
679
+ public function testCheckPasswordChangeValid ()
680
+ {
681
+ /** @var $validatorMock \Magento\Framework\Validator\DataObject|\PHPUnit_Framework_MockObject_MockObject */
682
+ $ validatorMock = $ this ->getMockBuilder ('Magento\Framework\Validator\DataObject ' )
683
+ ->disableOriginalConstructor ()
684
+ ->setMethods ([])
685
+ ->getMock ();
686
+ $ this ->validatorObjectFactoryMock ->expects ($ this ->once ())->method ('create ' )->willReturn ($ validatorMock );
687
+ $ this ->validationRulesMock ->expects ($ this ->once ())
688
+ ->method ('addUserInfoRules ' )
689
+ ->with ($ validatorMock );
690
+ $ validatorMock ->expects ($ this ->once ())->method ('isValid ' )->willReturn (true );
691
+
692
+ $ newPassword = "NEWmYn3wpassw0rd " ;
693
+ $ newPasswordHash = "new password hash " ;
694
+ $ oldPassword = "OLDmYn3wpassw0rd " ;
695
+ $ this ->model ->setPassword ($ newPassword )
696
+ ->setId (1 )
697
+ ->setOrigData ('password ' , $ oldPassword );
698
+ $ this ->encryptorMock ->expects ($ this ->once ())
699
+ ->method ('isValidHash ' )
700
+ ->with ($ newPassword , $ oldPassword )
701
+ ->willReturn (false );
702
+
703
+ $ this ->encryptorMock ->expects ($ this ->once ())
704
+ ->method ('getHash ' )
705
+ ->with ($ newPassword , false )
706
+ ->willReturn ($ newPasswordHash );
707
+
708
+ $ this ->resourceMock ->expects ($ this ->once ())->method ('getOldPasswords ' )->willReturn (['hash1 ' , 'hash2 ' ]);
709
+
710
+ $ result = $ this ->model ->validate ();
711
+ $ this ->assertTrue ($ result );
712
+ }
613
713
}
0 commit comments