1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Metaways Infosystems GmbH, 2014 |
6
|
|
|
* @copyright Aimeos (aimeos.org), 2014-2022 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
namespace Aimeos\Base\Cache; |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
class Typo3Test extends \PHPUnit\Framework\TestCase |
14
|
|
|
{ |
15
|
|
|
private $object; |
16
|
|
|
private $mock; |
17
|
|
|
|
18
|
|
|
|
19
|
|
|
protected function setUp() : void |
20
|
|
|
{ |
21
|
|
|
if( interface_exists( 'TYPO3\CMS\Core\Cache\Frontend\FrontendInterface' ) === false ) { |
22
|
|
|
$this->markTestSkipped( 'Class \\TYPO3\\CMS\\Core\\Cache\\Frontend\\FrontendInterface not found' ); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
$this->mock = $this->getMockBuilder( 'TYPO3\CMS\Core\Cache\Frontend\FrontendInterface' )->getMock(); |
26
|
|
|
$this->object = new \Aimeos\Base\Cache\Typo3( [], $this->mock ); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
|
30
|
|
|
protected function tearDown() : void |
31
|
|
|
{ |
32
|
|
|
unset( $this->mock, $this->object ); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
|
36
|
|
|
public function testClear() |
37
|
|
|
{ |
38
|
|
|
$this->mock->expects( $this->once() )->method( 'flush' ); |
39
|
|
|
$this->assertTrue( $this->object->clear() ); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
|
43
|
|
|
public function testClearWithSiteId() |
44
|
|
|
{ |
45
|
|
|
$object = new \Aimeos\Base\Cache\Typo3( array( 'siteid' => 1 ), $this->mock ); |
46
|
|
|
|
47
|
|
|
$this->mock->expects( $this->once() )->method( 'flushByTag' )->with( $this->equalTo( '1-siteid' ) ); |
48
|
|
|
$this->assertTrue( $object->clear() ); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
|
52
|
|
|
public function testDelete() |
53
|
|
|
{ |
54
|
|
|
$this->mock->expects( $this->once() )->method( 'remove' )->with( $this->equalTo( 'key' ) ); |
55
|
|
|
$this->assertTrue( $this->object->delete( 'key' ) ); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
|
59
|
|
|
public function testDeleteWithSiteId() |
60
|
|
|
{ |
61
|
|
|
$object = new \Aimeos\Base\Cache\Typo3( array( 'siteid' => 1 ), $this->mock ); |
62
|
|
|
|
63
|
|
|
$this->mock->expects( $this->once() )->method( 'remove' )->with( $this->equalTo( '1-key' ) ); |
64
|
|
|
$this->assertTrue( $object->delete( 'key' ) ); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
|
68
|
|
|
public function testDeleteMultiple() |
69
|
|
|
{ |
70
|
|
|
$this->mock->expects( $this->exactly( 2 ) )->method( 'remove' )->with( $this->equalTo( 'key' ) ); |
71
|
|
|
$this->assertTrue( $this->object->deleteMultiple( array( 'key', 'key' ) ) ); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
|
75
|
|
|
public function testDeleteMultipleWithSiteId() |
76
|
|
|
{ |
77
|
|
|
$object = new \Aimeos\Base\Cache\Typo3( array( 'siteid' => 1 ), $this->mock ); |
78
|
|
|
|
79
|
|
|
$this->mock->expects( $this->once() )->method( 'remove' )->with( $this->equalTo( '1-key' ) ); |
80
|
|
|
$this->assertTrue( $object->deleteMultiple( array( 'key' ) ) ); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
|
84
|
|
|
public function testDeleteByTags() |
85
|
|
|
{ |
86
|
|
|
$this->mock->expects( $this->exactly( 2 ) )->method( 'flushByTag' )->with( $this->equalTo( 'tag' ) ); |
87
|
|
|
$this->assertTrue( $this->object->deleteByTags( array( 'tag', 'tag' ) ) ); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
|
91
|
|
|
public function testDeleteByTagsWithSiteId() |
92
|
|
|
{ |
93
|
|
|
$object = new \Aimeos\Base\Cache\Typo3( array( 'siteid' => 1 ), $this->mock ); |
94
|
|
|
|
95
|
|
|
$this->mock->expects( $this->once() )->method( 'flushByTag' )->with( $this->equalTo( '1-tag' ) ); |
96
|
|
|
$this->assertTrue( $object->deleteByTags( array( 'tag' ) ) ); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
|
100
|
|
|
public function testGet() |
101
|
|
|
{ |
102
|
|
|
$this->mock->expects( $this->once() )->method( 'get' ) |
103
|
|
|
->with( $this->equalTo( 'key' ) )->will( $this->returnValue( 'value' ) ); |
104
|
|
|
|
105
|
|
|
$this->assertEquals( 'value', $this->object->get( 'key', 'default' ) ); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
|
109
|
|
|
public function testGetWithSiteId() |
110
|
|
|
{ |
111
|
|
|
$object = new \Aimeos\Base\Cache\Typo3( array( 'siteid' => 1 ), $this->mock ); |
112
|
|
|
|
113
|
|
|
$this->mock->expects( $this->once() )->method( 'get' )->with( $this->equalTo( '1-key' ) ); |
114
|
|
|
$object->get( 'key', 'default' ); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
|
118
|
|
|
public function testGetMultiple() |
119
|
|
|
{ |
120
|
|
|
$this->mock->expects( $this->exactly( 2 ) )->method( 'get' ) |
121
|
|
|
->will( $this->returnValue( 'value' ) ); |
122
|
|
|
|
123
|
|
|
$expected = array( 'key1' => 'value', 'key2' => 'value' ); |
124
|
|
|
$this->assertEquals( $expected, $this->object->getMultiple( array( 'key1', 'key2' ) ) ); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
|
128
|
|
|
public function testGetMultipleWithSiteId() |
129
|
|
|
{ |
130
|
|
|
$object = new \Aimeos\Base\Cache\Typo3( array( 'siteid' => 1 ), $this->mock ); |
131
|
|
|
|
132
|
|
|
$this->mock->expects( $this->once() )->method( 'get' )->with( $this->equalTo( '1-key' ) ); |
133
|
|
|
$object->getMultiple( array( 'key' ) ); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
|
137
|
|
|
public function testHas() |
138
|
|
|
{ |
139
|
|
|
$this->mock->expects( $this->once() )->method( 'has' )->will( $this->returnValue( true ) ); |
140
|
|
|
$this->assertTrue( $this->object->has( 'key' ) ); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
|
144
|
|
|
public function testSet() |
145
|
|
|
{ |
146
|
|
|
$this->mock->expects( $this->once() )->method( 'set' ) |
147
|
|
|
->with( |
148
|
|
|
$this->equalTo( 'key' ), $this->equalTo( 'value' ), |
149
|
|
|
$this->equalTo( ['tag'] ), $this->greaterThan( 0 ) |
150
|
|
|
); |
151
|
|
|
|
152
|
|
|
$this->assertTrue( $this->object->set( 'key', 'value', '2100-01-01 00:00:00', ['tag'] ) ); |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
|
156
|
|
|
public function testSetWithSiteId() |
157
|
|
|
{ |
158
|
|
|
$object = new \Aimeos\Base\Cache\Typo3( array( 'siteid' => 1 ), $this->mock ); |
159
|
|
|
|
160
|
|
|
$this->mock->expects( $this->once() )->method( 'set' ) |
161
|
|
|
->with( |
162
|
|
|
$this->equalTo( '1-key' ), $this->equalTo( 'value' ), |
163
|
|
|
$this->equalTo( array( '1-siteid', '1-tag' ) ), $this->equalTo( null ) |
164
|
|
|
); |
165
|
|
|
|
166
|
|
|
$this->assertTrue( $object->set( 'key', 'value', null, ['tag'] ) ); |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
|
170
|
|
|
public function testSetMultiple() |
171
|
|
|
{ |
172
|
|
|
$this->mock->expects( $this->once() )->method( 'set' ) |
173
|
|
|
->with( |
174
|
|
|
$this->equalTo( 'key' ), $this->equalTo( 'value' ), |
175
|
|
|
$this->equalTo( ['tag'] ), $this->greaterThan( 0 ) |
176
|
|
|
); |
177
|
|
|
|
178
|
|
|
$expires = '2100-01-01 00:00:00'; |
179
|
|
|
$this->assertTrue( $this->object->setMultiple( ['key' => 'value'], $expires, ['tag'] ) ); |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
|
183
|
|
|
public function testSetMultipleWithSiteId() |
184
|
|
|
{ |
185
|
|
|
$object = new \Aimeos\Base\Cache\Typo3( array( 'siteid' => 1 ), $this->mock ); |
186
|
|
|
|
187
|
|
|
$this->mock->expects( $this->once() )->method( 'set' ) |
188
|
|
|
->with( |
189
|
|
|
$this->equalTo( '1-key' ), $this->equalTo( 'value' ), |
190
|
|
|
$this->equalTo( array( '1-siteid', '1-tag' ) ), $this->equalTo( null ) |
191
|
|
|
); |
192
|
|
|
|
193
|
|
|
$this->assertTrue( $object->setMultiple( ['key' => 'value'], null, ['tag'] ) ); |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
} |
197
|
|
|
|