@@ -19,6 +19,7 @@ public function it_can_create_an_editor()
1919 $ this ->assertEmpty ($ editor ->template );
2020
2121 $ editor
22+ ->idSrc ()
2223 ->fields ([
2324 Text::make ('name ' ),
2425 ])
@@ -28,6 +29,16 @@ public function it_can_create_an_editor()
2829 $ this ->assertCount (1 , $ editor ->fields );
2930 $ this ->assertEquals ('/test ' , $ editor ->ajax );
3031 $ this ->assertEquals ('#template ' , $ editor ->template );
32+ $ this ->assertEquals ('DT_RowId ' , $ editor ->idSrc );
33+ }
34+
35+ /**
36+ * @param string $instance
37+ * @return \Yajra\DataTables\Html\Editor\Editor
38+ */
39+ protected function getEditor (string $ instance = 'editor ' ): Editor
40+ {
41+ return Editor::make ($ instance );
3142 }
3243
3344 /** @test */
@@ -51,29 +62,119 @@ public function it_can_have_events()
5162 /** @test */
5263 public function it_has_authorizations ()
5364 {
54- $ editor = Editor::makeIf (true , 'editor ' );
65+ $ editor = Editor::makeIf (true , 'editor ' )
66+ ->fields ([
67+ Text::make ('name ' ),
68+ ]);
5569 $ this ->assertInstanceOf (Editor::class, $ editor );
5670 $ this ->assertEquals (true , $ editor ->isAuthorized ());
57-
58- $ editor = Editor::makeIf (false , 'editor ' );
71+ $ this ->assertEquals ([
72+ 'instance ' => 'editor ' ,
73+ 'fields ' => [
74+ Text::make ('name ' )->toArray (),
75+ ],
76+ ], $ editor ->toArray ());
77+
78+ $ editor = Editor::makeIf (false , 'editor ' )
79+ ->fields ([
80+ Text::make ('name ' ),
81+ ]);
5982 $ this ->assertInstanceOf (Editor::class, $ editor );
6083 $ this ->assertEquals (false , $ editor ->isAuthorized ());
84+ $ this ->assertCount (1 , $ editor ->fields );
85+ $ this ->assertEquals ([], $ editor ->toArray ());
6186
6287 $ editor = Editor::makeIfCan ('ability ' , 'editor ' );
6388 $ this ->assertInstanceOf (Editor::class, $ editor );
6489 $ this ->assertEquals (false , $ editor ->isAuthorized ());
90+ $ this ->assertEquals ([], $ editor ->toArray ());
6591
6692 $ editor = Editor::makeIfCannot ('ability ' , 'editor ' );
6793 $ this ->assertInstanceOf (Editor::class, $ editor );
6894 $ this ->assertEquals (false , $ editor ->isAuthorized ());
95+ $ this ->assertEquals ([], $ editor ->toArray ());
6996 }
7097
71- /**
72- * @param string $instance
73- * @return \Yajra\DataTables\Html\Editor\Editor
74- */
75- protected function getEditor (string $ instance = 'editor ' ): Editor
98+ /** @test */
99+ public function it_can_be_serialized_to_array ()
76100 {
77- return Editor::make ($ instance );
101+ $ editor = Editor::make ()
102+ ->ajax ('' )
103+ ->fields ([
104+ Text::make ('name ' ),
105+ ]);
106+
107+ $ this ->assertEquals ([
108+ 'instance ' => 'editor ' ,
109+ 'ajax ' => '' ,
110+ 'fields ' => [
111+ Text::make ('name ' )->toArray (),
112+ ],
113+ ], $ editor ->toArray ());
114+ }
115+
116+ /** @test */
117+ public function it_can_be_serialized_to_json_string ()
118+ {
119+ $ editor = Editor::make ()
120+ ->ajax ('' )
121+ ->fields ([
122+ Text::make ('name ' ),
123+ ]);
124+
125+ $ expected = '{"instance":"editor","ajax":"","fields":[{"name":"name","label":"Name","type":"text"}]} ' ;
126+ $ this ->assertEquals ($ expected , $ editor ->toJson ());
127+ }
128+
129+ /** @test */
130+ public function it_has_form_options ()
131+ {
132+ $ editor = Editor::make ()
133+ ->formOptions ([
134+ 'main ' => [
135+ 'esc ' => true ,
136+ ],
137+ ]);
138+
139+ $ this ->assertEquals ([
140+ 'main ' => [
141+ 'esc ' => true ,
142+ ],
143+ ], $ editor ->formOptions );
144+
145+ $ editor ->formOptionsMain (['esc ' => true ]);
146+ $ this ->assertEquals (['esc ' => true ], $ editor ->formOptions ['main ' ]);
147+
148+ $ editor ->formOptionsBubble (['esc ' => true ]);
149+ $ this ->assertEquals (['esc ' => true ], $ editor ->formOptions ['bubble ' ]);
150+
151+ $ editor ->formOptionsInline (['esc ' => true ]);
152+ $ this ->assertEquals (['esc ' => true ], $ editor ->formOptions ['inline ' ]);
153+ }
154+
155+ /** @test */
156+ public function it_has_display_constants ()
157+ {
158+ $ editor = Editor::make ()->display (Editor::DISPLAY_BOOTSTRAP );
159+ $ this ->assertEquals ('bootstrap ' , $ editor ->display );
160+
161+ $ editor ->display (Editor::DISPLAY_ENVELOPE );
162+ $ this ->assertEquals ('envelope ' , $ editor ->display );
163+
164+ $ editor ->display (Editor::DISPLAY_FOUNDATION );
165+ $ this ->assertEquals ('foundation ' , $ editor ->display );
166+
167+ $ editor ->display (Editor::DISPLAY_JQUERYUI );
168+ $ this ->assertEquals ('jqueryui ' , $ editor ->display );
169+
170+ $ editor ->display (Editor::DISPLAY_LIGHTBOX );
171+ $ this ->assertEquals ('lightbox ' , $ editor ->display );
172+ }
173+
174+ /** @test */
175+ public function it_has_scripts ()
176+ {
177+ $ editor = Editor::make ()->scripts ('fn ' );
178+ $ this ->assertEquals ('fn ' , $ editor ->scripts );
78179 }
79- }
180+ }
0 commit comments