8
8
use Illuminate \Http \Request ;
9
9
use Illuminate \Support \MessageBag ;
10
10
use Illuminate \Support \Facades \App ;
11
+ use Illuminate \Support \ViewErrorBag ;
11
12
use Illuminate \Contracts \Http \Kernel ;
12
13
use Illuminate \Support \Facades \Blade ;
13
14
use Illuminate \Support \Facades \Route ;
@@ -56,7 +57,15 @@ public function test_middleware_is_registered()
56
57
57
58
public function test_validation_errors_are_registered ()
58
59
{
59
- $ this ->assertTrue (Inertia::getShared ('errors ' ) instanceof Closure);
60
+ $ this ->assertInstanceOf (Closure::class, Inertia::getShared ('errors ' ));
61
+ }
62
+
63
+ public function test_validation_errors_can_be_empty ()
64
+ {
65
+ $ errors = Inertia::getShared ('errors ' )();
66
+
67
+ $ this ->assertIsObject ($ errors );
68
+ $ this ->assertEmpty (get_object_vars ($ errors ));
60
69
}
61
70
62
71
public function test_validation_errors_are_not_registered_when_already_registered ()
@@ -68,15 +77,29 @@ public function test_validation_errors_are_not_registered_when_already_registere
68
77
69
78
public function test_validation_errors_are_returned_in_the_correct_format ()
70
79
{
71
- Session::put ('errors ' , new MessageBag ([
80
+ Session::put ('errors ' , ( new ViewErrorBag ())-> put ( ' default ' , new MessageBag ([
72
81
'name ' => 'The name field is required. ' ,
73
82
'email ' => 'Not a valid email address. ' ,
74
- ]));
83
+ ]))) ;
75
84
76
85
$ errors = Inertia::getShared ('errors ' )();
77
86
78
87
$ this ->assertIsObject ($ errors );
79
88
$ this ->assertSame ('The name field is required. ' , $ errors ->name );
80
89
$ this ->assertSame ('Not a valid email address. ' , $ errors ->email );
81
90
}
91
+
92
+ public function test_validation_errors_with_named_error_bags_are_scoped ()
93
+ {
94
+ Session::put ('errors ' , (new ViewErrorBag ())->put ('example ' , new MessageBag ([
95
+ 'name ' => 'The name field is required. ' ,
96
+ 'email ' => 'Not a valid email address. ' ,
97
+ ])));
98
+
99
+ $ errors = Inertia::getShared ('errors ' )();
100
+
101
+ $ this ->assertIsObject ($ errors );
102
+ $ this ->assertSame ('The name field is required. ' , $ errors ->example ->name );
103
+ $ this ->assertSame ('Not a valid email address. ' , $ errors ->example ->email );
104
+ }
82
105
}
0 commit comments