| | 56 | function test_get_multi_single_with_bad_key() { |
| | 57 | $key = rand_str(); |
| | 58 | $this->assertFalse( $this->cache->get_multi( $key ) ); |
| | 59 | } |
| | 60 | |
| | 61 | function test_get_multi_single_with_bad_key_and_group() { |
| | 62 | $key = rand_str(); |
| | 63 | $group = rand_str(); |
| | 64 | $this->assertFalse( $this->cache->get_multi( $key, $group ) ); |
| | 65 | } |
| | 66 | |
| | 67 | function test_get_multi_single_value_no_group() { |
| | 68 | $key = rand_str(); |
| | 69 | $val = rand_str(); |
| | 70 | |
| | 71 | $this->assertTrue( $this->cache->set( $key, $val ) ); |
| | 72 | |
| | 73 | $values = $this->cache->get_multi( $key ); |
| | 74 | $this->assertSame( $val, $values[ 'default' ][ $key ] ); |
| | 75 | } |
| | 76 | |
| | 77 | function test_get_multi_single_value_single_group() { |
| | 78 | $key = rand_str(); |
| | 79 | $val = rand_str(); |
| | 80 | |
| | 81 | $group = rand_str(); |
| | 82 | |
| | 83 | $this->assertTrue( $this->cache->set( $key, $val, $group ) ); |
| | 84 | |
| | 85 | $values = $this->cache->get_multi( $key, $group ); |
| | 86 | $this->assertSame( $val, $values[ $group ][ $key ] ); |
| | 87 | } |
| | 88 | |
| | 89 | function test_get_multi_many_values_with_no_group() { |
| | 90 | $vals_with_keys = array(); |
| | 91 | |
| | 92 | for ( $i = 0; $i < 5; $i++ ) { |
| | 93 | $rand = rand_str(); |
| | 94 | $vals_with_keys[ $rand ] = rand_str(); |
| | 95 | } |
| | 96 | |
| | 97 | foreach ( $vals_with_keys as $key => $val ) |
| | 98 | $this->assertTrue( $this->cache->set( $key, $val ) ); |
| | 99 | |
| | 100 | $gets = $this->cache->get_multi( array_keys( $vals_with_keys ) ); |
| | 101 | |
| | 102 | // Verify array type |
| | 103 | $this->assertContainsOnly( 'array', $gets ); |
| | 104 | |
| | 105 | // Verify individual values |
| | 106 | foreach ( $gets as $group => $key_value ) { |
| | 107 | foreach ( $key_value as $key => $value ) { |
| | 108 | $this->assertSame( $vals_with_keys[ $key ], $value ); |
| | 109 | } |
| | 110 | } |
| | 111 | } |
| | 112 | |
| | 113 | function test_get_multi_many_values_with_single_group() { |
| | 114 | $vals_with_keys = array(); |
| | 115 | $group = rand_str(); |
| | 116 | |
| | 117 | for ( $i = 0; $i < 5; $i++ ) { |
| | 118 | $rand = rand_str(); |
| | 119 | $vals_with_keys[ $rand ] = rand_str(); |
| | 120 | } |
| | 121 | |
| | 122 | // Verify sets |
| | 123 | foreach ( $vals_with_keys as $key => $val ) |
| | 124 | $this->assertTrue( $this->cache->set( $key, $val, $group ) ); |
| | 125 | |
| | 126 | // Verify accessible by normal get |
| | 127 | foreach ( $vals_with_keys as $key => $val ) |
| | 128 | $this->assertSame( $val, $this->cache->get( $key, $group ) ); |
| | 129 | |
| | 130 | $gets = $this->cache->get_multi( array_keys( $vals_with_keys ), $group ); |
| | 131 | |
| | 132 | // Verify array type |
| | 133 | $this->assertContainsOnly( 'array', $gets ); |
| | 134 | |
| | 135 | // Verify individual values |
| | 136 | foreach ( $gets as $group => $key_value ) { |
| | 137 | foreach ( $key_value as $key => $value ) { |
| | 138 | $this->assertSame( $vals_with_keys[ $key ], $value ); |
| | 139 | } |
| | 140 | } |
| | 141 | } |
| | 142 | |
| | 143 | function test_get_multi_many_values_with_unique_groups() { |
| | 144 | $vals_with_keys_and_groups = array(); |
| | 145 | $keys = array(); |
| | 146 | $groups = array(); |
| | 147 | |
| | 148 | for ( $i = 0; $i < 5; $i++ ) { |
| | 149 | $key = rand_str(); |
| | 150 | $group = rand_str(); |
| | 151 | $vals_with_keys_and_groups[ $group ][ $key ] = rand_str(); |
| | 152 | |
| | 153 | $keys[] = $key; |
| | 154 | $groups[] = $group; |
| | 155 | } |
| | 156 | |
| | 157 | // Verify sets |
| | 158 | foreach ( $vals_with_keys_and_groups as $group => $val_with_key ) { |
| | 159 | foreach ( $val_with_key as $key => $value ) { |
| | 160 | $this->assertTrue( $this->cache->set( $key, $value, $group ) ); |
| | 161 | } |
| | 162 | } |
| | 163 | |
| | 164 | // Verify accessible by normal get |
| | 165 | foreach ( $vals_with_keys_and_groups as $group => $val_with_key ) { |
| | 166 | foreach ( $val_with_key as $key => $value ) { |
| | 167 | $this->assertSame( $vals_with_keys_and_groups[ $group ][ $key ], $this->cache->get( $key, $group ) ); |
| | 168 | } |
| | 169 | } |
| | 170 | |
| | 171 | $gets = $this->cache->get_multi( $keys, $groups ); |
| | 172 | |
| | 173 | // Verify array type |
| | 174 | $this->assertContainsOnly( 'array', $gets ); |
| | 175 | |
| | 176 | // Verify individual values |
| | 177 | foreach ( $gets as $group => $val_with_key ) { |
| | 178 | foreach ( $val_with_key as $key => $val ) { |
| | 179 | $this->assertSame( $vals_with_keys_and_groups[ $group ][ $key ], $val ); |
| | 180 | } |
| | 181 | } |
| | 182 | } |
| | 183 | |
| | 184 | function test_get_multi_many_values_with_unique_and_default_groups() { |
| | 185 | $vals_with_keys_and_groups = array(); |
| | 186 | $keys = array(); |
| | 187 | $groups = array(); |
| | 188 | |
| | 189 | for ( $i = 0; $i < 5; $i++ ) { |
| | 190 | $key = rand_str(); |
| | 191 | $group = $i < 3 ? rand_str() : 'default'; |
| | 192 | |
| | 193 | $vals_with_keys_and_groups[ $group ][ $key ] = rand_str(); |
| | 194 | |
| | 195 | $keys[] = $key; |
| | 196 | $groups[] = $group; |
| | 197 | } |
| | 198 | |
| | 199 | // Verify sets |
| | 200 | foreach ( $vals_with_keys_and_groups as $group => $val_with_key ) { |
| | 201 | foreach ( $val_with_key as $key => $value ) { |
| | 202 | $this->assertTrue( $this->cache->set( $key, $value, $group ) ); |
| | 203 | } |
| | 204 | } |
| | 205 | |
| | 206 | // Verify accessible by normal get |
| | 207 | foreach ( $vals_with_keys_and_groups as $group => $val_with_key ) { |
| | 208 | foreach ( $val_with_key as $key => $value ) { |
| | 209 | $this->assertSame( $vals_with_keys_and_groups[ $group ][ $key ], $this->cache->get( $key, $group ) ); |
| | 210 | } |
| | 211 | } |
| | 212 | |
| | 213 | $gets = $this->cache->get_multi( $keys, $groups ); |
| | 214 | |
| | 215 | // Verify array type |
| | 216 | $this->assertContainsOnly( 'array', $gets ); |
| | 217 | |
| | 218 | // Verify individual values |
| | 219 | foreach ( $gets as $group => $val_with_key ) { |
| | 220 | foreach ( $val_with_key as $key => $val ) { |
| | 221 | $this->assertSame( $vals_with_keys_and_groups[ $group ][ $key ], $val ); |
| | 222 | } |
| | 223 | } |
| | 224 | } |
| | 225 | |