WordPress.org

Make WordPress Core

Changeset 280 in tests


Ignore:
Timestamp:
12/22/09 16:11:03 (5 years ago)
Author:
westi
Message:

Add extra object cache tests. Props Denis-de-Bernardy.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wp-testcase/test_includes_cache.php

    r170 r280  
    3333    } 
    3434 
     35    function test_add_get_0() { 
     36        $key = rand_str(); 
     37        $val = 0; 
     38 
     39        // you can store zero in the cache 
     40        $this->cache->add($key, $val); 
     41        $this->assertEquals($val, $this->cache->get($key)); 
     42    } 
     43 
     44    function test_add_get_null() { 
     45        $key = rand_str(); 
     46        $val = null; 
     47 
     48        // you can't store null in the cache 
     49        $this->assertFalse($this->cache->add($key, $val)); 
     50        $this->assertFalse($this->cache->get($key)); 
     51    } 
     52 
     53    function test_add() { 
     54        $key = rand_str(); 
     55        $val1 = rand_str(); 
     56        $val2 = rand_str(); 
     57 
     58        // add $key to the cache 
     59        $this->assertTrue($this->cache->add($key, $val1)); 
     60        $this->assertEquals($val1, $this->cache->get($key)); 
     61        // $key is in the cache, so reject new calls to add() 
     62        $this->assertFalse($this->cache->add($key, $val2)); 
     63        $this->assertEquals($val1, $this->cache->get($key)); 
     64    } 
     65 
     66    function test_replace() { 
     67        $key = rand_str(); 
     68        $val = rand_str(); 
     69 
     70        // memcached rejects replace() if the key does not exist 
     71        $this->assertFalse($this->cache->replace($key, $val)); 
     72        $this->assertFalse($this->cache->get($key)); 
     73    } 
     74 
     75    function test_set() { 
     76        $key = rand_str(); 
     77        $val = rand_str(); 
     78 
     79        // memcached accepts set() if the key does not exist 
     80        $this->assertTrue($this->cache->set($key, $val)); 
     81        $this->assertEquals($val, $this->cache->get($key)); 
     82    } 
     83 
    3584    function test_flush() { 
    3685        $key = rand_str(); 
     
    4190        $this->assertEquals($val, $this->cache->get($key)); 
    4291        $this->cache->flush(); 
    43         $this->assertEquals(NULL, $this->cache->get($key)); 
     92        // If there is no value get returns false. 
     93        $this->assertFalse($this->cache->get($key)); 
    4494    } 
    4595 
Note: See TracChangeset for help on using the changeset viewer.