Skip to content

Commit 469def2

Browse files
authored
Merge pull request #4 from glhd/bugfix/if-no-label-given-uses-invalid-text
Bugfix: Invalid Default Label, Allow for Publishing Bootstrap Views, Remove Group Error, Clean Up Tests
2 parents 76f38b7 + f7f371c commit 469def2

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

src/AireBootstrapServiceProvider.php

+7-6
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,18 @@ public function boot()
1414
{
1515
$this->loadViewsFrom(dirname(__DIR__) . '/views', 'aire-bootstrap');
1616

17+
$this->publishes([
18+
dirname(__DIR__).'/views' => $this->app->resourcePath('views/vendor/aire-bootstrap'),
19+
], 'aire-bootstrap-views');
20+
1721
Aire::setTheme('aire-bootstrap', null, [
1822
'default_classes' => [
1923
'group' => 'form-group',
2024
'group_input_group' => 'input-group',
2125
'group_prepend' => 'input-group-prepend',
2226
'group_append' => 'input-group-append',
2327
'group_help_text' => 'form-text text-muted',
24-
'group_errors' => 'd-none',
28+
'group_errors' => '',
2529
'label' => '',
2630
'input' => 'form-control',
2731

@@ -137,21 +141,18 @@ public function boot()
137141
});
138142

139143
Input::registerElementMutator(function (Input $input) {
140-
141-
// Apply a label by default
142-
$input->group->label('Choose file');
143144

144145
$input->attributes->registerMutator('class', function (ClassNames $classNames) use ($input) {
145146

146147
if ('file' === $input->attributes->get('type')) {
147148
$classNames
148149
->remove('form-control')
149150
->add('custom-file-input');
150-
151+
151152
$input
152153
->groupAddClass('custom-file')
153154
->groupRemoveClass('form-group');
154-
155+
155156
$input->group->label
156157
->addClass('custom-file-label')
157158
->removeClass('cursor-pointer');

tests/BootstrapMarkupTest.php

+17-7
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ public function test_an_ungrouped_checkbox(): void
2424
->id('foo-box')
2525
->withoutGroup();
2626

27-
$this->assertSelectorExists($html, 'div.form-check');
28-
$this->assertSelectorAttribute($html, 'div.form-check > input.form-check-input', 'name', 'demo');
29-
$this->assertSelectorAttribute($html, 'div.form-check > label.form-check-label', 'for', 'foo-box');
30-
$this->assertSelectorContainsText($html, 'div.form-check > label.form-check-label', 'Demo checkbox');
27+
$this->assertSelectorDoesNotExist($html,'.form-group');
28+
$this->assertSelectorAttribute($html, 'input.custom-control-input', 'name', 'demo');
29+
$this->assertSelectorAttribute($html, 'label.custom-control-label', 'for', 'foo-box');
30+
$this->assertSelectorContainsText($html, 'label.custom-control-label', 'Demo checkbox');
3131
}
3232

3333
public function test_a_select_form(): void
@@ -61,7 +61,7 @@ public function test_submit_button_html()
6161
->id('foo-submit-button');
6262

6363
$this->assertSelectorAttribute($html, 'button', 'type', 'submit');
64-
$this->assertSelectorAttribute($html, 'button', 'class', 'btn btn-primary');
64+
$this->assertSelectorAttribute($html, 'button', 'class', 'btn btn-primary ');
6565
$this->assertSelectorAttribute($html, 'button', 'id', 'foo-submit-button');
6666
$this->assertSelectorContainsText($html, 'button', 'Submit Awesome');
6767
}
@@ -71,7 +71,17 @@ public function test_radio_group_form() : void
7171
$html = $this->aire()->form()
7272
->radioGroup(['radio-1'=>'Radio 1','radio-2'=>'Radio 2'],'radio_selector','Foo Radio Selector');
7373

74-
$this->assertSelectorAttribute($html, 'div.form-check > input.form-check-input', 'value', 'radio-1');
75-
$this->assertSelectorContainsText($html,'div.form-check > label.form-check-label','Radio 1');
74+
$this->assertSelectorContainsText($html, 'div.form-group > label', 'Foo Radio Selector');
75+
$this->assertSelectorAttribute($html,'div.custom-control.custom-radio > input.custom-control-input','value', 'radio-1');
76+
$this->assertSelectorAttribute($html,'div.custom-control.custom-radio + div.custom-control.custom-radio > input.custom-control-input','value', 'radio-2');
77+
}
78+
79+
public function test_when_no_label_given_a_label_is_not_generated() : void
80+
{
81+
$html = $this->aire()
82+
->form()
83+
->input('text-input');
84+
85+
$this->assertSelectorDoesNotExist($html, 'label');
7686
}
7787
}

0 commit comments

Comments
 (0)