/**
  * 最常用的使用方式(推荐) 
  * -------------------------------------------------------------------
  * LtCookie要求: 
  *  # 使用LtCookie必须设置密钥(cookie.secret_key)
  * 
  * -------------------------------------------------------------------
  * LtCookie建议(不强求):
  *  # 使用杂乱无章的字符串作为密钥
  * 
  * 本测试用例期望效果:
  * 通过Web script对HTTP头(Cookie在http头里)进行单元测试,实际使用方法和效果参见unittest/Cookie/cookie_proxy.php
  */
 public function testMostUsedWay()
 {
     $result1 = callWeb("Cookie/cookie_proxy.php", array("operation" => "set", "cookies[username]" => "lotusphp", "cookies[is_the_best]" => "yes"), null, true);
     preg_match_all('~Set-Cookie: (.*); expires=~i', $result1, $matches);
     $cookieHeader = "Cookie: " . implode(";", $matches[1]);
     $this->assertTrue(0 < strpos($cookieHeader, "username="******"is_the_best="));
     $result2 = callWeb("Cookie/cookie_proxy.php", array("operation" => "get", "cookie_name" => "username"), array($cookieHeader));
     $this->assertEquals("lotusphp", unserialize($result2));
     $result3 = callWeb("Cookie/cookie_proxy.php", array("operation" => "del", "cookie_name" => "is_the_best"), array($cookieHeader), true);
     if (LOTUS_UNITTEST_DEBUG) {
         echo $result3;
     }
     $this->assertTrue(0 < strpos($result3, "is_the_best=deleted"));
 }
 /**
  * 通过callWeb测试不能工作在cli的cache
  */
 public function testOpcodeCacheAdapter()
 {
     $opcodeCacheAdapters = array();
     if (extension_loaded('apc')) {
         $opcodeCacheAdapters[] = "apc";
     }
     if (extension_loaded('eaccelerator')) {
         // eAccelerator 0.9.6 取消了相关功能
         if (function_exists('eaccelerator_put') && function_exists('eaccelerator_get')) {
             $opcodeCacheAdapters[] = "eaccelerator";
         }
     }
     if (extension_loaded('xcache')) {
         $opcodeCacheAdapters[] = "xcache";
     }
     foreach ($opcodeCacheAdapters as $adapter) {
         if (LOTUS_UNITTEST_DEBUG) {
             echo "\n--testOpcodeCacheAdapter--" . $adapter . "--callWeb--\n";
         }
         $result = callWeb("Cache/opcode_cache_proxy.php", array("adapter" => $adapter, "operation" => "add", "key" => "test_key", "table_name" => "test", "value" => "test_value"));
         $this->assertTrue(unserialize($result));
         $result = callWeb("Cache/opcode_cache_proxy.php", array("adapter" => $adapter, "operation" => "get", "key" => "test_key", "table_name" => "test"));
         $this->assertEquals("test_value", unserialize($result));
         $result = callWeb("Cache/opcode_cache_proxy.php", array("adapter" => $adapter, "operation" => "update", "key" => "test_key", "table_name" => "test", "value" => "new_value"));
         $this->assertTrue(unserialize($result));
         $result = callWeb("Cache/opcode_cache_proxy.php", array("adapter" => $adapter, "operation" => "get", "key" => "test_key", "table_name" => "test"));
         $this->assertEquals("new_value", unserialize($result));
         $result = callWeb("Cache/opcode_cache_proxy.php", array("adapter" => $adapter, "operation" => "del", "key" => "test_key", "table_name" => "test"));
         $this->assertTrue(unserialize($result));
         $result = callWeb("Cache/opcode_cache_proxy.php", array("adapter" => $adapter, "operation" => "get", "key" => "test_key", "table_name" => "test"));
         $this->assertFalse(unserialize($result));
         /**
          * 测试ttl, xcache在同一请求内不会过期, 因此拆成两个请求测试,
          * 第一次请求设置过期时间为一秒, 延时2秒后读取返回结果
          */
         $result = callWeb("Cache/opcode_cache_proxy.php", array("adapter" => $adapter, "operation" => "add", "key" => "test_key", "table_name" => "test", "value" => "test_ttl_value", 'ttl' => 1));
         $this->assertTrue(unserialize($result));
         sleep(2);
         $result = callWeb("Cache/opcode_cache_proxy.php", array("adapter" => $adapter, "operation" => "get", "key" => "test_key", "table_name" => "test"));
         $this->assertFalse(unserialize($result));
     }
 }