Add tests for MemcachedBagOStuff::validateKeyEncoding
authorThiemo Mättig <thiemo.maettig@wikimedia.de>
Wed, 28 Oct 2015 15:26:37 +0000 (16:26 +0100)
committerThiemo Mättig <thiemo.maettig@wikimedia.de>
Wed, 28 Oct 2015 17:12:35 +0000 (18:12 +0100)
If3e20c6 and the following patches introduced a breaking change and
cause a regression in Wikibase because we are using the version number
constant as part of a cache key prefix. Currently the Wikibase version
is set to "0.5 alpha".

Space characters were allowed before and encoded as "%20". This does
not happen any more.

Change-Id: Ia2fd4ed6738a10e02050bced947ef5d4e8b98980

tests/phpunit/includes/objectcache/MemcachedBagOStuffTest.php

index b0c9e4f..3e3bac3 100644 (file)
@@ -12,7 +12,7 @@ class MemcachedBagOStuffTest extends MediaWikiTestCase {
        }
 
        /**
-        * @covers MemcachedBagOStuff::makeKeyInternal
+        * @covers MemcachedBagOStuff::makeKey
         */
        public function testKeyNormalization() {
                $this->assertEquals(
@@ -67,4 +67,39 @@ class MemcachedBagOStuffTest extends MediaWikiTestCase {
                        $this->cache->makeKey( 'long_key_part_hashed', str_repeat( 'y', 500 ) )
                );
        }
+
+       /**
+        * @dataProvider validKeyProvider
+        */
+       public function testValidateKeyEncoding( $key ) {
+               $this->assertSame( $key, $this->cache->validateKeyEncoding( $key ) );
+       }
+
+       public function validKeyProvider() {
+               return array(
+                       'empty' => array( '' ),
+                       'digits' => array( '09' ),
+                       'letters' => array( 'AZaz' ),
+                       'ASCII special characters' => array( '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~' ),
+               );
+       }
+
+       /**
+        * @dataProvider invalidKeyProvider
+        */
+       public function testValidateKeyEncodingThrowsException( $key ) {
+               $this->setExpectedException( 'Exception' );
+               $this->cache->validateKeyEncoding( $key );
+       }
+
+       public function invalidKeyProvider() {
+               return array(
+                       array( "\x00" ),
+                       array( ' ' ),
+                       array( "\x1F" ),
+                       array( "\x7F" ),
+                       array( "\x80" ),
+                       array( "\xFF" ),
+               );
+       }
 }