Make WordPress Core

Changeset 170 in tests for wp-testcase/test_includes_cache.php


Ignore:
Timestamp:
03/10/2008 08:43:16 AM (18 years ago)
Author:
nbachiyski
Message:

Remove persistent object cache tests

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wp-testcase/test_includes_cache.php

    r105 r170  
    88        // create two cache objects with a shared cache dir
    99        // this simulates a typical cache situation, two separate requests interacting
    10         $this->cache1 =& $this->init_cache();
    11         $this->cache2 =& $this->init_cache();
     10        $this->cache =& $this->init_cache();
    1211    }
    1312
     
    1918    function &init_cache() {
    2019        $cache = new WP_Object_cache();
    21         $cache->cache_enabled = true;
    22         $cache->cache_dir = '/tmp/wp_cache_test/';
    2320        return $cache;
    2421    }
    2522
    2623    function test_miss() {
    27         $this->assertEquals(NULL, $this->cache1->get(rand_str()));
     24        $this->assertEquals(NULL, $this->cache->get(rand_str()));
    2825    }
    2926
     
    3229        $val = rand_str();
    3330
    34         $this->cache1->add($key, $val);
    35         $this->cache1->save();
    36         $this->assertEquals($val, $this->cache2->get($key));
    37         $this->assertEquals($val, $this->cache1->get($key));
     31        $this->cache->add($key, $val);
     32        $this->assertEquals($val, $this->cache->get($key));
    3833    }
    3934
     
    4237        $val = rand_str();
    4338
    44         $this->cache1->add($key, $val);
    45         $this->cache1->save();
     39        $this->cache->add($key, $val);
    4640        // item is visible to both cache objects
    47         $this->assertEquals($val, $this->cache1->get($key));
    48         $this->cache1->flush();
    49         // flush affects both cache objects
    50         $this->assertEquals(NULL, $this->cache1->get($key));
    51         $this->assertEquals(NULL, $this->cache2->get($key));
     41        $this->assertEquals($val, $this->cache->get($key));
     42        $this->cache->flush();
     43        $this->assertEquals(NULL, $this->cache->get($key));
    5244    }
    5345
    54     function test_not_expired() {
    55         $key = rand_str();
    56         $val = rand_str();
    57 
    58         // expires in 1 second
    59         // nb: add() accepts an $expire parameter, but it doesn't work
    60         // so we have to set the expiration value for the whole cache
    61         // http://trac.wordpress.org/ticket/4179
    62         $this->cache1->expiration_time = 3; # seconds
    63         $this->cache2->expiration_time = 3;
    64         $this->assertTrue($this->cache1->add($key, $val));
    65         $this->assertTrue($this->cache1->save());
    66 
    67         // not yet expired
    68         $this->assertEquals($val, $this->cache1->get($key));
    69         $this->assertEquals($val, $this->cache2->get($key));
    70     }
    71 
    72     function test_expired() {
    73 
    74         $key = rand_str();
    75         $val = rand_str();
    76 
    77         // expires in 1 second
    78         $this->cache1->expiration_time = 1; # second
    79         $this->cache2->expiration_time = 1;
    80         $this->assertTrue($this->cache1->add($key, $val));
    81         $this->assertTrue($this->cache1->save());
    82 
    83         // 3 seconds later, key should have expired
    84         sleep(3);
    85         $this->assertEquals(NULL, $this->cache2->get($key));
    86         // cache1's key is still cached in memory, which doesn't expire
    87         $this->assertEquals($val, $this->cache1->get($key));
    88     }
    89 
    90     function test_individual_expiry() {
    91         // FIXME: this is a current bug
    92         $this->markTestSkipped();
    93 
    94         $key = rand_str();
    95         $val = rand_str();
    96 
    97         // http://trac.wordpress.org/ticket/4179
    98         // individual expiration parameters are ignored
    99         // this should expire after 1 second
    100         $this->assertTrue($this->cache1->add($key, $val, '', 1));
    101         $this->assertTrue($this->cache1->save());
    102 
    103         // not yet expired
    104         $this->assertEquals($val, $this->cache1->get($key));
    105         $this->assertEquals($val, $this->cache2->get($key));
    106 
    107         // 3 seconds later, key should have expired
    108         sleep(3);
    109         $this->assertEquals(NULL, $this->cache2->get($key));
    110         // cache1's key is still cached in memory, which doesn't expire
    111         $this->assertEquals($val, $this->cache1->get($key));
    112     }
    11346}
    11447
Note: See TracChangeset for help on using the changeset viewer.