File tree 2 files changed +19
-3
lines changed
2 files changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -726,8 +726,24 @@ public function testTruncateModel()
726
726
727
727
public function testGuardedModel ()
728
728
{
729
- Guarded:: create ([ ' var ' => ' val ' ] );
729
+ $ model = new Guarded ( );
730
730
731
- $ this ->assertEquals (1 , Guarded::count ());
731
+ // foobar is properly guarded
732
+ $ model ->fill (['foobar ' => 'ignored ' , 'name ' => 'John Doe ' ]);
733
+ $ this ->assertFalse (isset ($ model ->foobar ));
734
+ $ this ->assertSame ('John Doe ' , $ model ->name );
735
+
736
+ // foobar is guarded to any level
737
+ $ model ->fill (['foobar->level2 ' => 'v2 ' ]);
738
+ $ this ->assertNull ($ model ->getAttribute ('foobar->level2 ' ));
739
+
740
+ // multi level statement also guarded
741
+ $ model ->fill (['level1->level2 ' => 'v1 ' ]);
742
+ $ this ->assertNull ($ model ->getAttribute ('level1->level2 ' ));
743
+
744
+ // level1 is still writable
745
+ $ dataValues = ['array ' , 'of ' , 'values ' ];
746
+ $ model ->fill (['level1 ' => $ dataValues ]);
747
+ $ this ->assertEquals ($ dataValues , $ model ->getAttribute ('level1 ' ));
732
748
}
733
749
}
Original file line number Diff line number Diff line change @@ -7,5 +7,5 @@ class Guarded extends Eloquent
7
7
{
8
8
protected $ connection = 'mongodb ' ;
9
9
protected $ collection = 'guarded ' ;
10
- protected $ guarded = ['foobar ' ];
10
+ protected $ guarded = ['foobar ' , ' level1->level2 ' ];
11
11
}
You can’t perform that action at this time.
0 commit comments