/** * test setting parameters in beforeDispatch method * * @return void */ public function testQueryStringAndCustomTime() { $folder = CACHE . 'views' . DS; $file = $folder . 'posts-home-coffee-life-sleep-sissies-coffee-life-sleep-sissies.html'; $content = '<!--cachetime:' . (time() + WEEK) . ';ext:html-->Foo bar'; file_put_contents($file, $content); Router::reload(); Router::connect('/', ['controller' => 'Pages', 'action' => 'display', 'home']); Router::connect('/pages/*', ['controller' => 'Pages', 'action' => 'display']); Router::connect('/:controller/:action/*'); $_GET = ['coffee' => 'life', 'sleep' => 'sissies']; $filter = new CacheFilter(); $request = new Request('posts/home/?coffee=life&sleep=sissies'); $response = new Response(); $event = new Event(__CLASS__, $this, compact('request', 'response')); $filter->beforeDispatch($event); $result = $response->body(); $expected = '<!--created:'; $this->assertTextStartsWith($expected, $result); $expected = '-->Foo bar'; $this->assertTextEndsWith($expected, $result); $result = $response->type(); $expected = 'text/html'; $this->assertEquals($expected, $result); $result = $response->header(); $this->assertNotEmpty($result['Expires']); // + 1 week unlink($file); }
/** * @param string|null $url * @return void|int */ public function clear($url = null) { if ($url) { $cache = new CacheFilter(); $file = $cache->getFile($url); if (!$file) { $this->error('No cache file found'); return; } unlink($file); $this->out('File ' . $file . ' deleted'); return; } $folder = CACHE . 'views' . DS; $continue = $this->in('Clear `' . $folder . '`?', ['y', 'n'], 'y'); if ($continue !== 'y') { return $this->error('Aborted!'); } $fi = new \FilesystemIterator($folder, \FilesystemIterator::SKIP_DOTS); foreach ($fi as $file) { $path = $file->getPathname(); if ($this->params['verbose']) { $this->out('Deleting ' . $path); } unlink($path); } $this->out('Done!'); }