Skip to content

Commit

Permalink
Merge pull request #4 from glhd/bugfix/if-no-label-given-uses-invalid…
Browse files Browse the repository at this point in the history
…-text

Bugfix: Invalid Default Label, Allow for Publishing Bootstrap Views, Remove Group Error, Clean Up Tests
  • Loading branch information
inxilpro authored Feb 20, 2020
2 parents 76f38b7 + f7f371c commit 469def2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
13 changes: 7 additions & 6 deletions src/AireBootstrapServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,18 @@ public function boot()
{
$this->loadViewsFrom(dirname(__DIR__) . '/views', 'aire-bootstrap');

$this->publishes([
dirname(__DIR__).'/views' => $this->app->resourcePath('views/vendor/aire-bootstrap'),
], 'aire-bootstrap-views');

Aire::setTheme('aire-bootstrap', null, [
'default_classes' => [
'group' => 'form-group',
'group_input_group' => 'input-group',
'group_prepend' => 'input-group-prepend',
'group_append' => 'input-group-append',
'group_help_text' => 'form-text text-muted',
'group_errors' => 'd-none',
'group_errors' => '',
'label' => '',
'input' => 'form-control',

Expand Down Expand Up @@ -137,21 +141,18 @@ public function boot()
});

Input::registerElementMutator(function (Input $input) {

// Apply a label by default
$input->group->label('Choose file');

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

if ('file' === $input->attributes->get('type')) {
$classNames
->remove('form-control')
->add('custom-file-input');

$input
->groupAddClass('custom-file')
->groupRemoveClass('form-group');

$input->group->label
->addClass('custom-file-label')
->removeClass('cursor-pointer');
Expand Down
24 changes: 17 additions & 7 deletions tests/BootstrapMarkupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ public function test_an_ungrouped_checkbox(): void
->id('foo-box')
->withoutGroup();

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

public function test_a_select_form(): void
Expand Down Expand Up @@ -61,7 +61,7 @@ public function test_submit_button_html()
->id('foo-submit-button');

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

$this->assertSelectorAttribute($html, 'div.form-check > input.form-check-input', 'value', 'radio-1');
$this->assertSelectorContainsText($html,'div.form-check > label.form-check-label','Radio 1');
$this->assertSelectorContainsText($html, 'div.form-group > label', 'Foo Radio Selector');
$this->assertSelectorAttribute($html,'div.custom-control.custom-radio > input.custom-control-input','value', 'radio-1');
$this->assertSelectorAttribute($html,'div.custom-control.custom-radio + div.custom-control.custom-radio > input.custom-control-input','value', 'radio-2');
}

public function test_when_no_label_given_a_label_is_not_generated() : void
{
$html = $this->aire()
->form()
->input('text-input');

$this->assertSelectorDoesNotExist($html, 'label');
}
}

0 comments on commit 469def2

Please sign in to comment.