-
Notifications
You must be signed in to change notification settings - Fork 638
/
StringFrontendTest.php
130 lines (120 loc) · 5.44 KB
/
StringFrontendTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?php
namespace TYPO3\CMS\Core\Tests\UnitDeprecated\Cache\Frontend;
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
use TYPO3\CMS\Core\Cache\Exception\InvalidDataException;
/**
* Testcase for the string cache frontend
*
* This file is a backport from FLOW3
*/
class StringFrontendTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
{
/**
* @test
*/
public function setChecksIfTheIdentifierIsValid()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionCode(1233057566);
$cache = $this->getMockBuilder(\TYPO3\CMS\Core\Cache\Frontend\StringFrontend::class)
->setMethods(['isValidEntryIdentifier'])
->disableOriginalConstructor()
->getMock();
$cache->expects($this->once())->method('isValidEntryIdentifier')->with('foo')->will($this->returnValue(false));
$cache->set('foo', 'bar');
}
/**
* @test
*/
public function setPassesStringToBackend()
{
$theString = 'Just some value';
$backend = $this->getMockBuilder(\TYPO3\CMS\Core\Cache\Backend\AbstractBackend::class)
->setMethods(['get', 'set', 'has', 'remove', 'findIdentifiersByTag', 'flush', 'flushByTag', 'collectGarbage'])
->disableOriginalConstructor()
->getMock();
$backend->expects($this->once())->method('set')->with($this->equalTo('StringCacheTest'), $this->equalTo($theString));
$cache = new \TYPO3\CMS\Core\Cache\Frontend\StringFrontend('StringFrontend', $backend);
$cache->set('StringCacheTest', $theString);
}
/**
* @test
*/
public function setPassesLifetimeToBackend()
{
$theString = 'Just some value';
$theLifetime = 1234;
$backend = $this->getMockBuilder(\TYPO3\CMS\Core\Cache\Backend\AbstractBackend::class)
->setMethods(['get', 'set', 'has', 'remove', 'findIdentifiersByTag', 'flush', 'flushByTag', 'collectGarbage'])
->disableOriginalConstructor()
->getMock();
$backend->expects($this->once())->method('set')->with($this->equalTo('StringCacheTest'), $this->equalTo($theString), $this->equalTo([]), $this->equalTo($theLifetime));
$cache = new \TYPO3\CMS\Core\Cache\Frontend\StringFrontend('StringFrontend', $backend);
$cache->set('StringCacheTest', $theString, [], $theLifetime);
}
/**
* @test
*/
public function setThrowsInvalidDataExceptionOnNonStringValues()
{
$this->expectException(InvalidDataException::class);
$this->expectExceptionCode(1222808333);
$backend = $this->getMockBuilder(\TYPO3\CMS\Core\Cache\Backend\AbstractBackend::class)
->setMethods(['get', 'set', 'has', 'remove', 'findIdentifiersByTag', 'flush', 'flushByTag', 'collectGarbage'])
->disableOriginalConstructor()
->getMock();
$cache = new \TYPO3\CMS\Core\Cache\Frontend\StringFrontend('StringFrontend', $backend);
$cache->set('StringCacheTest', []);
}
/**
* @test
*/
public function getFetchesStringValueFromBackend()
{
$backend = $this->getMockBuilder(\TYPO3\CMS\Core\Cache\Backend\AbstractBackend::class)
->setMethods(['get', 'set', 'has', 'remove', 'findIdentifiersByTag', 'flush', 'flushByTag', 'collectGarbage'])
->disableOriginalConstructor()
->getMock();
$backend->expects($this->once())->method('get')->will($this->returnValue('Just some value'));
$cache = new \TYPO3\CMS\Core\Cache\Frontend\StringFrontend('StringFrontend', $backend);
$this->assertEquals('Just some value', $cache->get('StringCacheTest'), 'The returned value was not the expected string.');
}
/**
* @test
*/
public function hasReturnsResultFromBackend()
{
$backend = $this->getMockBuilder(\TYPO3\CMS\Core\Cache\Backend\AbstractBackend::class)
->setMethods(['get', 'set', 'has', 'remove', 'findIdentifiersByTag', 'flush', 'flushByTag', 'collectGarbage'])
->disableOriginalConstructor()
->getMock();
$backend->expects($this->once())->method('has')->with($this->equalTo('StringCacheTest'))->will($this->returnValue(true));
$cache = new \TYPO3\CMS\Core\Cache\Frontend\StringFrontend('StringFrontend', $backend);
$this->assertTrue($cache->has('StringCacheTest'), 'has() did not return TRUE.');
}
/**
* @test
*/
public function removeCallsBackend()
{
$cacheIdentifier = 'someCacheIdentifier';
$backend = $this->getMockBuilder(\TYPO3\CMS\Core\Cache\Backend\AbstractBackend::class)
->setMethods(['get', 'set', 'has', 'remove', 'findIdentifiersByTag', 'flush', 'flushByTag', 'collectGarbage'])
->disableOriginalConstructor()
->getMock();
$backend->expects($this->once())->method('remove')->with($this->equalTo($cacheIdentifier))->will($this->returnValue(true));
$cache = new \TYPO3\CMS\Core\Cache\Frontend\StringFrontend('StringFrontend', $backend);
$this->assertTrue($cache->remove($cacheIdentifier), 'remove() did not return TRUE');
}
}