Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ModelTest.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
10 class ModelTest extends \PHPUnit\Framework\TestCase
11 {
15  protected $_model;
16 
17  protected function setUp()
18  {
20  \Magento\Framework\Encryption\Encryptor::class
21  );
22  }
23 
24  public function testEncryptDecrypt()
25  {
27 
28  $this->assertEquals('', $encryptor->decrypt($encryptor->encrypt('')));
29  $this->assertEquals('test', $encryptor->decrypt($encryptor->encrypt('test')));
30  }
31 
32  public function testEncryptDecrypt2()
33  {
35 
36  $initial = md5(uniqid());
37  $encrypted = $encryptor->encrypt($initial);
38  $this->assertNotEquals($initial, $encrypted);
39  $this->assertEquals($initial, $encryptor->decrypt($encrypted));
40  }
41 
42  public function testValidateKey()
43  {
44  $validKey = md5(uniqid());
45  $this->_model->validateKey($validKey);
46  }
47 
51  public function testValidateKeyInvalid()
52  {
53  $invalidKey = '---- ';
54  $this->_model->validateKey($invalidKey);
55  }
56 
57  public function testGetValidateHash()
58  {
59  $password = uniqid();
60  $hash = $this->_model->getHash($password, true);
61 
62  $this->assertTrue(is_string($hash));
63  $this->assertTrue($this->_model->validateHash($password, $hash));
64  }
65 }