@@ -75,6 +75,7 @@ public function testSectionsAreNotFlushedWhenNotDoneRendering()
7575 $ view ->getEnvironment ()->shouldReceive ('flushSectionsIfDoneRendering ' )->once ();
7676
7777 $ this ->assertEquals ('contents ' , $ view ->render ());
78+ $ this ->assertEquals ('contents ' , (string )$ view );
7879 }
7980
8081
@@ -104,6 +105,97 @@ public function testViewAcceptsArrayableImplementations()
104105 $ this ->assertEquals ('bar ' , $ view ->foo );
105106 $ this ->assertEquals (array ('qux ' , 'corge ' ), $ view ->baz );
106107 }
108+
109+
110+ public function testViewGettersSetters ()
111+ {
112+ $ view = $ this ->getView ();
113+ $ this ->assertEquals ($ view ->getName (), 'view ' );
114+ $ this ->assertEquals ($ view ->getPath (), 'path ' );
115+ $ this ->assertEquals ($ view ->getData ()['foo ' ], 'bar ' );
116+ $ view ->setPath ('newPath ' );
117+ $ this ->assertEquals ($ view ->getPath (), 'newPath ' );
118+ }
119+
120+
121+ public function testViewArrayAccess ()
122+ {
123+ $ view = $ this ->getView ();
124+ $ this ->assertTrue ($ view instanceof ArrayAccess);
125+ $ this ->assertTrue ($ view ->offsetExists ('foo ' ));
126+ $ this ->assertEquals ($ view ->offsetGet ('foo ' ), 'bar ' );
127+ $ view ->offsetSet ('foo ' ,'baz ' );
128+ $ this ->assertEquals ($ view ->offsetGet ('foo ' ), 'baz ' );
129+ $ view ->offsetUnset ('foo ' );
130+ $ this ->assertFalse ($ view ->offsetExists ('foo ' ));
131+ }
132+
133+
134+ public function testViewMagicMethods ()
135+ {
136+ $ view = $ this ->getView ();
137+ $ this ->assertTrue (isset ($ view ->foo ));
138+ $ this ->assertEquals ($ view ->foo , 'bar ' );
139+ $ view ->foo = 'baz ' ;
140+ $ this ->assertEquals ($ view ->foo , 'baz ' );
141+ $ this ->assertEquals ($ view ['foo ' ], $ view ->foo );
142+ unset($ view ->foo );
143+ $ this ->assertFalse (isset ($ view ->foo ));
144+ $ this ->assertFalse ($ view ->offsetExists ('foo ' ));
145+ }
146+
147+
148+ public function testViewBadMethod ()
149+ {
150+ $ this ->setExpectedException ('BadMethodCallException ' );
151+ $ view = $ this ->getView ();
152+ $ view ->badMethodCall ();
153+ }
154+
155+
156+ public function testViewGatherDataWithRenderable ()
157+ {
158+ $ view = $ this ->getView ();
159+ $ view ->getEnvironment ()->shouldReceive ('incrementRender ' )->once ()->ordered ();
160+ $ view ->getEnvironment ()->shouldReceive ('callComposer ' )->once ()->ordered ()->with ($ view );
161+ $ view ->getEnvironment ()->shouldReceive ('getShared ' )->once ()->andReturn (array ('shared ' => 'foo ' ));
162+ $ view ->getEngine ()->shouldReceive ('get ' )->once ()->andReturn ('contents ' );
163+ $ view ->getEnvironment ()->shouldReceive ('decrementRender ' )->once ()->ordered ();
164+ $ view ->getEnvironment ()->shouldReceive ('flushSectionsIfDoneRendering ' )->once ();
165+
166+ $ view ->renderable = m::mock ('Illuminate\Support\Contracts\RenderableInterface ' );
167+ $ view ->renderable ->shouldReceive ('render ' )->once ()->andReturn ('text ' );
168+ $ view ->render ();
169+ }
170+
171+
172+ public function testViewRenderSections ()
173+ {
174+ $ view = $ this ->getView ();
175+ $ view ->getEnvironment ()->shouldReceive ('incrementRender ' )->once ()->ordered ();
176+ $ view ->getEnvironment ()->shouldReceive ('callComposer ' )->once ()->ordered ()->with ($ view );
177+ $ view ->getEnvironment ()->shouldReceive ('getShared ' )->once ()->andReturn (array ('shared ' => 'foo ' ));
178+ $ view ->getEngine ()->shouldReceive ('get ' )->once ()->andReturn ('contents ' );
179+ $ view ->getEnvironment ()->shouldReceive ('decrementRender ' )->once ()->ordered ();
180+ $ view ->getEnvironment ()->shouldReceive ('flushSectionsIfDoneRendering ' )->once ();
181+
182+ $ view ->getEnvironment ()->shouldReceive ('getSections ' )->once ()->andReturn (array ('foo ' ,'bar ' ));
183+ $ sections = $ view ->renderSections ();
184+ $ this ->assertEquals ($ sections [0 ], 'foo ' );
185+ $ this ->assertEquals ($ sections [1 ], 'bar ' );
186+ }
187+
188+
189+ public function testWithErrors ()
190+ {
191+ $ view = $ this ->getView ();
192+ $ this ->assertTrue ($ view ->withErrors (array ('foo ' =>'bar ' ,'qu ' =>'ux ' )) === $ view );
193+ $ this ->assertTrue ($ view ->errors instanceof \Illuminate \Support \MessageBag);
194+ $ this ->assertEquals (reset ($ view ->errors ->get ('foo ' )), 'bar ' );
195+ $ this ->assertEquals (reset ($ view ->errors ->get ('qu ' )), 'ux ' );
196+ $ this ->assertTrue ($ view ->withErrors (new \Illuminate \Support \MessageBag (array ('foo ' =>'baz ' ))) === $ view );
197+ $ this ->assertEquals (reset ($ view ->errors ->get ('foo ' )), 'baz ' );
198+ }
107199
108200
109201 protected function getView ()
0 commit comments