Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
KeyLengthTest.php
Go to the documentation of this file.
1 <?php
8 
10 
11 class KeyLengthTest extends \PHPUnit\Framework\TestCase
12 {
16  const KEY_LENGTH = 32;
17 
22 
23  protected function setUp()
24  {
25  $options = ['length' => KeyLengthTest::KEY_LENGTH];
26  $this->keyLengthValidator = new KeyLength($options);
27  }
28 
29  public function testSetLength()
30  {
31  $this->assertEquals(KeyLengthTest::KEY_LENGTH, $this->keyLengthValidator->getLength());
32  $this->assertEquals(KeyLengthTest::KEY_LENGTH, $this->keyLengthValidator->getMin());
33  $this->assertEquals(KeyLengthTest::KEY_LENGTH, $this->keyLengthValidator->getMax());
34  }
35 
36  public function testIsValidLong()
37  {
38  $invalidToken = 'asjdkhbcaklsjhlkasjdhlkajhsdljahksdlkafjsljdhskjhksj';
39  $this->keyLengthValidator->isValid($invalidToken);
40  $expected = ['stringLengthTooLong' => "Key '{$invalidToken}' is more than 32 characters long"];
41  $this->assertEquals($expected, $this->keyLengthValidator->getMessages());
42  }
43 
44  public function testIsValidShort()
45  {
46  $invalidToken = 'fajdhkahkjha';
47  $this->keyLengthValidator->isValid($invalidToken);
48  $expected = ['stringLengthTooShort' => "Key '{$invalidToken}' is less than 32 characters long"];
49  $this->assertEquals($expected, $this->keyLengthValidator->getMessages());
50  }
51 
53  {
54  $invalidToken = 'fajdhkahkjha';
55  $this->keyLengthValidator->setName('Custom Key');
56  $this->keyLengthValidator->isValid($invalidToken);
57  $expected = ['stringLengthTooShort' => "Custom Key '{$invalidToken}' is less than 32 characters long"];
58  $this->assertEquals($expected, $this->keyLengthValidator->getMessages());
59  }
60 
65  public function testIsValidInvalidType()
66  {
67  $invalidTokenType = 1;
68  $this->keyLengthValidator->isValid($invalidTokenType);
69  }
70 }