From b812f2f08a20e15ef39bcc303f9090f36203e3dc Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 25 Jan 2012 10:16:50 -0600 Subject: [PATCH] adding more view tests. --- tests/cases/laravel/view.test.php | 73 +++++++++++++++++++ .../laravel/application/views/tests/basic.php | 1 + 2 files changed, 74 insertions(+) create mode 100644 tests/laravel/application/views/tests/basic.php diff --git a/tests/cases/laravel/view.test.php b/tests/cases/laravel/view.test.php index 111e5322..548ed95f 100644 --- a/tests/cases/laravel/view.test.php +++ b/tests/cases/laravel/view.test.php @@ -2,6 +2,16 @@ class ViewTest extends PHPUnit_Framework_TestCase { + /** + * Test the View::make method. + * + * @group laravel + */ + public function testMakeMethodReturnsAViewInstance() + { + $this->assertInstanceOf('Laravel\\View', View::make('home.index')); + } + /** * Test the View class constructor. * @@ -38,6 +48,42 @@ public function testDataIsSetOnViewByConstructor() $this->assertEquals('Taylor', $view->data['name']); } + /** + * Test the View::name method. + * + * @group laravel + */ + public function testNameMethodRegistersAViewName() + { + View::name('home.index', 'home'); + + $this->assertEquals('home.index', View::$names['home']); + } + + /** + * Test the View::shared method. + * + * @group laravel + */ + public function testSharedMethodAddsDataToSharedArray() + { + View::share('comment', 'Taylor'); + + $this->assertEquals('Taylor', View::$shared['comment']); + } + + /** + * Test the View::with method. + * + * @group laravel + */ + public function testViewDataCanBeSetUsingWithMethod() + { + $view = View::make('home.index')->with('comment', 'Taylor'); + + $this->assertEquals('Taylor', $view->data['comment']); + } + /** * Test the View class constructor. * @@ -106,4 +152,31 @@ public function testDataCanBeRetrievedThroughArrayAccess() $this->assertEquals('Taylor', $view['comment']); } + /** + * Test the View::nest method. + * + * @group laravel + */ + 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']); + } + + /** + * Test that the registered data is passed to the view correctly. + * + * @group laravel + */ + public function testDataIsPassedToViewCorrectly() + { + View::share('name', 'Taylor'); + + $view = View::make('tests.basic')->with('age', 25)->render(); + + $this->assertEquals('Taylor is 25', $view); + } + } \ No newline at end of file diff --git a/tests/laravel/application/views/tests/basic.php b/tests/laravel/application/views/tests/basic.php new file mode 100644 index 00000000..c961dc2f --- /dev/null +++ b/tests/laravel/application/views/tests/basic.php @@ -0,0 +1 @@ + is \ No newline at end of file