Location: PHPKode > projects > GnomePHP > peec-GnomePHP-b5a360b/gnomephp/mvc/MVCTests.php
<?php
namespace gnomephp\mvc;


use gnomephp\mvc\router\Router;

/**
 * Runs tests against the mvc package.
 * 
 * @author peec
 *
 */
class MVCTests extends \gnomephp\testsuite\TestController{
	
	protected function testDispatchRouterFailure(){
		
		$router = new Router('/test/fake/url', $_SERVER);

		$dispatcher = new Dispatcher($router);
		
		$this->expectException('gnomephp\mvc\RouterException');
		$dispatcher->run();		
	}
	
	protected function testDispatchAutoLoaderException(){
		$router = new Router('/exists', $_SERVER);
		$router->parse("
		*		/exists			\gnomephp\NonExistantController.Nonexistsmethod()
		");
		$dispatcher = new Dispatcher($router);
		
		$this->expectException('\gnomephp\AutoLoaderException');
		$dispatcher->run();
	}
	
	
	protected function testControllerVars(){
		$this->test($this->input)->assertNotNull();
		$this->test($this->session)->assertNotNull();
		$this->test($this->lang)->assertNotNull();
		$this->test($this->notifier)->assertNotNull();
		$this->test($this->view)->assertNotNull();
		$this->test($this->model)->assertNotNull();
		$this->test($this->state)->assertNotNull();
		$this->test($this->captcha)->assertNotNull();
	}
	
	
	protected function testView(){
		
		$v = new View($this->input, $this->lang, $this->session);
		
		// Test messages.
		\gnomephp\message\Message::add(\gnomephp\message\Message::SUCCESS, 'Test message');
		$this->test(count($v->getMessages()))->assertEqual(1);
		\gnomephp\message\Message::deleteMessages();
		
		// Test vars
		$v->assign('one', 1);
		$v->assign('two', 2);
		
		
		// Now test extend .
		$viewFile = GNOME_FW_PATH . '/res/test/view/viewfile';
		
		$content = $v->render($viewFile, true, '.php', true);
		$this->test($content)->assertEqual('template|staticContent|12');
		
		$refObj = new \ReflectionObject($v);
		
		$prop = $refObj->getProperty('extendingView');
		$prop->setAccessible(true);
		$this->test($prop->getValue($v))
			->assertEqual(GNOME_FW_PATH . '/res/test/view/viewtemplate');
		
		$prop = $refObj->getProperty('extendingViewAlias');
		$prop->setAccessible(true);
		$this->test($prop->getValue($v))
			->assertEqual('content');
		
		$prop = $refObj->getProperty('extendingVars');
		$prop->setAccessible(true);
		$this->test($prop->getValue($v))
			->assertArray();
		

		
	}
	
	protected function testViewCaching(){
		$v = new View($this->input, $this->lang, $this->session);
		$viewFile = GNOME_FW_PATH . '/res/test/view/viewfile';
		
		// Test vars
		$v->assign('one', 1);
		$v->assign('two', 2);
		
		$refObj = new \ReflectionObject($v);
		
		// Delete the cache file if it exist.
		$this->test($v->getViewCache($viewFile, '_NO_SALT_')->delete())
			->assertFalse();
		
		// Ok now - lets test cache! 
		$v->renderCache($viewFile, 3600, true, '.php', true,'_NO_SALT_');	
		
		// Check cache queue.
		$prop = $refObj->getProperty('cacheQueue');
		$prop->setAccessible(true);
		$cacheObj = $prop->getValue($v);
		$cacheObj = $cacheObj[0];
		$this->test($cacheObj)
			->assertObject();
		
		// Render it / Cache it for the first time!
		$c = $v->render($viewFile, true, '.php', true);
		// Now we should get a cached version.
		$cachedContent = $v->renderCache($viewFile, 3600, true, '.php', true, '_NO_SALT_');	
		// Nothing in cache queue.
		$this->test(count($prop->getValue($v)))
			->assertEqual(0);
		// Cache file must exist.
		$this->test(file_exists($cacheObj->getCacheFile()))->assertTrue();
		$this->test($cachedContent)->assertEqual('template|staticContent|12');
		
		// Delete the cache file.
		$this->test($v->getViewCache($viewFile, '_NO_SALT_')->delete())
			->assertTrue();
					
	}
	
	
	
	
}
Return current item: GnomePHP