Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AccessListTest.php
Go to the documentation of this file.
1 <?php
7 declare(strict_types=1);
8 
10 
12 use PHPUnit\Framework\TestCase;
15 
16 class AccessListTest extends TestCase
17 {
21  private $accessList;
22 
26  protected function setUp()
27  {
28  $objectManager = new ObjectManager($this);
29  $configMock = $this->getMockForAbstractClass(
30  ScopeConfigInterface::class
31  );
32  $configMock->expects($this->any())
33  ->method('getValue')
34  ->with('system/full_page_cache/default')
35  ->willReturn(['access_list' => 'localhost']);
36  $this->accessList = $objectManager->getObject(
37  AccessList::class,
38  [
39  'config' => $configMock,
40  'data' => ['field' => 'access_list']
41  ]
42  );
43  }
44 
48  public function getValidValues(): array
49  {
50  return [
51  ['localhost', 'localhost'],
52  [null, 'localhost'],
53  ['127.0.0.1', '127.0.0.1'],
54  ['127.0.0.1, localhost, ::2', '127.0.0.1, localhost, ::2'],
55  ];
56  }
57 
63  public function testBeforeSave($value, $expectedValue)
64  {
65  $this->accessList->setValue($value);
66  $this->accessList->beforeSave();
67  $this->assertEquals($expectedValue, $this->accessList->getValue());
68  }
69 
73  public function getInvalidValues(): array
74  {
75  return [
76  ['\\bull val\\'],
77  ['{*I am not an IP*}'],
78  ['{*I am not an IP*}, 127.0.0.1'],
79  ];
80  }
81 
87  public function testBeforeSaveInvalid($value)
88  {
89  $this->accessList->setValue($value);
90  $this->accessList->beforeSave();
91  }
92 }
$objectManager
Definition: bootstrap.php:17
$value
Definition: gender.phtml:16