3
3
4
4
use BladeTest \BladeTestCase ;
5
5
use Illuminate \Support \Facades \Auth ;
6
+ use Illuminate \Support \Facades \Session ;
6
7
use Illuminate \Support \Str ;
7
8
8
9
class DirectivesTest extends BladeTestCase
@@ -92,20 +93,51 @@ public function testSessionExistsDirectiveStyle()
92
93
public function testSessionExistsDirective ()
93
94
{
94
95
// When session exists ...
95
- \ Illuminate \ Support \ Facades \ Session::shouldReceive ('exists ' )
96
+ Session::shouldReceive ('exists ' )
96
97
->once ()
97
98
->with ('foo ' )
98
99
->andReturn (true );
99
100
$ view = view ('sessionExists ' )->render ();
100
101
$ this ->assertTrue (Str::contains ($ view , 'exists ' ));
101
102
102
103
// When session does not exist ...
103
- \ Illuminate \ Support \ Facades \ Session::shouldReceive ('exists ' )
104
+ Session::shouldReceive ('exists ' )
104
105
->once ()
105
106
->with ('foo ' )
106
107
->andReturn (false );
107
108
$ view = view ('sessionExists ' )->render ();
108
109
$ this ->assertFalse (Str::contains ($ view , 'exists ' ));
109
110
}
110
111
112
+ public function testSessionDirectiveStyle ()
113
+ {
114
+ $ this ->assertEquals ("<?php if(\session()->exists('foo')){ echo \session()->get('foo'); } ?> " , $ this ->compiler ->compileString ("@session('foo') " ));
115
+ }
116
+
117
+ public function testSessionDirectiveWorks ()
118
+ {
119
+ Session::shouldReceive ('exists ' )
120
+ ->once ()
121
+ ->with ('foo ' )
122
+ ->andReturn (true );
123
+ Session::shouldReceive ('get ' )
124
+ ->once ()
125
+ ->with ('foo ' )
126
+ ->andReturn ('hello ' );
127
+ $ view = view ('session ' )->render ();
128
+ $ this ->assertEquals ($ view , 'hello ' );
129
+ }
130
+
131
+ public function testSessionDirectiveNotWork ()
132
+ {
133
+ Session::shouldReceive ('exists ' )
134
+ ->once ()
135
+ ->with ('foo ' )
136
+ ->andReturn (false );
137
+ Session::shouldReceive ('get ' )
138
+ ->never ();
139
+ $ view = view ('session ' )->render ();
140
+ $ this ->assertEquals ($ view , '' );
141
+ }
142
+
111
143
}
0 commit comments