Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
TagScopeTest.php
Go to the documentation of this file.
1 <?php
7 
8 class TagScopeTest extends \PHPUnit\Framework\TestCase
9 {
13  protected $_object;
14 
18  protected $_frontend;
19 
20  protected function setUp()
21  {
22  $this->_frontend = $this->createMock(\Magento\Framework\Cache\FrontendInterface::class);
23  $this->_object = new \Magento\Framework\Cache\Frontend\Decorator\TagScope($this->_frontend, 'enforced_tag');
24  }
25 
26  protected function tearDown()
27  {
28  $this->_object = null;
29  $this->_frontend = null;
30  }
31 
32  public function testGetTag()
33  {
34  $this->assertEquals('enforced_tag', $this->_object->getTag());
35  }
36 
37  public function testSave()
38  {
39  $expectedResult = new \stdClass();
40  $this->_frontend->expects(
41  $this->once()
42  )->method(
43  'save'
44  )->with(
45  'test_value',
46  'test_id',
47  ['test_tag_one', 'test_tag_two', 'enforced_tag'],
48  111
49  )->will(
50  $this->returnValue($expectedResult)
51  );
52  $actualResult = $this->_object->save('test_value', 'test_id', ['test_tag_one', 'test_tag_two'], 111);
53  $this->assertSame($expectedResult, $actualResult);
54  }
55 
56  public function testCleanModeAll()
57  {
58  $expectedResult = new \stdClass();
59  $this->_frontend->expects(
60  $this->once()
61  )->method(
62  'clean'
63  )->with(
65  ['enforced_tag']
66  )->will(
67  $this->returnValue($expectedResult)
68  );
69  $actualResult = $this->_object->clean(
71  ['ignored_tag_one', 'ignored_tag_two']
72  );
73  $this->assertSame($expectedResult, $actualResult);
74  }
75 
76  public function testCleanModeMatchingTag()
77  {
78  $expectedResult = new \stdClass();
79  $this->_frontend->expects(
80  $this->once()
81  )->method(
82  'clean'
83  )->with(
85  ['test_tag_one', 'test_tag_two', 'enforced_tag']
86  )->will(
87  $this->returnValue($expectedResult)
88  );
89  $actualResult = $this->_object->clean(
91  ['test_tag_one', 'test_tag_two']
92  );
93  $this->assertSame($expectedResult, $actualResult);
94  }
95 
102  public function testCleanModeMatchingAnyTag($fixtureResultOne, $fixtureResultTwo, $expectedResult)
103  {
104  $this->_frontend->expects(
105  $this->at(0)
106  )->method(
107  'clean'
108  )->with(
110  ['test_tag_one', 'enforced_tag']
111  )->will(
112  $this->returnValue($fixtureResultOne)
113  );
114  $this->_frontend->expects(
115  $this->at(1)
116  )->method(
117  'clean'
118  )->with(
120  ['test_tag_two', 'enforced_tag']
121  )->will(
122  $this->returnValue($fixtureResultTwo)
123  );
124  $actualResult = $this->_object->clean(
126  ['test_tag_one', 'test_tag_two']
127  );
128  $this->assertEquals($expectedResult, $actualResult);
129  }
130 
135  {
136  return [
137  'failure, failure' => [false, false, false],
138  'failure, success' => [false, true, true],
139  'success, failure' => [true, false, true],
140  'success, success' => [true, true, true]
141  ];
142  }
143 }
testCleanModeMatchingAnyTag($fixtureResultOne, $fixtureResultTwo, $expectedResult)
const CLEANING_MODE_ALL
Definition: Cache.php:72
const CLEANING_MODE_MATCHING_ANY_TAG
Definition: Cache.php:76
const CLEANING_MODE_MATCHING_TAG
Definition: Cache.php:74