Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
VarnishTest.php
Go to the documentation of this file.
1 <?php
7 
8 class VarnishTest extends \PHPUnit\Framework\TestCase
9 {
13  protected $_model;
14 
18  protected $_config;
19 
20  protected function setUp()
21  {
23  \Magento\Framework\App\Config\MutableScopeConfigInterface::class
24  );
25  $data = [
26  'access_list' => 'localhost',
27  'backend_host' => 'localhost',
28  'backend_port' => 8080,
29  'ttl' => 120,
30  ];
31  $this->_config->setValue('system/full_page_cache/default', $data);
33  \Magento\PageCache\Model\System\Config\Backend\Varnish::class
34  );
35  }
36 
45  public function testBeforeSave($value, $path, $expected, $needUpdate)
46  {
47  if ($needUpdate) {
48  $this->_model->load($path, 'path');
49  }
50 
51  $this->_model->setValue($value);
52  $this->_model->setPath($path);
53  $this->_model->setField($path);
54  $this->_model->save();
55  $value = $this->_model->getValue();
56 
57  $this->assertEquals($value, $expected);
58  }
59 
60  public function beforeSaveDataProvider()
61  {
62  return [
63  ['localhost', 'access_list', 'localhost', false],
64  ['localhost', 'backend_host', 'localhost', false],
65  [8081, 'backend_port', 8081, false],
66  [125, 'ttl', 125, false],
67  ['localhost', 'access_list', 'localhost', true],
68  ['', 'backend_host', 'localhost', true],
69  [0, 'backend_port', 8080, true],
70  [0, 'ttl', 120, true]
71  ];
72  }
73 
81  public function testAfterLoad($path, $expected, $needUpdate)
82  {
83  if ($needUpdate) {
84  $this->_model->load($path, 'path');
85  }
86  $this->_model->setValue('');
87  $this->_model->setPath($path);
88  $this->_model->setField($path);
89  $this->_model->save();
90  $value = $this->_model->getValue();
91 
92  $this->assertEquals($value, $expected);
93  }
94 
95  public function afterLoadDataProvider()
96  {
97  return [
98  ['access_list', 'localhost', true],
99  ['backend_host', 'localhost', true],
100  ['backend_port', 8080, true],
101  ['ttl', 120, true]
102  ];
103  }
104 }
testBeforeSave($value, $path, $expected, $needUpdate)
Definition: VarnishTest.php:45
$value
Definition: gender.phtml:16