1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace PhpMyAdmin\MoTranslator\Tests\Cache; |
6
|
|
|
|
7
|
|
|
use PhpMyAdmin\MoTranslator\Cache\InMemoryCache; |
8
|
|
|
use PhpMyAdmin\MoTranslator\MoParser; |
9
|
|
|
use PHPUnit\Framework\TestCase; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @covers \PhpMyAdmin\MoTranslator\Cache\InMemoryCache |
13
|
|
|
*/ |
14
|
|
|
class InMemoryCacheTest extends TestCase |
15
|
|
|
{ |
16
|
|
|
public function testConstructorParsesCache(): void |
17
|
|
|
{ |
18
|
|
|
$expected = 'Pole'; |
19
|
|
|
$parser = new MoParser(__DIR__ . '/../data/little.mo'); |
20
|
|
|
$cache = new InMemoryCache($parser); |
21
|
|
|
$actual = $cache->get('Column'); |
22
|
|
|
$this->assertSame($expected, $actual); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function testGetReturnsMsgidForCacheMiss(): void |
26
|
|
|
{ |
27
|
|
|
$expected = 'Column'; |
28
|
|
|
$cache = new InMemoryCache(new MoParser(null)); |
29
|
|
|
$actual = $cache->get($expected); |
30
|
|
|
$this->assertSame($expected, $actual); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function testSetSetsMsgstr(): void |
34
|
|
|
{ |
35
|
|
|
$expected = 'Pole'; |
36
|
|
|
$msgid = 'Column'; |
37
|
|
|
$cache = new InMemoryCache(new MoParser(null)); |
38
|
|
|
$cache->set($msgid, $expected); |
39
|
|
|
$actual = $cache->get($msgid); |
40
|
|
|
$this->assertSame($expected, $actual); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function testHasReturnsFalse(): void |
44
|
|
|
{ |
45
|
|
|
$cache = new InMemoryCache(new MoParser(null)); |
46
|
|
|
$actual = $cache->has('Column'); |
47
|
|
|
$this->assertFalse($actual); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function testHasReturnsTrue(): void |
51
|
|
|
{ |
52
|
|
|
$cache = new InMemoryCache(new MoParser(__DIR__ . '/../data/little.mo')); |
53
|
|
|
$actual = $cache->has('Column'); |
54
|
|
|
$this->assertTrue($actual); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function testSetAllSetsTranslations(): void |
58
|
|
|
{ |
59
|
|
|
$translations = [ |
60
|
|
|
'foo' => 'bar', |
61
|
|
|
'and' => 'another', |
62
|
|
|
]; |
63
|
|
|
$cache = new InMemoryCache(new MoParser(null)); |
64
|
|
|
$cache->setAll($translations); |
65
|
|
|
foreach ($translations as $msgid => $expected) { |
66
|
|
|
$actual = $cache->get($msgid); |
67
|
|
|
$this->assertEquals($expected, $actual); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function testGetAllReturnsTranslations(): void |
72
|
|
|
{ |
73
|
|
|
$expected = [ |
74
|
|
|
'foo' => 'bar', |
75
|
|
|
'and' => 'another', |
76
|
|
|
]; |
77
|
|
|
$cache = new InMemoryCache(new MoParser(null)); |
78
|
|
|
$cache->setAll($expected); |
79
|
|
|
$actual = $cache->getAll(); |
80
|
|
|
$this->assertSame($expected, $actual); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|