Beispiel #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');
 }
Beispiel #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'));
 }
Beispiel #3
0
 public function testRenderWithFilenameWithEngineWithoutEngineRegistered()
 {
     $this->setExpectedException('Phalcon\\Mvc\\View\\Exception');
     $view = new View();
     $view->setDI(new Di());
     $view->setViewsDir('unit-tests/views/');
     $view->setParamToView('name', 'FooBar');
     $this->assertEquals('Hello FooBar', $view->render('test4/index.mhtml'));
 }
Beispiel #4
0
 /**
  * Tests render with filename without registered
  *
  * @author Kamil Skowron <*****@*****.**>
  * @since  2014-05-28
  */
 public function testRenderWithFilenameWithEngineWithoutEngineRegistered()
 {
     $this->specify('Render with filename without registered engine does not throw Exception', function () {
         $view = new Simple();
         $view->setDI(Di::getDefault());
         $view->setViewsDir(PATH_DATA . 'views' . DIRECTORY_SEPARATOR);
         $view->setParamToView('name', 'FooBar');
         $view->render('test4/index.mhtml');
     }, ['throws' => [Exception::class, "View '" . PATH_DATA . 'views' . DIRECTORY_SEPARATOR . 'test4' . DIRECTORY_SEPARATOR . "index.mhtml' was not found in the views directory"]]);
 }
Beispiel #5
0
 public function testGetRegisteredEngines()
 {
     $expected = array('.mhtml' => 'My_Mustache_Engine', '.phtml' => 'Phalcon\\Mvc\\View\\Engine\\Php', '.twig' => 'My_Twig_Engine', '.volt' => 'Phalcon\\Mvc\\View\\Engine\\Volt');
     $di = new Phalcon\DI();
     $view = new Phalcon\Mvc\View\Simple();
     $view->setDI($di);
     $view->setViewsDir('unit-tests/views/');
     $view->registerEngines($expected);
     $this->assertEquals($expected, $view->getRegisteredEngines());
 }