public function CacheFlushRulesEvents::testEvents in CacheFlush 7.3
Test the events.
File
- modules/
cacheflush_rules/ cacheflush_rules.test, line 37 - Contains test suite for cacheflush rules module.
Class
- CacheFlushRulesEvents
- Test the Rules integration.
Code
public function testEvents() {
module_load_include('inc', 'cacheflush', 'cacheflush.api');
// Create test user.
$user = $this
->drupalCreateUser(array(
'cacheflush clear cache',
));
$this
->drupalLogin($user);
// Create rule.
$rule = rules_reaction_rule();
$rule
->event('cacheflush_before');
$rule
->event('cacheflush_after');
$rule
->action('drupal_message', array(
'message' => 'hello!',
));
$rule
->save();
rules_clear_cache(TRUE);
RulesLog::logger()
->clear();
$entity = entity_create('cacheflush', array(
'title' => 'test',
'uid' => $user->uid,
));
$entity
->save();
// Let the events occur.
_cacheflush_clear_preset($entity->id);
// Now there should have been 5 events, 2 times presave and once insert,
// update and delete.
$count = substr_count(RulesLog::logger()
->render(), '0 ms Reacting on event');
$this
->assertTrue($count == 2, 'Events have been properly invoked.');
RulesLog::logger()
->checkLog();
$this
->drupalLogout();
}