Location: PHPKode > projects > Phalcon PHP > phalcon-cphalcon-b0abb3e/unit-tests/ViewTest.php
<?php

/*
  +------------------------------------------------------------------------+
  | Phalcon Framework                                                      |
  +------------------------------------------------------------------------+
  | Copyright (c) 2011-2012 Phalcon Team (http://www.phalconphp.com)       |
  +------------------------------------------------------------------------+
  | This source file is subject to the New BSD License that is bundled     |
  | with this package in the file docs/LICENSE.txt.                        |
  |                                                                        |
  | If you did not receive a copy of the license and are unable to         |
  | obtain it through the world-wide-web, please send an email             |
  | to hide@address.com so we can send you a copy immediately.       |
  +------------------------------------------------------------------------+
  | Authors: Andres Gutierrez <hide@address.com>                      |
  |          Eduar Carvajal <hide@address.com>                         |
  +------------------------------------------------------------------------+
*/

class ViewTest extends PHPUnit_Framework_TestCase {

	public function testStandardRender(){

		$view = new Phalcon_View();
		$view->setViewsDir('unit-tests/views/');
		$this->assertEquals($view->getViewsDir(), 'unit-tests/views/');

		//Standard Render
		$view->start();
		$view->render('test2', 'index');
		$view->finish();
		$this->assertEquals($view->getContent(), '<html>here</html>');

		$view->start();
		$view->render('test3', 'other');
		$view->finish();
		$this->assertEquals($view->getContent(), '<html>lolhere</html>');

		//Variables
		$view->setParamToView('born', 'this');

		$view->start();
		$view->render('test3', 'another');
		$view->finish();

		$this->assertEquals($view->getContent(), '<html>lol<p>this</p></html>');

		//Templates
		$view->setTemplateAfter('test');

		$view->start();
		$view->render('test3', 'other');
		$view->finish();

		$this->assertEquals($view->getContent(), '<html>zuplolhere</html>');

		$view->cleanTemplateAfter();

		//Render Levels
		$view->setRenderLevel(Phalcon_View::LEVEL_MAIN_LAYOUT);

		$view->start();
		$view->render('test3', 'other');
		$view->finish();
		$this->assertEquals($view->getContent(), '<html>lolhere</html>');

		$view->setRenderLevel(Phalcon_View::LEVEL_LAYOUT);

		$view->start();
		$view->render('test3', 'other');
		$view->finish();
		$this->assertEquals($view->getContent(), '<html>lol</html>');

		$view->setRenderLevel(Phalcon_View::LEVEL_ACTION_VIEW);

		$view->start();
		$view->render('test3', 'other');
		$view->finish();
		$this->assertEquals($view->getContent(), '<html></html>');

	}
}
Return current item: Phalcon PHP