rdbms: Rename "memCache" to "memStash" in LBFactory
[mediawiki.git] / tests / phpunit / includes / objectcache / MemcachedBagOStuffTest.php
blob7814b83051ef59f7878929e98f0576c238e0b17d
1 <?php
2 /**
3 * @group BagOStuff
4 */
5 class MemcachedBagOStuffTest extends MediaWikiTestCase {
6 /** @var MemcachedBagOStuff */
7 private $cache;
9 protected function setUp() {
10 parent::setUp();
11 $this->cache = new MemcachedBagOStuff( [ 'keyspace' => 'test' ] );
14 /**
15 * @covers MemcachedBagOStuff::makeKey
17 public function testKeyNormalization() {
18 $this->assertEquals(
19 'test:vanilla',
20 $this->cache->makeKey( 'vanilla' )
23 $this->assertEquals(
24 'test:punctuation_marks_are_ok:!@$^&*()',
25 $this->cache->makeKey( 'punctuation_marks_are_ok', '!@$^&*()' )
28 $this->assertEquals(
29 'test:but_spaces:hashes%23:and%0Anewlines:are_not',
30 $this->cache->makeKey( 'but spaces', 'hashes#', "and\nnewlines", 'are_not' )
33 $this->assertEquals(
34 'test:this:key:contains:%F0%9D%95%9E%F0%9D%95%A6%F0%9D%95%9D%F0%9D%95%A5%F0%9' .
35 'D%95%9A%F0%9D%95%93%F0%9D%95%AA%F0%9D%95%A5%F0%9D%95%96:characters',
36 $this->cache->makeKey( 'this', 'key', 'contains', '𝕞𝕦𝕝𝕥𝕚𝕓𝕪𝕥𝕖', 'characters' )
39 $this->assertEquals(
40 'test:this:key:contains:#c118f92685a635cb843039de50014c9c',
41 $this->cache->makeKey( 'this', 'key', 'contains', '𝕥𝕠𝕠 𝕞𝕒𝕟𝕪 𝕞𝕦𝕝𝕥𝕚𝕓𝕪𝕥𝕖 𝕔𝕙𝕒𝕣𝕒𝕔𝕥𝕖𝕣𝕤' )
44 $this->assertEquals(
45 'test:##dc89dcb43b28614da27660240af478b5',
46 $this->cache->makeKey( '𝕖𝕧𝕖𝕟', '𝕚𝕗', '𝕨𝕖', '𝕄𝔻𝟝', '𝕖𝕒𝕔𝕙',
47 '𝕒𝕣𝕘𝕦𝕞𝕖𝕟𝕥', '𝕥𝕙𝕚𝕤', '𝕜𝕖𝕪', '𝕨𝕠𝕦𝕝𝕕', '𝕤𝕥𝕚𝕝𝕝', '𝕓𝕖', '𝕥𝕠𝕠', '𝕝𝕠𝕟𝕘' )
50 $this->assertEquals(
51 'test:%23%235820ad1d105aa4dc698585c39df73e19',
52 $this->cache->makeKey( '##5820ad1d105aa4dc698585c39df73e19' )
55 $this->assertEquals(
56 'test:percent_is_escaped:!@$%25^&*()',
57 $this->cache->makeKey( 'percent_is_escaped', '!@$%^&*()' )
60 $this->assertEquals(
61 'test:colon_is_escaped:!@$%3A^&*()',
62 $this->cache->makeKey( 'colon_is_escaped', '!@$:^&*()' )
65 $this->assertEquals(
66 'test:long_key_part_hashed:#0244f7b1811d982dd932dd7de01465ac',
67 $this->cache->makeKey( 'long_key_part_hashed', str_repeat( 'y', 500 ) )
71 /**
72 * @dataProvider validKeyProvider
74 public function testValidateKeyEncoding( $key ) {
75 $this->assertSame( $key, $this->cache->validateKeyEncoding( $key ) );
78 public function validKeyProvider() {
79 return [
80 'empty' => [ '' ],
81 'digits' => [ '09' ],
82 'letters' => [ 'AZaz' ],
83 'ASCII special characters' => [ '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~' ],
87 /**
88 * @dataProvider invalidKeyProvider
90 public function testValidateKeyEncodingThrowsException( $key ) {
91 $this->setExpectedException( 'Exception' );
92 $this->cache->validateKeyEncoding( $key );
95 public function invalidKeyProvider() {
96 return [
97 [ "\x00" ],
98 [ ' ' ],
99 [ "\x1F" ],
100 [ "\x7F" ],
101 [ "\x80" ],
102 [ "\xFF" ],