You are here

public function OptimizedbFunctionsTestCase::testClearTable in OptimizeDB 7

Test _optimizedb_clear_cache_form_table() function.

File

./optimizedb.test, line 83
Tests for optimizedb.module.

Class

OptimizedbFunctionsTestCase
Test the module functions.

Code

public function testClearTable() {
  $this
    ->assertEqual($this
    ->countCacheFormRows(), 0);
  $time = REQUEST_TIME;
  for ($cid = 1; $cid <= 5; $cid++) {
    $cache_time = $time - $cid * 10;
    $this
      ->createCacheFormItem($cid, $cache_time);
  }
  for ($cid = 6; $cid <= 10; $cid++) {
    $cache_time = $time + $cid * 10;
    $this
      ->createCacheFormItem($cid, $cache_time);
  }
  $this
    ->assertEqual($this
    ->countCacheFormRows(), 10);
  $count_expire_all = (int) db_select('cache_form')
    ->condition('expire', $time, '<')
    ->countQuery()
    ->execute()
    ->fetchField();
  $this
    ->assertEqual($count_expire_all, 5);
  _optimizedb_clear_cache_form_table(OPTIMIZEDB_CLEAR_EXPIRED_CACHE);
  $this
    ->assertEqual($this
    ->countCacheFormRows(), 5);
  db_truncate('cache_form')
    ->execute();
  for ($cid = 1; $cid <= 5; $cid++) {
    $cache_time = $time - $cid * 10;
    $this
      ->createCacheFormItem($cid, $cache_time);
  }
  _optimizedb_clear_cache_form_table(OPTIMIZEDB_CLEAR_EXPIRED_CACHE);
  $this
    ->assertEqual($this
    ->countCacheFormRows(), 0);
}