From 974ff302efdcbaa54404f94f6e46d9a906268492 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 25 Jan 2012 08:37:04 -0600 Subject: [PATCH] adding some view tests and fixing a few bugs. --- laravel/session.php | 10 +++--- laravel/view.php | 14 +++++--- tests/cases/laravel/view.test.php | 53 +++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 10 deletions(-) create mode 100644 tests/cases/laravel/view.test.php diff --git a/laravel/session.php b/laravel/session.php index d2253834..0c598a7b 100644 --- a/laravel/session.php +++ b/laravel/session.php @@ -1,10 +1,5 @@ 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; + } } } diff --git a/tests/cases/laravel/view.test.php b/tests/cases/laravel/view.test.php new file mode 100644 index 00000000..caf5406b --- /dev/null +++ b/tests/cases/laravel/view.test.php @@ -0,0 +1,53 @@ +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']); + } + +} \ No newline at end of file