public function testHelpers() { \PHPPE\Core::$core->nocache = true; \PHPPE\Core::$core->meta["test"] = "testing"; \PHPPE\Core::$core->link["apple-touch-icon"] = "testing"; \PHPPE\View::init([]); $dir = dirname(__DIR__); \PHPPE\View::setPath($dir); \PHPPE\View::assign("dir", $dir); \PHPPE\View::css("test.css"); \PHPPE\View::css("test2.css"); \PHPPE\View::css(url("css", "test.css")); $this->assertNotEmpty(\PHPPE\View::css(), "CSS"); \PHPPE\View::jslib("test.js", "testjs();"); \PHPPE\View::jslib("test2.js", "testjs();"); \PHPPE\View::jslib(url("js", "test.js"), "testjs();"); $this->assertNotEmpty(\PHPPE\View::jslib(), "JSLib"); \PHPPE\View::js("some()", "thing();"); \PHPPE\View::js("some2()", "thing();", true); \PHPPE\View::menu("a", "b"); \PHPPE\View::menu("c", ["d" => "e"]); $this->assertNotEmpty(\PHPPE\View::menu(), "Menu"); $o = \PHPPE\Core::$core->output; \PHPPE\Core::$core->output = "ncurses"; $o = trim(\PHPPE\View::e('D', "message", "module")); $this->assertEquals("module-D: message" . chr(27) . "[0m", $o, "error string #1"); \PHPPE\Core::$core->output = "html"; $this->assertEquals("<span style='background:#F00000;color:#FEA0A0;padding:3px;'>E-module: ["message"]</span>", trim(\PHPPE\View::e('E', ["message"], "module")), "error string #2"); \PHPPE\Core::$core->output = $o; $this->assertEquals("aaa\n<!include test2>\nbbb\n", \PHPPE\View::get("test1"), "Raw template file"); \PHPPE\DS::close(); $ds = new \PHPPE\DS("sqlite::memory:"); \PHPPE\DS::exec("UPDATE views SET css='[\"a.css\"]' WHERE id='simple'"); $this->assertNotEmpty(\PHPPE\View::get("simple"), "Raw template db"); \PHPPE\DS::exec("UPDATE views SET css='' WHERE id='simple'"); }
public function testCache() { \PHPPE\Core::$core->nocache = false; $dir = "vendor/phppe/Developer"; \PHPPE\View::setPath($dir); \PHPPE\Core::$user->id = ""; //test if there's no cache $mc = \PHPPE\Cache::$mc; $cache = new \PHPPE\Cache("files"); $cache->set('aaa', 1); $cache->get('aaa'); \PHPPE\Cache::$mc = null; $cache->set('aaa', 1); $cache->get('aaa'); \PHPPE\Cache::$mc = $mc; //use memcached cache if otherwise not configured if (empty($mc) || empty(\PHPPE\Core::$core->cache)) { $mem = new \PHPPE\Cache("127.0.0.1:11211"); } \PHPPE\Core::$core->nocache = false; if (empty(\PHPPE\Cache::$mc)) { $mem = new \PHPPE\Cache("files"); } if (empty(\PHPPE\Cache::$mc)) { $this->markTestSkipped(); } $this->assertNotEmpty(\PHPPE\Cache::$mc, "Cache initialized"); $var = "t_00" . time(); \PHPPE\Core::$core->nocache = true; $this->assertFalse(\PHPPE\Cache::set($var, "aaa"), "Set with nocache"); $this->assertNull(\PHPPE\Cache::get($var), "Get with nocache"); \PHPPE\Core::$core->nocache = false; $this->assertNotFalse(\PHPPE\Cache::set($var, "aaa"), "Set"); $this->assertEquals("aaa", \PHPPE\Cache::get($var), "Get"); $tn = 't_' . sha1(\PHPPE\Core::$core->base . "_cachetest"); \PHPPE\Cache::set($tn, "", 1); $txt = \PHPPE\View::template("cachetest", ["var" => "value"]); $this->assertNotEmpty(\PHPPE\Cache::get($tn), "Template caching {$tn}"); $sha = \PHPPE\Core::$core->base . "tests/http/cachetest/" . \PHPPE\Core::$user->id . "/" . \PHPPE\Core::$client->lang; $N = 'p_' . sha1($sha); \PHPPE\Cache::set($N, "", 1); $this->assertEmpty(\PHPPE\View::fromCache($N), "Page cache #1 " . $N); $url = url("tests", "http") . "cachetest"; if (trim(@file_get_contents($url)) == '') { $url = str_replace("public/", "", $url); } file_get_contents($url); //make sure the output gets to the cache $d1 = file_get_contents($url); //this must be served from cache $this->assertNotEmpty(\PHPPE\View::fromCache($N), "Page cache #2 (Configure cache '127.0.0.1:11211' in config.php if fails)"); $d2 = file_get_contents($url . "?skipcache=1"); //trigger nocache flag set in constructor $this->assertNotFalse(strpos($d1, ", mc -->"), "Output cache #1"); $this->assertFalse(strpos($d1, "NOCACHE"), "Output cache #2"); $this->assertFalse(strpos($d2, ", mc -->"), "Output cache #3"); $this->assertNotFalse(strpos($d2, "NOCACHE"), "Output cache #4"); if (method_exists(\PHPPE\Cache::$mc, "cronMinute")) { \PHPPE\Cache::$mc->cronMinute(""); } }