Permalink
Browse files

MDL-38165 cache: added unit tests for event purging of persistent caches

  • Loading branch information...
Sam Hemelryk
Sam Hemelryk committed Feb 28, 2013
1 parent f9bbcc5 commit fcb404faac6f228ce3546f3f46668318acc97f76
Showing with 75 additions and 1 deletion.
  1. +74 −0 cache/tests/cache_test.php
  2. +1 −1 cache/tests/fixtures/lib.php
View
@@ -627,6 +627,66 @@ public function test_application_event_purge() {
'crazyevent'
)
));
+ $instance->phpunit_add_definition('phpunit/eventpurgetestpersistent', array(
+ 'mode' => cache_store::MODE_APPLICATION,
+ 'component' => 'phpunit',
+ 'area' => 'eventpurgetestpersistent',
+ 'persistent' => true,
+ 'invalidationevents' => array(
+ 'crazyevent'
+ )
+ ));
+ $cache = cache::make('phpunit', 'eventpurgetest');
+
+ $this->assertTrue($cache->set('testkey1', 'test data 1'));
+ $this->assertEquals('test data 1', $cache->get('testkey1'));
+ $this->assertTrue($cache->set('testkey2', 'test data 2'));
+ $this->assertEquals('test data 2', $cache->get('testkey2'));
+
+ // Purge the event.
+ cache_helper::purge_by_event('crazyevent');
+
+ // Check things have been removed.
+ $this->assertFalse($cache->get('testkey1'));
+ $this->assertFalse($cache->get('testkey2'));
+
+ // Now test the persistent cache.
+ $cache = cache::make('phpunit', 'eventpurgetestpersistent');
+ $this->assertTrue($cache->set('testkey1', 'test data 1'));
+ $this->assertEquals('test data 1', $cache->get('testkey1'));
+ $this->assertTrue($cache->set('testkey2', 'test data 2'));
+ $this->assertEquals('test data 2', $cache->get('testkey2'));
+
+ // Purge the event.
+ cache_helper::purge_by_event('crazyevent');
+
+ // Check things have been removed.
+ $this->assertFalse($cache->get('testkey1'));
+ $this->assertFalse($cache->get('testkey2'));
+ }
+
+ /**
+ * Tests session cache event purge
+ */
+ public function test_session_event_purge() {
+ $instance = cache_config_phpunittest::instance();
+ $instance->phpunit_add_definition('phpunit/eventpurgetest', array(
+ 'mode' => cache_store::MODE_SESSION,
+ 'component' => 'phpunit',
+ 'area' => 'eventpurgetest',
+ 'invalidationevents' => array(
+ 'crazyevent'
+ )
+ ));
+ $instance->phpunit_add_definition('phpunit/eventpurgetestpersistent', array(
+ 'mode' => cache_store::MODE_SESSION,
+ 'component' => 'phpunit',
+ 'area' => 'eventpurgetestpersistent',
+ 'persistent' => true,
+ 'invalidationevents' => array(
+ 'crazyevent'
+ )
+ ));
$cache = cache::make('phpunit', 'eventpurgetest');
$this->assertTrue($cache->set('testkey1', 'test data 1'));
@@ -640,6 +700,20 @@ public function test_application_event_purge() {
// Check things have been removed.
$this->assertFalse($cache->get('testkey1'));
$this->assertFalse($cache->get('testkey2'));
+
+ // Now test the persistent cache.
+ $cache = cache::make('phpunit', 'eventpurgetestpersistent');
+ $this->assertTrue($cache->set('testkey1', 'test data 1'));
+ $this->assertEquals('test data 1', $cache->get('testkey1'));
+ $this->assertTrue($cache->set('testkey2', 'test data 2'));
+ $this->assertEquals('test data 2', $cache->get('testkey2'));
+
+ // Purge the event.
+ cache_helper::purge_by_event('crazyevent');
+
+ // Check things have been removed.
+ $this->assertFalse($cache->get('testkey1'));
+ $this->assertFalse($cache->get('testkey2'));
}
/**
@@ -46,7 +46,7 @@ public function phpunit_add_definition($area, array $properties) {
case cache_store::MODE_APPLICATION:
$properties['overrideclass'] = 'cache_phpunit_application';
break;
- case cache_store::MDOE_SESSION:
+ case cache_store::MODE_SESSION:
$properties['overrideclass'] = 'cache_phpunit_session';
break;
case cache_store::MODE_REQUEST:

0 comments on commit fcb404f

Please sign in to comment.