From 37b5f614ba9bca1e9f00638fd2240c2178b3d383 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 25 Jan 2012 10:30:31 -0600 Subject: [PATCH] more view tests. --- tests/cases/laravel/view.test.php | 55 +++++++++++++++++++ .../application/views/tests/nested.php | 1 + 2 files changed, 56 insertions(+) create mode 100644 tests/laravel/application/views/tests/nested.php diff --git a/tests/cases/laravel/view.test.php b/tests/cases/laravel/view.test.php index 548ed95f..9c8aabd0 100644 --- a/tests/cases/laravel/view.test.php +++ b/tests/cases/laravel/view.test.php @@ -2,6 +2,15 @@ class ViewTest extends PHPUnit_Framework_TestCase { + /** + * Tear down the testing environment. + */ + public function tearDown() + { + View::$shared = array(); + Event::$events = array(); + } + /** * Test the View::make method. * @@ -162,6 +171,7 @@ public function testNestMethodSetsViewInstanceInData() $view = View::make('home.index')->nest('partial', 'tests.basic'); $this->assertEquals('tests.basic', $view->data['partial']->view); + $this->assertInstanceOf('Laravel\\View', $view->data['partial']); } @@ -179,4 +189,49 @@ public function testDataIsPassedToViewCorrectly() $this->assertEquals('Taylor is 25', $view); } + /** + * Test that the View class renders nested views. + * + * @group laravel + */ + public function testNestedViewsAreRendered() + { + $view = View::make('tests.basic') + ->with('age', 25) + ->nest('name', 'tests.nested'); + + $this->assertEquals('Taylor is 25', $view->render()); + } + + /** + * Test that the View class renders nested responses. + * + * @group laravel + */ + public function testNestedResponsesAreRendered() + { + $view = View::make('tests.basic') + ->with('age', 25) + ->with('name', Response::view('tests.nested')); + + $this->assertEquals('Taylor is 25', $view->render()); + } + + /** + * Test the View class raises a composer event. + * + * @group laravel + */ + public function testComposerEventIsCalledWhenViewIsRendering() + { + View::composer('tests.basic', function($view) + { + $view->data = array('name' => 'Taylor', 'age' => 25); + }); + + $view = View::make('tests.basic')->render(); + + $this->assertEquals('Taylor is 25', $view); + } + } \ No newline at end of file diff --git a/tests/laravel/application/views/tests/nested.php b/tests/laravel/application/views/tests/nested.php new file mode 100644 index 00000000..9ce498e5 --- /dev/null +++ b/tests/laravel/application/views/tests/nested.php @@ -0,0 +1 @@ +Taylor \ No newline at end of file