diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 11a07ca..b00d276 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -23,7 +23,7 @@ jobs: strategy: matrix: - php-version: [ "7.4" ] + php-version: [ "8.1" ] operating-system: [ "ubuntu-latest" ] fail-fast: false @@ -82,7 +82,7 @@ jobs: strategy: matrix: - php-version: [ "7.4" ] + php-version: [ "8.1" ] operating-system: [ "ubuntu-latest" ] fail-fast: false @@ -138,11 +138,11 @@ jobs: strategy: matrix: - php-version: [ "7.2", "7.3", "7.4", "8.0", "8.1", "8.2"] + php-version: ["8.1", "8.2"] operating-system: [ "ubuntu-latest" ] composer-args: [ "" ] include: - - php-version: "7.2" + - php-version: "8.1" operating-system: "ubuntu-latest" composer-args: "--prefer-lowest" - php-version: "8.3" @@ -205,7 +205,7 @@ jobs: strategy: matrix: - php-version: [ "7.4" ] + php-version: [ "8.1" ] operating-system: [ "ubuntu-latest" ] fail-fast: false diff --git a/composer.json b/composer.json index e66fa11..29e0c13 100644 --- a/composer.json +++ b/composer.json @@ -17,13 +17,13 @@ } ], "require": { - "php": ">=7.2", + "php": ">=8.1", "nette/forms": "3.1.12", "nette/application": "^3.0" }, "require-dev": { - "ninjify/qa": "^v0.12", - "phpunit/phpunit": "^8.5", + "contributte/qa": "^v0.3", + "phpunit/phpunit": "^9.5", "phpstan/phpstan": "^0.12.6", "phpstan/phpstan-deprecation-rules": "^0.12", "phpstan/phpstan-nette": "^0.12", diff --git a/ruleset.xml b/ruleset.xml index 88b3255..b1fd514 100644 --- a/ruleset.xml +++ b/ruleset.xml @@ -1,9 +1,16 @@ - + - + + + + + + + + diff --git a/src/BootstrapForm.php b/src/BootstrapForm.php index 70c998a..8f7156e 100644 --- a/src/BootstrapForm.php +++ b/src/BootstrapForm.php @@ -25,12 +25,18 @@ class BootstrapForm extends Form use BootstrapContainerTrait; use AddRowTrait; + /** @var bool */ + public static $allwaysUseNullable = false; + /** @var string Class to be added if this is ajax. Defaults to 'ajax' */ public $ajaxClass = 'ajax'; /** @var Html */ protected $elementPrototype; + /** @var int */ + private static $bootstrapVersion = BootstrapVersion::V4; + /** @var bool */ private $isAjax = true; @@ -40,24 +46,19 @@ class BootstrapForm extends Form /** @var bool */ private $autoShowValidation = true; - /** @var bool */ - public static $allwaysUseNullable = false; - - /** @var int */ - private static $bootstrapVersion = BootstrapVersion::V4; - /** * @param IContainer|null $container */ public function __construct($container = null) { parent::__construct($container); + $this->setRenderer(new BootstrapRenderer()); $prototype = Html::el('form', [ 'action' => '', 'method' => self::POST, - 'class' => [], + 'class' => [], ]); $this->elementPrototype = $prototype; @@ -86,7 +87,6 @@ public function getElementPrototype(): Html return $this->elementPrototype; } - /** * @return BootstrapRenderer */ diff --git a/src/BootstrapRenderer.php b/src/BootstrapRenderer.php index 1b98f84..0b6cc63 100644 --- a/src/BootstrapRenderer.php +++ b/src/BootstrapRenderer.php @@ -159,40 +159,40 @@ public function configElem($config, ?Html $el = null): ?Html public function getConfig(): array { return [ - Cnf::FORM => [], - Cnf::GROUP => [ + Cnf::FORM => [], + Cnf::GROUP => [ Cnf::ELEMENT_NAME => 'fieldset', ], Cnf::GROUP_LABEL => [ Cnf::ELEMENT_NAME => 'legend', ], - Cnf::GRID_ROW => [ + Cnf::GRID_ROW => [ Cnf::ELEMENT_NAME => 'div', - Cnf::CLASS_ADD => BootstrapForm::getBootstrapVersion() === BootstrapVersion::V5 ? 'row' : 'form-row', + Cnf::CLASS_ADD => BootstrapForm::getBootstrapVersion() === BootstrapVersion::V5 ? 'row' : 'form-row', ], Cnf::GRID_CELL => [ Cnf::ELEMENT_NAME => 'div', ], Cnf::FORM_OWN_ERRORS => [], - Cnf::FORM_OWN_ERROR => [ + Cnf::FORM_OWN_ERROR => [ Cnf::ELEMENT_NAME => 'div', - Cnf::CLASS_SET => ['alert', 'alert-danger'], + Cnf::CLASS_SET => ['alert', 'alert-danger'], ], - Cnf::PAIR => [ + Cnf::PAIR => [ Cnf::ELEMENT_NAME => 'div', - Cnf::CLASS_SET => BootstrapForm::getBootstrapVersion() === BootstrapVersion::V5 ? 'mb-3' : 'form-group', + Cnf::CLASS_SET => BootstrapForm::getBootstrapVersion() === BootstrapVersion::V5 ? 'mb-3' : 'form-group', ], Cnf::LABEL => [ Cnf::ELEMENT_NAME => 'label', - Cnf::CLASS_SET => BootstrapForm::getBootstrapVersion() === BootstrapVersion::V5 ? 'form-label' : null, + Cnf::CLASS_SET => BootstrapForm::getBootstrapVersion() === BootstrapVersion::V5 ? 'form-label' : null, ], - Cnf::INPUT => [], + Cnf::INPUT => [], // inputs which are normally inline elements (after bootstrap classes are applied) - Cnf::INPUT_VALID => [ + Cnf::INPUT_VALID => [ Cnf::CLASS_ADD => 'is-valid', ], Cnf::INPUT_INVALID => [ @@ -201,13 +201,13 @@ public function getConfig(): array Cnf::DESCRIPTION => [ Cnf::ELEMENT_NAME => 'small', - Cnf::CLASS_SET => ['form-text', 'text-muted'], + Cnf::CLASS_SET => ['form-text', 'text-muted'], ], - Cnf::FEEDBACK => [ + Cnf::FEEDBACK => [ Cnf::ELEMENT_NAME => 'div', ], - Cnf::FEEDBACK_VALID => [ + Cnf::FEEDBACK_VALID => [ Cnf::CLASS_ADD => 'valid-feedback', ], Cnf::FEEDBACK_INVALID => [ @@ -215,7 +215,7 @@ public function getConfig(): array ], // empty wrapper, but it gets utilized in side-by side and inline mode - Cnf::NON_LABEL => [ + Cnf::NON_LABEL => [ Cnf::ELEMENT_NAME => null, ], ]; @@ -237,8 +237,8 @@ public function getConfigOverride(): array $labelColClass .= ' col-form-label'; return [ - RenderMode::INLINE => [ - Cnf::FORM => [ + RenderMode::INLINE => [ + Cnf::FORM => [ Cnf::CLASS_ADD => 'form-inline', ], Cnf::NON_LABEL => [ @@ -246,18 +246,18 @@ public function getConfigOverride(): array ], ], RenderMode::SIDE_BY_SIDE_MODE => [ - Cnf::PAIR => [ + Cnf::PAIR => [ Cnf::CLASS_ADD => 'row', ], - Cnf::LABEL => [ + Cnf::LABEL => [ Cnf::CLASS_ADD => $labelColClass, ], Cnf::NON_LABEL => [ Cnf::ELEMENT_NAME => 'div', - Cnf::CLASS_SET => $nonLabelColClass, + Cnf::CLASS_SET => $nonLabelColClass, ], ], - RenderMode::VERTICAL_MODE => [], + RenderMode::VERTICAL_MODE => [], ]; } diff --git a/src/Enums/DateTimeFormat.php b/src/Enums/DateTimeFormat.php index 320fc31..4aa3324 100644 --- a/src/Enums/DateTimeFormat.php +++ b/src/Enums/DateTimeFormat.php @@ -68,7 +68,7 @@ public static function validate(string $format, string $timeString): bool } /** - * Turns datetime format into a human readable format, e.g. 'd.m.Y' => 'dd.mm.yyyy'. + * Turns datetime format into a human readable format, e.g. 'd.m.Y' => 'dd.mm.yyyy'. * Supported values: d, j, m, n, Y, y, a, A, g, G, h, H, i, s, c, U */ public static function toHumanFormat(string $format, bool $example = true, bool $appendExample = true): string diff --git a/src/Enums/RenderMode.php b/src/Enums/RenderMode.php index aa2e1b1..9b263d0 100644 --- a/src/Enums/RenderMode.php +++ b/src/Enums/RenderMode.php @@ -15,6 +15,7 @@ class RenderMode * Labels above controls */ public const VERTICAL_MODE = 0; + /** * Labels beside controls */ diff --git a/src/Enums/RendererConfig.php b/src/Enums/RendererConfig.php index 7dda5b4..96332e4 100644 --- a/src/Enums/RendererConfig.php +++ b/src/Enums/RendererConfig.php @@ -24,6 +24,7 @@ class RendererConfig * Form group */ public const GROUP = 'group'; + /** * Label of a group */ @@ -35,6 +36,7 @@ class RendererConfig * @see BootstrapRow */ public const GRID_ROW = 'grid-row'; + /** * @see BootstrapCell */ @@ -44,6 +46,7 @@ class RendererConfig * Errors belonging to the form rather than an individual control. This is a container. */ public const FORM_OWN_ERRORS = 'form-own-errors'; + /** * Multiple of those will be inside FORM_OWN_ERRORS */ @@ -52,6 +55,7 @@ class RendererConfig public const PAIR = 'pair'; public const LABEL = 'label'; public const DESCRIPTION = 'description'; + /** * form group parts which are not label - input, feedback, description */ @@ -63,6 +67,7 @@ class RendererConfig public const INPUT = 'input'; public const INPUT_VALID = 'input-valid'; public const INPUT_INVALID = 'input-invalid'; + /** * Element that is normally an inline element within bootstrap */ @@ -71,10 +76,12 @@ class RendererConfig * Text saying if field is valid or invalid */ public const FEEDBACK = 'feedback'; + /** * Child of 'feedback'. Extra attributes for invalid feedback */ public const FEEDBACK_VALID = 'feedback-valid'; + /** * Child of 'feedback'. Extra attributes for valid feedback */ @@ -84,20 +91,24 @@ class RendererConfig * Element name */ public const ELEMENT_NAME = 'element'; + /** * Container. Must contain 'element' key. May be recursive. */ public const CONTAINER = 'container'; public const ATTRIBUTES = 'attributes'; + /** * Class or array of classes to set */ public const CLASS_SET = 'class-set'; + /** * Class or array of classes to add */ public const CLASS_ADD = 'class-add'; + /** * Class or array to classes to remove if they exist */ diff --git a/src/Enums/RendererOptions.php b/src/Enums/RendererOptions.php index 246e9bf..9eee5bf 100644 --- a/src/Enums/RendererOptions.php +++ b/src/Enums/RendererOptions.php @@ -13,36 +13,43 @@ class RendererOptions * Internal. If control has already been rendered. */ public const _RENDERED = '_rendered'; + /** * Boolean. Can se set on groups, if false, group will not be rendered separately. * Honestly I have no clue as to why would you do it, but is present on the original renderer... */ public const VISUAL = 'visual'; + /** * String|Html. Can be set on groups. If it's a string, it will be used as Html::el(container) */ public const CONTAINER = 'container'; + /** * String. Can be set on groups or controls. It is just a regular HTML attribute id. * Note that if it's set on a control, it will be applied to the pair, not the control as it's already * set internally. */ public const ID = 'id'; + /** * String. Standard input description, a.ka. bootstrap Help text */ public const DESCRIPTION = 'description'; + /** * String|Html. Can be set on a group and will dictate its . If it's a string, it will be * translated (if applicable) */ public const LABEL = 'label'; + /** * String. Can be set on an input. If set to 'hidden', label is not rendered and all hidden inputs are * rendered at the end of form. * I wouldn't play with this. */ public const TYPE = 'type'; + /** * String. Can be set on an input. If form's validation state is shown and the input is valid, this is * shown instead of an error diff --git a/src/Grid/BootstrapCell.php b/src/Grid/BootstrapCell.php index f418beb..558e085 100644 --- a/src/Grid/BootstrapCell.php +++ b/src/Grid/BootstrapCell.php @@ -127,6 +127,16 @@ public function setCurrentGroup(?ControlGroup $currentGroup): self return $this; } + /** + * @return static + */ + public function addHtmlClass(string $class) + { + $this->elementPrototype->class[] = $class; + + return $this; + } + /** * Creates column class based on numOfColumns */ @@ -145,14 +155,4 @@ protected function createClass(): string return $this->row->gridBreakPoint !== null ? 'col-' . $this->row->gridBreakPoint . '-' . $this->numOfColumns : 'col-' . $this->numOfColumns; } - /** - * @return static - */ - public function addHtmlClass(string $class) - { - $this->elementPrototype->class[] = $class; - - return $this; - } - } diff --git a/src/Grid/BootstrapRow.php b/src/Grid/BootstrapRow.php index 97c13a7..ccfb433 100644 --- a/src/Grid/BootstrapRow.php +++ b/src/Grid/BootstrapRow.php @@ -33,18 +33,18 @@ class BootstrapRow implements IComponent, Control use FakeControlTrait; /** - * Global name counter + * Number of columns in Bootstrap grid. Default is 12, but it can be customized. * * @var int */ - private static $uidCounter = 0; + public $numOfColumns = 12; /** - * Number of columns in Bootstrap grid. Default is 12, but it can be customized. + * Global name counter * * @var int */ - public $numOfColumns = 12; + private static $uidCounter = 0; /** @var string $name */ private $name; diff --git a/src/Inputs/CheckboxInput.php b/src/Inputs/CheckboxInput.php index 23e3a65..cf1e778 100644 --- a/src/Inputs/CheckboxInput.php +++ b/src/Inputs/CheckboxInput.php @@ -36,27 +36,14 @@ class CheckboxInput extends Checkbox implements IValidationInput */ public $allignWithInputControls; + /** + * @param string|object $label + */ public function __construct($label = null) { $this->allignWithInputControls = static::$defaultAllignWithInputControls; - parent::__construct($label); - } - /** - * Generates a checkbox - */ - public function getControl(): Html - { - return self::makeCheckbox( - $this->getHtmlName(), - $this->getHtmlId(), - $this->translate($this->caption), - $this->value, - false, - $this->required, - $this->disabled, - $this->getRules() - ); + parent::__construct($label); } /** @@ -78,13 +65,13 @@ public static function makeCheckbox( { $label = Html::el('label', ['class' => BootstrapForm::getBootstrapVersion() === BootstrapVersion::V5 ? 'form-check' : ['custom-control', 'custom-checkbox']]); $input = Html::el('input', [ - 'type' => 'checkbox', - 'class' => [BootstrapForm::getBootstrapVersion() === BootstrapVersion::V5 ? 'form-check-input' : 'custom-control-input'], - 'name' => $name, - 'disabled' => $disabled, - 'required' => $required, - 'checked' => $checked, - 'id' => $htmlId, + 'type' => 'checkbox', + 'class' => [BootstrapForm::getBootstrapVersion() === BootstrapVersion::V5 ? 'form-check-input' : 'custom-control-input'], + 'name' => $name, + 'disabled' => $disabled, + 'required' => $required, + 'checked' => $checked, + 'id' => $htmlId, 'data-nette-rules' => $rules ? Nette\Forms\Helpers::exportRules($rules) : false, ]); if ($value !== false) { @@ -97,7 +84,7 @@ public static function makeCheckbox( $label->addHtml( Html::el('label', [ 'class' => [BootstrapForm::getBootstrapVersion() === BootstrapVersion::V5 ? 'form-check-label' : 'custom-control-label'], - 'for' => $htmlId, + 'for' => $htmlId, ])->setText($caption) ); @@ -107,6 +94,22 @@ public static function makeCheckbox( return $label; } + /** + * Generates a checkbox + */ + public function getControl(): Html + { + return self::makeCheckbox( + $this->getHtmlName(), + $this->getHtmlId(), + $this->translate($this->caption), + $this->value, + false, + $this->required, + $this->disabled, + $this->getRules() + ); + } /** * Modify control in such a way that it explicitly shows its validation state. diff --git a/src/Inputs/CheckboxListInput.php b/src/Inputs/CheckboxListInput.php index e75f52c..bd51434 100644 --- a/src/Inputs/CheckboxListInput.php +++ b/src/Inputs/CheckboxListInput.php @@ -25,6 +25,7 @@ class CheckboxListInput extends CheckboxList implements IValidationInput public function getControl(): Html { parent::getControl(); + $fieldset = Html::el('fieldset', [ 'disabled' => $this->isControlDisabled(), ]); diff --git a/src/Inputs/DateInput.php b/src/Inputs/DateInput.php index e37601a..0acfd06 100644 --- a/src/Inputs/DateInput.php +++ b/src/Inputs/DateInput.php @@ -16,7 +16,7 @@ class DateInput extends TextInput { - /** @var string */ + /** @var string */ public static $defaultFormat = DateTimeFormat::D_DMY_DOTS_NO_LEAD; /** @var string[] */ @@ -54,9 +54,7 @@ public function __construct($label = null, ?int $maxLength = null) parent::__construct($label, null); - $this->addRule(function ($input) { - return DateTimeFormat::validate($this->format, $input->value); - }, $this->invalidFormatMessage); + $this->addRule(fn ($input) => DateTimeFormat::validate($this->format, $input->value), $this->invalidFormatMessage); $this->setFormat(static::$defaultFormat); } @@ -96,11 +94,13 @@ public function setValue($value) { if ($value instanceof DateTimeInterface) { parent::setValue($value->format($this->format)); + $this->validate(); return $this; } elseif (is_string($value) && DateTimeFormat::validate($this->format, $value)) { parent::setValue($value); + $this->validate(); return $this; @@ -119,6 +119,7 @@ public function setValue($value) if ($date !== false) { parent::setValue($date->format($this->format)); + $this->validate(); return $this; @@ -145,6 +146,7 @@ public function getControl(): Html public function validate(): void { parent::validate(); + $this->isValidated = true; } diff --git a/src/Inputs/DateTimeInput.php b/src/Inputs/DateTimeInput.php index 5566d3a..0732dfe 100644 --- a/src/Inputs/DateTimeInput.php +++ b/src/Inputs/DateTimeInput.php @@ -12,7 +12,7 @@ class DateTimeInput extends DateInput { - /** @var string */ + /** @var string */ public static $defaultFormat = DateTimeFormat::D_DMY_DOTS_NO_LEAD . ' ' . DateTimeFormat::T_24_NO_LEAD; /** @var string[] */ diff --git a/src/Inputs/MultiselectInput.php b/src/Inputs/MultiselectInput.php index 888c1ad..5d9f1c4 100644 --- a/src/Inputs/MultiselectInput.php +++ b/src/Inputs/MultiselectInput.php @@ -40,7 +40,7 @@ public function getControl(): Html $select = parent::getControl(); $select->attrs += [ - 'class' => [BootstrapForm::getBootstrapVersion() === BootstrapVersion::V5 ? 'form-select' : 'form-control'], + 'class' => [BootstrapForm::getBootstrapVersion() === BootstrapVersion::V5 ? 'form-select' : 'form-control'], 'disabled' => $this->isControlDisabled(), ]; diff --git a/src/Inputs/RadioInput.php b/src/Inputs/RadioInput.php index 41ae0cb..4692f84 100644 --- a/src/Inputs/RadioInput.php +++ b/src/Inputs/RadioInput.php @@ -15,7 +15,7 @@ /** * Class RadioInput. Lets user choose one out of multiple options. */ -class RadioInput extends RadioList implements IValidationInput +class RadioInput extends RadioList implements IValidationInput { use ChoiceInputTrait; @@ -30,6 +30,7 @@ class RadioInput extends RadioList implements IValidationInput public function __construct($label = null, ?array $items = null) { parent::__construct($label, $items); + $this->control->type = 'radio'; $this->container = Html::el('fieldset'); $this->setOption(RendererOptions::TYPE, 'radio'); @@ -57,13 +58,13 @@ public function getControl(): Html ]); $input = Html::el('input', [ - 'class' => [BootstrapForm::getBootstrapVersion() === BootstrapVersion::V5 ? 'form-check-input' : 'custom-control-input'], - 'type' => 'radio', - 'value' => $value, - 'name' => $this->getHtmlName(), - 'checked' => $this->isValueSelected($value), + 'class' => [BootstrapForm::getBootstrapVersion() === BootstrapVersion::V5 ? 'form-check-input' : 'custom-control-input'], + 'type' => 'radio', + 'value' => $value, + 'name' => $this->getHtmlName(), + 'checked' => $this->isValueSelected($value), 'disabled' => $disabledOption, - 'id' => $itemHtmlId, + 'id' => $itemHtmlId, ]); if ($c === 0) { // the first (0th) input has data-nette-rules, none other @@ -75,7 +76,7 @@ public function getControl(): Html $wrapper->addHtml( Html::el('label', [ 'class' => [BootstrapForm::getBootstrapVersion() === BootstrapVersion::V5 ? 'form-check-label' : 'custom-control-label'], - 'for' => $itemHtmlId, + 'for' => $itemHtmlId, ])->addHtml($this->translate($caption)) ); diff --git a/src/Inputs/SelectInput.php b/src/Inputs/SelectInput.php index 1c2ba91..58f9963 100644 --- a/src/Inputs/SelectInput.php +++ b/src/Inputs/SelectInput.php @@ -28,6 +28,7 @@ class SelectInput extends SelectBox implements IValidationInput public function __construct($label = null, ?array $items = null) { parent::__construct($label); + if ($items !== null) { $this->setItems($items); } @@ -41,7 +42,7 @@ public function getControl(): Html $select = parent::getControl(); $select->attrs += [ - 'class' => [BootstrapForm::getBootstrapVersion() === BootstrapVersion::V5 ? 'form-select' : 'custom-select'], + 'class' => [BootstrapForm::getBootstrapVersion() === BootstrapVersion::V5 ? 'form-select' : 'custom-select'], 'disabled' => $this->isControlDisabled(), ]; diff --git a/src/Inputs/TextAreaInput.php b/src/Inputs/TextAreaInput.php index c310ebf..7b15b1e 100644 --- a/src/Inputs/TextAreaInput.php +++ b/src/Inputs/TextAreaInput.php @@ -21,6 +21,7 @@ class TextAreaInput extends TextArea implements IValidationInput, IAutocompleteI public function __construct($label = null) { parent::__construct($label); + $this->setRequired(false); } diff --git a/src/Inputs/TextInput.php b/src/Inputs/TextInput.php index e3c8bb4..7752189 100644 --- a/src/Inputs/TextInput.php +++ b/src/Inputs/TextInput.php @@ -29,6 +29,7 @@ class TextInput extends \Nette\Forms\Controls\TextInput implements IValidationIn public function __construct($label = null, ?int $maxLength = null) { parent::__construct($label, $maxLength); + $this->setRequired(false); } @@ -96,6 +97,9 @@ public function setPlaceholder(string $placeholder) return $this; } + /** + * @param object|string $caption + */ public function getLabel($caption = null): Html { /** @var Html $label */ diff --git a/src/Inputs/UploadInput.php b/src/Inputs/UploadInput.php index fc084db..b524300 100644 --- a/src/Inputs/UploadInput.php +++ b/src/Inputs/UploadInput.php @@ -56,7 +56,7 @@ public function getControl() $el->addHtml( Html::el('label', [ 'class' => [BootstrapForm::getBootstrapVersion() === BootstrapVersion::V5 ? 'form-label' : 'custom-file-label'], - 'for' => $this->getHtmlId(), + 'for' => $this->getHtmlId(), ])->setText($this->buttonCaption) ); diff --git a/src/Traits/BootstrapButtonTrait.php b/src/Traits/BootstrapButtonTrait.php index bd1a3b1..8de7305 100644 --- a/src/Traits/BootstrapButtonTrait.php +++ b/src/Traits/BootstrapButtonTrait.php @@ -13,9 +13,6 @@ trait BootstrapButtonTrait { - /** @var string */ - private $btnClass = 'btn-primary'; - /** * set to true so that buttons by defaults are alligned on right with input fields * @@ -30,6 +27,9 @@ trait BootstrapButtonTrait */ public $allignWithInputControls; + /** @var string */ + private $btnClass = 'btn-primary'; + /** * Gets additional button class. Default is btn-primary. */ @@ -61,12 +61,6 @@ public function getControl($caption = null): Html return $control; } - protected function addBtnClass(Html $element): void - { - BootstrapUtils::standardizeClass($element); - $element->class[] = 'btn ' . $this->getBtnClass(); - } - public function allignWithInputControls(): bool { return $this->allignWithInputControls ?? self::$defaultAllignWithInputControls; @@ -77,4 +71,10 @@ public function setAllignWithInputControls(bool $allignWithControls = true): voi $this->allignWithInputControls = $allignWithControls; } + protected function addBtnClass(Html $element): void + { + BootstrapUtils::standardizeClass($element); + $element->class[] = 'btn ' . $this->getBtnClass(); + } + } diff --git a/src/Traits/FakeControlTrait.php b/src/Traits/FakeControlTrait.php index 5648951..44b4466 100644 --- a/src/Traits/FakeControlTrait.php +++ b/src/Traits/FakeControlTrait.php @@ -62,6 +62,7 @@ public function setValue($value): Control */ public function validate(): void { + //intentionally empty } } diff --git a/tests/Grid/BootstrapCellTest.php b/tests/Grid/BootstrapCellTest.php index 979b3d5..29fd611 100644 --- a/tests/Grid/BootstrapCellTest.php +++ b/tests/Grid/BootstrapCellTest.php @@ -21,14 +21,6 @@ class BootstrapCellTest extends BaseTest /** @var BootstrapRow */ private $row; - protected function setUp(): void - { - $this->form = new BootstrapForm(); - $this->row = $this->form->addRow(); - $this->cell = $this->row->addCell(12); - $this->form->setParent($this->createMock(Presenter::class)); - } - public function testAddClass(): void { $this->cell->addHtmlClass('new-class'); @@ -59,4 +51,12 @@ public function testGroup(): void $this->assertEquals($first, $this->cell->getCurrentGroup()); } + protected function setUp(): void + { + $this->form = new BootstrapForm(); + $this->row = $this->form->addRow(); + $this->cell = $this->row->addCell(12); + $this->form->setParent($this->createMock(Presenter::class)); + } + } diff --git a/tests/Rendering/SideBySideTest.php b/tests/Rendering/SideBySideTest.php index e0cf77b..e2613dd 100644 --- a/tests/Rendering/SideBySideTest.php +++ b/tests/Rendering/SideBySideTest.php @@ -11,16 +11,9 @@ class SideBySideTest extends BaseTest { - /** @var BootstrapForm */ + /** @var BootstrapForm */ private $form; - protected function setUp(): void - { - $this->form = new BootstrapForm(); - $this->form->setRenderer(new BootstrapRenderer(RenderMode::SIDE_BY_SIDE_MODE)); - $this->form->setParent($this->createMock(Presenter::class)); - } - public function testEmpty(): void { $this->expectOutputString($this->loadTextData('empty_form.html')); @@ -88,7 +81,6 @@ public function testTextArea(): void $this->form->render(); } - public function testErrorRendering(): void { $this->form->addText('a')->addError('test-error'); @@ -96,4 +88,11 @@ public function testErrorRendering(): void $this->form->render(); } + protected function setUp(): void + { + $this->form = new BootstrapForm(); + $this->form->setRenderer(new BootstrapRenderer(RenderMode::SIDE_BY_SIDE_MODE)); + $this->form->setParent($this->createMock(Presenter::class)); + } + }