Ejemplo n.º 1
0
 public function testRenderWithCache(IntegrationTester $I)
 {
     $I->wantToTest('Render by using simple view with cache');
     if (PHP_MAJOR_VERSION == 7) {
         throw new \PHPUnit_Framework_SkippedTestError('Skipped in view of the experimental support for PHP 7.');
     }
     // Create cache at first run
     $view = new Simple();
     codecept_debug(gettype($view->getParamsToView()));
     $view->setViewsDir(PATH_DATA . 'views/');
     // No cache before DI is set
     $I->assertFalse($view->getCache());
     $view->setDI($this->getDi());
     $I->assertEquals($view, $view->cache(['key' => 'view_simple_cache']));
     $cache = $view->getCache();
     $I->assertInstanceOf('Phalcon\\Cache\\BackendInterface', $cache);
     $timeNow = time();
     $view->setParamToView('a_cool_var', $timeNow);
     $I->assertEquals("<p>{$timeNow}</p>", rtrim($view->render('test3/coolVar')));
     $I->amInPath(PATH_CACHE);
     $I->seeFileFound('view_simple_cache');
     $I->seeInThisFile("<p>{$timeNow}</p>");
     unset($view, $cache);
     // Re-use the cached contents
     $view = new Simple();
     $view->setViewsDir(PATH_DATA . 'views/');
     $view->setDI($this->getDi());
     $view->cache(['key' => 'view_simple_cache']);
     $I->assertEmpty($view->getContent());
     $I->assertEquals("<p>{$timeNow}</p>", rtrim($view->render('test3/coolVar')));
     $I->assertNotEmpty($view->getContent());
     $I->assertEquals("<p></p>", rtrim($view->render('test3/coolVar')));
     $I->deleteFile('view_simple_cache');
 }
Ejemplo n.º 2
0
 public function testRenderWithCache()
 {
     // Create cache at first run
     $view = new View();
     $view->setViewsDir('unit-tests/views/');
     $this->assertFalse($view->getCache());
     // No cache before DI is set
     $view->setDI($this->_getDI());
     $this->assertEquals($view, $view->cache(array('key' => 'view_simple_cache')));
     $cache = $view->getCache();
     $this->assertInstanceOf('Phalcon\\Cache\\BackendInterface', $cache);
     if ($cache instanceof BackendInterface == false) {
         $this->fail('Expected BackendInterface');
     }
     $timeNow = time();
     $view->setParamToView('a_cool_var', $timeNow);
     $this->assertEquals("<p>{$timeNow}</p>", $view->render('test3/coolVar'));
     unset($view, $cache);
     // Re-use the cached contents
     $view = new View();
     $view->setViewsDir('unit-tests/views/');
     $view->setDI($this->_getDI());
     $view->cache(array('key' => 'view_simple_cache'));
     $this->assertEquals("<p>{$timeNow}</p>", $view->render('test3/coolVar'));
     // Cache should expire
     $this->assertEquals("<p></p>", @$view->render('test3/coolVar'));
 }