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'); }
/** * Tests render * * @author Kamil Skowron <*****@*****.**> * @since 2014-05-28 */ public function testRenderStandard() { $this->specify('The view rendering does not work as expected', function () { $view = new Simple(); $view->setViewsDir(PATH_DATA . 'views' . DIRECTORY_SEPARATOR); expect($view->render('test2/index'))->equals('We are here'); expect($view->getContent())->equals('We are here'); }); }
public function testRenderWithPartials() { $view = new View(); $view->setViewsDir('unit-tests/views/'); $expectedParams = array('cool_var' => 'FooBar'); ob_start(); $view->partial('partials/_partial1', $expectedParams); ob_clean(); $this->assertEquals('Hey, this is a partial, also FooBar', $view->getContent()); $view->setVars($expectedParams); $this->assertEquals('Hey, this is a partial, also FooBar', $view->render('test5/index')); $this->assertEquals('Hey, this is a partial, also FooBar<br />Hey, this is a second partial, also FooBar', $view->render('test9/index')); }