Add @covers tags to objectcache tests
[lhc/web/wiklou.git] / tests / phpunit / includes / objectcache / MemcachedBagOStuffTest.php
index b0c9e4f..7eb5582 100644 (file)
@@ -8,11 +8,11 @@ class MemcachedBagOStuffTest extends MediaWikiTestCase {
 
        protected function setUp() {
                parent::setUp();
-               $this->cache = new MemcachedBagOStuff( array( 'keyspace' => 'test' ) );
+               $this->cache = new MemcachedBagOStuff( [ 'keyspace' => 'test' ] );
        }
 
        /**
-        * @covers MemcachedBagOStuff::makeKeyInternal
+        * @covers MemcachedBagOStuff::makeKey
         */
        public function testKeyNormalization() {
                $this->assertEquals(
@@ -42,7 +42,7 @@ class MemcachedBagOStuffTest extends MediaWikiTestCase {
                );
 
                $this->assertEquals(
-                       'test:##5820ad1d105aa4dc698585c39df73e19',
+                       'test:BagOStuff-long-key:##dc89dcb43b28614da27660240af478b5',
                        $this->cache->makeKey( '𝕖𝕧𝕖𝕟', '𝕚𝕗', '𝕨𝕖', '𝕄𝔻𝟝', '𝕖𝕒𝕔𝕙',
                                '𝕒𝕣𝕘𝕦𝕞𝕖𝕟𝕥', '𝕥𝕙𝕚𝕤', '𝕜𝕖𝕪', '𝕨𝕠𝕦𝕝𝕕', '𝕤𝕥𝕚𝕝𝕝', '𝕓𝕖', '𝕥𝕠𝕠', '𝕝𝕠𝕟𝕘' )
                );
@@ -67,4 +67,41 @@ class MemcachedBagOStuffTest extends MediaWikiTestCase {
                        $this->cache->makeKey( 'long_key_part_hashed', str_repeat( 'y', 500 ) )
                );
        }
+
+       /**
+        * @dataProvider validKeyProvider
+        * @covers MemcachedBagOStuff::validateKeyEncoding
+        */
+       public function testValidateKeyEncoding( $key ) {
+               $this->assertSame( $key, $this->cache->validateKeyEncoding( $key ) );
+       }
+
+       public function validKeyProvider() {
+               return [
+                       'empty' => [ '' ],
+                       'digits' => [ '09' ],
+                       'letters' => [ 'AZaz' ],
+                       'ASCII special characters' => [ '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~' ],
+               ];
+       }
+
+       /**
+        * @dataProvider invalidKeyProvider
+        * @covers MemcachedBagOStuff::validateKeyEncoding
+        */
+       public function testValidateKeyEncodingThrowsException( $key ) {
+               $this->setExpectedException( 'Exception' );
+               $this->cache->validateKeyEncoding( $key );
+       }
+
+       public function invalidKeyProvider() {
+               return [
+                       [ "\x00" ],
+                       [ ' ' ],
+                       [ "\x1F" ],
+                       [ "\x7F" ],
+                       [ "\x80" ],
+                       [ "\xFF" ],
+               ];
+       }
 }