MediaWiki  1.32.5
MemcachedBagOStuffTest.php
Go to the documentation of this file.
1 <?php
7  private $cache;
8 
9  protected function setUp() {
10  parent::setUp();
11  $this->cache = new MemcachedBagOStuff( [ 'keyspace' => 'test' ] );
12  }
13 
17  public function testKeyNormalization() {
18  $this->assertEquals(
19  'test:vanilla',
20  $this->cache->makeKey( 'vanilla' )
21  );
22 
23  $this->assertEquals(
24  'test:punctuation_marks_are_ok:!@$^&*()',
25  $this->cache->makeKey( 'punctuation_marks_are_ok', '!@$^&*()' )
26  );
27 
28  $this->assertEquals(
29  'test:but_spaces:hashes%23:and%0Anewlines:are_not',
30  $this->cache->makeKey( 'but spaces', 'hashes#', "and\nnewlines", 'are_not' )
31  );
32 
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' )
37  );
38 
39  $this->assertEquals(
40  'test:this:key:contains:#c118f92685a635cb843039de50014c9c',
41  $this->cache->makeKey( 'this', 'key', 'contains', '𝕥𝕠𝕠 𝕞𝕒𝕟𝕪 𝕞𝕦𝕝𝕥𝕚𝕓𝕪𝕥𝕖 𝕔𝕙𝕒𝕣𝕒𝕔𝕥𝕖𝕣𝕤' )
42  );
43 
44  $this->assertEquals(
45  'test:BagOStuff-long-key:##dc89dcb43b28614da27660240af478b5',
46  $this->cache->makeKey( '𝕖𝕧𝕖𝕟', '𝕚𝕗', '𝕨𝕖', '𝕄𝔻𝟝', '𝕖𝕒𝕔𝕙',
47  '𝕒𝕣𝕘𝕦𝕞𝕖𝕟𝕥', '𝕥𝕙𝕚𝕤', '𝕜𝕖𝕪', '𝕨𝕠𝕦𝕝𝕕', '𝕤𝕥𝕚𝕝𝕝', '𝕓𝕖', '𝕥𝕠𝕠', '𝕝𝕠𝕟𝕘' )
48  );
49 
50  $this->assertEquals(
51  'test:%23%235820ad1d105aa4dc698585c39df73e19',
52  $this->cache->makeKey( '##5820ad1d105aa4dc698585c39df73e19' )
53  );
54 
55  $this->assertEquals(
56  'test:percent_is_escaped:!@$%25^&*()',
57  $this->cache->makeKey( 'percent_is_escaped', '!@$%^&*()' )
58  );
59 
60  $this->assertEquals(
61  'test:colon_is_escaped:!@$%3A^&*()',
62  $this->cache->makeKey( 'colon_is_escaped', '!@$:^&*()' )
63  );
64 
65  $this->assertEquals(
66  'test:long_key_part_hashed:#0244f7b1811d982dd932dd7de01465ac',
67  $this->cache->makeKey( 'long_key_part_hashed', str_repeat( 'y', 500 ) )
68  );
69  }
70 
75  public function testValidateKeyEncoding( $key ) {
76  $this->assertSame( $key, $this->cache->validateKeyEncoding( $key ) );
77  }
78 
79  public function validKeyProvider() {
80  return [
81  'empty' => [ '' ],
82  'digits' => [ '09' ],
83  'letters' => [ 'AZaz' ],
84  'ASCII special characters' => [ '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~' ],
85  ];
86  }
87 
92  public function testValidateKeyEncodingThrowsException( $key ) {
93  $this->setExpectedException( Exception::class );
94  $this->cache->validateKeyEncoding( $key );
95  }
96 
97  public function invalidKeyProvider() {
98  return [
99  [ "\x00" ],
100  [ ' ' ],
101  [ "\x1F" ],
102  [ "\x7F" ],
103  [ "\x80" ],
104  [ "\xFF" ],
105  ];
106  }
107 }
MemcachedBagOStuff
Base class for memcached clients.
Definition: MemcachedBagOStuff.php:29
cache
you have access to all of the normal MediaWiki so you can get a DB use the cache
Definition: maintenance.txt:52
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
MemcachedBagOStuffTest\setUp
setUp()
Definition: MemcachedBagOStuffTest.php:9
MemcachedBagOStuffTest\invalidKeyProvider
invalidKeyProvider()
Definition: MemcachedBagOStuffTest.php:97
MediaWikiTestCase
Definition: MediaWikiTestCase.php:16
MemcachedBagOStuffTest\$cache
MemcachedBagOStuff $cache
Definition: MemcachedBagOStuffTest.php:7
MemcachedBagOStuffTest\testValidateKeyEncoding
testValidateKeyEncoding( $key)
validKeyProvider MemcachedBagOStuff::validateKeyEncoding
Definition: MemcachedBagOStuffTest.php:75
MemcachedBagOStuffTest\testKeyNormalization
testKeyNormalization()
MemcachedBagOStuff::makeKey.
Definition: MemcachedBagOStuffTest.php:17
MemcachedBagOStuffTest\testValidateKeyEncodingThrowsException
testValidateKeyEncodingThrowsException( $key)
invalidKeyProvider MemcachedBagOStuff::validateKeyEncoding
Definition: MemcachedBagOStuffTest.php:92
MemcachedBagOStuffTest\validKeyProvider
validKeyProvider()
Definition: MemcachedBagOStuffTest.php:79
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
MemcachedBagOStuffTest
BagOStuff.
Definition: MemcachedBagOStuffTest.php:5