diff --git a/e107_handlers/cache_handler.php b/e107_handlers/cache_handler.php
index 89b197a5e..cd9217bf0 100644
--- a/e107_handlers/cache_handler.php
+++ b/e107_handlers/cache_handler.php
@@ -31,6 +31,7 @@ class ecache {
public $CachenqMD5;
public $UserCacheActive; // Checkable flag - TRUE if user cache enabled
public $SystemCacheActive; // Checkable flag - TRUE if system cache enabled
+ private $lastError;
const CACHE_PREFIX = 'lastError = "Couldn't read ".$cache_file;
+ }
+
if (substr($ret,0,strlen(self::CACHE_PREFIX)) == self::CACHE_PREFIX)
{
$ret = substr($ret, strlen(self::CACHE_PREFIX));
@@ -154,18 +161,28 @@ class ecache {
{
$ret = substr($ret, 5); // Handle the history for now
}
+
return $ret;
}
}
else
{
- // e107::getDebug()->log("Couldn't find cache file: ".json_encode($cache_file));
+ $this->lastError = "Cache file not found: ".$cache_file;
return false;
}
}
return false;
}
+ /**
+ * Return the last error encountered during cache processing.
+ * @return mixed
+ */
+ public function getLastError()
+ {
+ return $this->lastError;
+ }
+
/**
* @return string
* @param string $CacheTag
@@ -225,7 +242,7 @@ class ecache {
{
if(isset($this) && $this instanceof ecache)
{
- return $this->set($CacheTag, $Data, $ForceCache, $bRaw, true);
+ $this->set($CacheTag, $Data, $ForceCache, $bRaw, true);
}
else
{
diff --git a/e107_tests/tests/_data/ecache/content/C_wmessage_0800fc577294c34e0b28ad2839435945.cache.php_ b/e107_tests/tests/_data/ecache/content/C_wmessage_0800fc577294c34e0b28ad2839435945.cache.php_
new file mode 100644
index 000000000..d74f21a6c
--- /dev/null
+++ b/e107_tests/tests/_data/ecache/content/C_wmessage_0800fc577294c34e0b28ad2839435945.cache.php_
@@ -0,0 +1 @@
+
Get Started
\ No newline at end of file
diff --git a/e107_tests/tests/_data/ecache/content/S_Config_test.cache.php_ b/e107_tests/tests/_data/ecache/content/S_Config_test.cache.php_
new file mode 100644
index 000000000..6e7262a14
--- /dev/null
+++ b/e107_tests/tests/_data/ecache/content/S_Config_test.cache.php_
@@ -0,0 +1,5 @@
+ 4,
+ 'most_guests_online' => 4,
+ 'most_online_datestamp' => 1534279911,
+)
\ No newline at end of file
diff --git a/e107_tests/tests/_data/ecache/content/S_Update_core.cache.php_ b/e107_tests/tests/_data/ecache/content/S_Update_core.cache.php_
new file mode 100644
index 000000000..1de5d31ec
--- /dev/null
+++ b/e107_tests/tests/_data/ecache/content/S_Update_core.cache.php_
@@ -0,0 +1,3 @@
+{
+ "status": "not needed"
+}
\ No newline at end of file
diff --git a/e107_tests/tests/_data/ecache/db/online.php_ b/e107_tests/tests/_data/ecache/db/online.php_
new file mode 100644
index 000000000..f77eb6fae
--- /dev/null
+++ b/e107_tests/tests/_data/ecache/db/online.php_
@@ -0,0 +1,18 @@
+array (
+ '_FIELD_TYPES' =>
+ array (
+ 'online_timestamp' => 'int',
+ 'online_flag' => 'int',
+ 'online_user_id' => 'escape',
+ 'online_ip' => 'escape',
+ 'online_location' => 'escape',
+ 'online_pagecount' => 'int',
+ 'online_active' => 'int',
+ 'online_agent' => 'escape',
+ 'online_language' => 'escape',
+ ),
+ '_NOTNULL' =>
+ array (
+ 'online_location' => '',
+ ),
+)
\ No newline at end of file
diff --git a/e107_tests/tests/unit/ecacheTest.php b/e107_tests/tests/unit/ecacheTest.php
new file mode 100644
index 000000000..9bb9caf82
--- /dev/null
+++ b/e107_tests/tests/unit/ecacheTest.php
@@ -0,0 +1,189 @@
+cache = $this->make('ecache');
+ }
+ catch(Exception $e)
+ {
+ $this->assertTrue(false, $e->getMessage());
+ }
+
+ $file = codecept_data_dir('ecache/content/S_Config_test.cache.php_');
+ $dest = e_CACHE_CONTENT."S_Config_test.cache.php";
+
+ if(!file_exists($dest) && !copy($file,$dest))
+ {
+ $this->assertTrue(false, "Couldn't copy cache file from ".$file);
+ }
+
+ $file = codecept_data_dir('ecache/content/S_Update_core.cache.php_');
+ $dest = e_CACHE_CONTENT."S_Update_core.cache.php";
+
+ if(!file_exists($dest) && !copy($file, $dest))
+ {
+ $this->assertTrue(false, "Couldn't copy cache file from ".$file);
+ }
+
+ $file = codecept_data_dir('ecache/db/online.php_');
+ $dest = e_CACHE_DB."online.php";
+
+ if(!file_exists($dest) && !copy($file, $dest))
+ {
+ $this->assertTrue(false, "Couldn't copy cache file from ".$file);
+ }
+
+ $file = codecept_data_dir('ecache/content/C_wmessage_0800fc577294c34e0b28ad2839435945.cache.php_');
+ $dest = e_CACHE_CONTENT."C_wmessage_0800fc577294c34e0b28ad2839435945.cache.php";
+
+ if(!file_exists($dest) && !copy($file, $dest))
+ {
+ $this->assertTrue(false, "Couldn't copy cache file from ".$file);
+ }
+
+
+ }
+
+ public function testRetrieve()
+ {
+ $tests = array(
+ 0 => array(
+ 'name' => 'Config_test',
+ 'system' => true,
+ 'expected' => "array (
+ 'most_members_online' => 4,
+ 'most_guests_online' => 4,
+ 'most_online_datestamp' => 1534279911,
+ )",
+ ),
+ 1 => array(
+ 'name' => 'Update_core',
+ 'system' => true,
+ 'expected' => '{
+ "status": "not needed"
+ }',
+ ),
+ 2 => array(
+ 'name' => 'wmessage',
+ 'system' => false,
+ 'expected' => 'GetStarted
',
+ ),
+ );
+
+ $this->cache->setMD5('hash'); // set a consistent hash value: ie. 0800fc577294c34e0b28ad2839435945
+
+ $clean = ["\t", "\n", " "];
+
+ foreach($tests as $var)
+ {
+
+ $result = $this->cache->retrieve($var['name'], false, true, $var['system']);
+ $result = str_replace($clean, '', $result);
+ $expected = str_replace($clean, '', $var['expected']);
+ $this->assertSame($expected, $result);
+ }
+
+ $errorStatus = $this->cache->getLastError();
+ $this->assertEmpty($errorStatus, "An error occurred during cache: ".$errorStatus);
+
+ }
+/*
+ public function testClear_sys()
+ {
+
+ }
+
+ public function testSet_sys()
+ {
+
+ }
+
+ public function testClear()
+ {
+
+ }
+
+ public function testDelete()
+ {
+
+ }
+
+ public function test__construct()
+ {
+
+ }
+
+ public function testClearAll()
+ {
+
+ }
+
+ public function testGetMD5()
+ {
+
+ }
+
+ public function testSetMD5()
+ {
+
+ }
+
+ public function testRetrieve_sys()
+ {
+
+ }*/
+
+ public function testSetAndRetrieve()
+ {
+ $tests = array(
+ 0 => array(
+ 'data' => 'This is my cached data',
+ 'braw' => false,
+ 'system' => true
+ ),
+ 1 => array(
+ 'data' => 'This is my cached data 1',
+ 'braw' => false,
+ 'system' => false
+ ),
+ 2 => array(
+ 'data' => 'This is my cached data 2',
+ 'braw' => true,
+ 'system' => false
+ ),
+ 3 => array(
+ 'data' => 'This is my cached data 3',
+ 'braw' => true,
+ 'system' => true
+ ),
+
+ );
+
+ foreach($tests as $index => $var)
+ {
+ $tag = "custom_".$index;
+ $this->cache->set($tag, $var['data'], true, $var['braw'], $var['system']);
+ $result = $this->cache->retrieve($tag, false, true, $var['system']);
+ $this->assertSame($var['data'],$result);
+ }
+
+
+ }
+/*
+ public function testCache_fname()
+ {
+
+ }
+*/
+
+}