adding some view tests and fixing a few bugs.
This commit is contained in:
parent
c9eb7bdf35
commit
974ff302ef
|
@ -1,10 +1,5 @@
|
||||||
<?php namespace Laravel;
|
<?php namespace Laravel;
|
||||||
|
|
||||||
if (Config::get('application.key') === '')
|
|
||||||
{
|
|
||||||
throw new \Exception("An application key is required to use sessions.");
|
|
||||||
}
|
|
||||||
|
|
||||||
class Session {
|
class Session {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -29,6 +24,11 @@ class Session {
|
||||||
*/
|
*/
|
||||||
public static function start($driver)
|
public static function start($driver)
|
||||||
{
|
{
|
||||||
|
if (Config::get('application.key') === '')
|
||||||
|
{
|
||||||
|
throw new \Exception("An application key is required to use sessions.");
|
||||||
|
}
|
||||||
|
|
||||||
static::$instance = new Session\Payload(static::factory($driver));
|
static::$instance = new Session\Payload(static::factory($driver));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ class View implements ArrayAccess {
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $path;
|
public $path;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* All of the shared view data.
|
* All of the shared view data.
|
||||||
|
@ -68,12 +68,16 @@ public function __construct($view, $data = array())
|
||||||
// This makes error display in the view extremely convenient, since the
|
// This makes error display in the view extremely convenient, since the
|
||||||
// developer can always assume they have a message container instance
|
// developer can always assume they have a message container instance
|
||||||
// available to them in the view.
|
// available to them in the view.
|
||||||
if (Config::get('session.driver') !== '' and Session::started() and ! isset($this['errors']))
|
if ( ! isset($this->data['errors']))
|
||||||
{
|
{
|
||||||
$this->data['errors'] = Session::get('errors', function()
|
if (Session::started() and Session::has('errors'))
|
||||||
{
|
{
|
||||||
return new Messages;
|
$this->data['errors'] = Session::get('errors');
|
||||||
});
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->data['errors'] = new Messages;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class ViewTest extends PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test the View class constructor.
|
||||||
|
*
|
||||||
|
* @group laravel
|
||||||
|
*/
|
||||||
|
public function testViewNameIsSetByConstrutor()
|
||||||
|
{
|
||||||
|
$view = new View('home.index');
|
||||||
|
|
||||||
|
$this->assertEquals('home.index', $view->view);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test the View class constructor.
|
||||||
|
*
|
||||||
|
* @group laravel
|
||||||
|
*/
|
||||||
|
public function testViewIsCreatedWithCorrectPath()
|
||||||
|
{
|
||||||
|
$view = new View('home.index');
|
||||||
|
|
||||||
|
$this->assertEquals(APP_PATH.'views/home/index.php', $view->path);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test the View class constructor.
|
||||||
|
*
|
||||||
|
* @group laravel
|
||||||
|
*/
|
||||||
|
public function testDataIsSetOnViewByConstructor()
|
||||||
|
{
|
||||||
|
$view = new View('home.index', array('name' => 'Taylor'));
|
||||||
|
|
||||||
|
$this->assertEquals('Taylor', $view->data['name']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test the View class constructor.
|
||||||
|
*
|
||||||
|
* @group laravel
|
||||||
|
*/
|
||||||
|
public function testEmptyMessageContainerSetOnViewWhenNoErrorsInSession()
|
||||||
|
{
|
||||||
|
$view = new View('home.index');
|
||||||
|
|
||||||
|
$this->assertInstanceOf('Laravel\\Messages', $view->data['errors']);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue