11<?php
22
33use Illuminate \Http \Request ;
4- use Kris \LaravelFormBuilder \FormHelper ;
4+ use Kris \LaravelFormBuilder \Fields \ CheckableType ;
55use Kris \LaravelFormBuilder \Fields \InputType ;
6+ use Kris \LaravelFormBuilder \FormHelper ;
67
78class FormFieldTest extends FormBuilderTestCase
89{
@@ -117,7 +118,7 @@ public function it_appends_to_the_class_attribute_of_the_field()
117118 $ text = new InputType ('field_name ' , 'text ' , $ this ->plainForm , $ options );
118119 $ renderResult = $ text ->render ();
119120
120- $ this ->assertMatchesRegularExpression ('/appended / ' , $ text ->getOption ('attr.class ' ));
121+ $ this ->assertMatchesRegularExpression ('/\bappended\b / ' , $ text ->getOption ('attr.class ' ));
121122
122123 $ defaultClasses = $ this ->config ['defaults ' ]['field_class ' ];
123124 $ this ->assertEquals ('form-control appended ' , $ text ->getOption ('attr.class ' ));
@@ -126,6 +127,26 @@ public function it_appends_to_the_class_attribute_of_the_field()
126127 $ this ->assertStringNotContainsString ('class_append ' , $ renderResult );
127128 }
128129
130+ /** @test */
131+ public function it_appends_to_the_class_attribute_of_a_custom_classes_checkbox_field ()
132+ {
133+ $ options = [
134+ 'attr ' => [
135+ 'class_append ' => 'appended ' ,
136+ ],
137+ ];
138+
139+ $ text = new CheckableType ('field_name ' , 'checkbox ' , $ this ->plainForm , $ options );
140+ $ renderResult = $ text ->render ();
141+
142+ $ this ->assertMatchesRegularExpression ('/\bappended\b/ ' , $ text ->getOption ('attr.class ' ));
143+
144+ $ this ->assertEquals ('custom-checkbox-field-class appended ' , $ text ->getOption ('attr.class ' ));
145+
146+ $ defaultClasses = $ this ->config ['defaults ' ]['field_class ' ];
147+ $ this ->assertStringNotContainsString ($ defaultClasses , $ text ->getOption ('attr.class ' ));
148+ }
149+
129150 /** @test */
130151 public function it_appends_to_the_class_attribute_of_the_label ()
131152 {
@@ -138,7 +159,7 @@ public function it_appends_to_the_class_attribute_of_the_label()
138159 $ text = new InputType ('field_name ' , 'text ' , $ this ->plainForm , $ options );
139160 $ renderResult = $ text ->render ();
140161
141- $ this ->assertMatchesRegularExpression ('/appended / ' , $ text ->getOption ('label_attr.class ' ));
162+ $ this ->assertMatchesRegularExpression ('/\bappended\b / ' , $ text ->getOption ('label_attr.class ' ));
142163
143164 $ defaultClasses = $ this ->config ['defaults ' ]['label_class ' ];
144165 $ this ->assertEquals ('control-label appended ' , $ text ->getOption ('label_attr.class ' ));
@@ -159,7 +180,7 @@ public function it_appends_to_the_class_attribute_of_the_wrapper()
159180 $ text = new InputType ('field_name ' , 'text ' , $ this ->plainForm , $ options );
160181 $ renderResult = $ text ->render ();
161182
162- $ this ->assertMatchesRegularExpression ('/appended / ' , $ text ->getOption ('wrapper.class ' ));
183+ $ this ->assertMatchesRegularExpression ('/\bappended\b / ' , $ text ->getOption ('wrapper.class ' ));
163184
164185 $ defaultClasses = $ this ->config ['defaults ' ]['wrapper_class ' ];
165186 $ this ->assertEquals ('form-group appended ' , $ text ->getOption ('wrapper.class ' ));
0 commit comments