diff --git a/src/InputRenderer.php b/src/InputRenderer.php index a18031f..43361cd 100644 --- a/src/InputRenderer.php +++ b/src/InputRenderer.php @@ -148,7 +148,7 @@ class InputRenderer * @param string|string[]|null $collection_name collection name(s) for inputs, e.g. 'myform' or ['myform', '123'] etc. * @param string|null $id_prefix base id for inputs, e.g. 'myform' or 'myform-123', etc. */ - public function __construct($model = null, $collection_name = null, $id_prefix = null) + public function __construct($model = null, $collection_name = null, $id_prefix = "form") { $this->model = InputModel::create($model); $this->collection_name = $collection_name; diff --git a/tests/unit/FieldRenderCest.php b/tests/unit/FieldRenderCest.php index 472281d..3321ca5 100644 --- a/tests/unit/FieldRenderCest.php +++ b/tests/unit/FieldRenderCest.php @@ -26,38 +26,38 @@ public function renderTextFields(UnitTester $I) $model = $form->model; $field = new TextField('value'); - $I->assertSame('', $form->render($field), + $I->assertSame('', $form->render($field), 'basic input with no value-attribute'); $field->setValue($model, 'Hello World'); - $I->assertSame('', + $I->assertSame('', $form->render($field), 'basic input with value-attribute'); $field->max_length = 50; - $I->assertSame('', + $I->assertSame('', $form->render($field), 'input with value and maxlength-attribute'); $field->setPlaceholder('hello'); - $I->assertSame('', + $I->assertSame('', $form->render($field), 'input with value, maxlength and placeholder-attributes'); - $I->assertSame('', + $I->assertSame('', $form->render($field, ['data-foo' => 'bar']), 'input with custom data-attribute overridden'); - $I->assertSame('', + $I->assertSame('', $form->render($field, ['placeholder' => 'override']), 'input with placeholder-attribute overridden'); $field->setValue($model, 'this & that'); - $I->assertSame('', + $I->assertSame('', $form->render($field), 'input with value-attribute escaped as HTML'); $field = new TextField("value"); $field->setPattern('[A-Z]{2}', 'Enter two-letter ISO language code'); - $I->assertSame('', + $I->assertSame('', $form->render($field)); } @@ -69,7 +69,7 @@ public function renderPasswordField(UnitTester $I) $field->setValue($model, 'supersecret'); - $I->assertSame('', $form->render($field), + $I->assertSame('', $form->render($field), 'input with type=password'); } @@ -93,7 +93,7 @@ public function renderEmailField(UnitTester $I) $field->setValue($model, 'foo@bar.baz'); - $I->assertSame('', + $I->assertSame('', $form->render($field), 'input with type=email (html5)'); } @@ -105,7 +105,7 @@ public function renderTextArea(UnitTester $I) $field->setValue($model, 'this & that'); - $I->assertSame('', $form->render($field), + $I->assertSame('', $form->render($field), 'simple textarea with content'); } @@ -154,22 +154,22 @@ public function renderSelectTags(UnitTester $I) 2 => 'Option Two', ]); - $I->assertSame('', + $I->assertSame('', $form->render($field)); $field->setValue($form->model, 1); - $I->assertSame('', + $I->assertSame('', $form->render($field)); $field->disabled = 'Please select'; - $I->assertSame('', + $I->assertSame('', $form->render($field)); $field->setValue($form->model, null); - $I->assertSame('', + $I->assertSame('', $form->render($field)); } @@ -204,16 +204,16 @@ public function renderIntField(UnitTester $I) $field = new IntField("value"); - $I->assertSame('', $form->render($field)); + $I->assertSame('', $form->render($field)); $field->min_value = -1; - $I->assertSame('', $form->render($field)); + $I->assertSame('', $form->render($field)); $field->min_value = 1; $field->max_value = 99; - $I->assertSame('', $form->render($field)); + $I->assertSame('', $form->render($field)); } public function renderFloatField(UnitTester $I) @@ -222,16 +222,16 @@ public function renderFloatField(UnitTester $I) $field = new FloatField("value"); - $I->assertSame('', $form->render($field)); + $I->assertSame('', $form->render($field)); $field->min_value = -1; - $I->assertSame('', $form->render($field)); + $I->assertSame('', $form->render($field)); $field->min_value = 1; $field->max_value = 99; - $I->assertSame('', $form->render($field)); + $I->assertSame('', $form->render($field)); } public function renderDateTimeField(UnitTester $I) @@ -240,7 +240,7 @@ public function renderDateTimeField(UnitTester $I) $field = new DateTimeField('value', 'Europe/Copenhagen', 'Y-m-d H:i:s', ['readonly' => true]); $field->setValue($form->model, 173919600); - $I->assertSame('', + $I->assertSame('', $form->render($field)); } @@ -269,17 +269,17 @@ public function renderDateSelector(UnitTester $I) $I->expectParts( $form->render($field), [ - '', '', '', '', '', - '', '', '', '', '', - '', '', '', '', @@ -291,11 +291,11 @@ public function renderDateSelector(UnitTester $I) $I->expectParts( $form->render($field), [ - '', '', - '', '', - '', '', ] ); @@ -304,11 +304,11 @@ public function renderDateSelector(UnitTester $I) $I->expectParts( $form->render($field), [ - '', '', - '', '', - '', '', ] ); diff --git a/tests/unit/InputRendererCest.php b/tests/unit/InputRendererCest.php index c9693af..fdc481d 100644 --- a/tests/unit/InputRendererCest.php +++ b/tests/unit/InputRendererCest.php @@ -15,21 +15,24 @@ public function handleAttributes(UnitTester $I) $form = new InputRenderer(); $field = new TextField('text'); - $I->assertSame('', + $I->assertSame('', $form->render($field, ['class' => ['foo', 'bar']]), 'folds multi-valued class attribute'); - $I->assertSame('', + $I->assertSame('', $form->render($field, ['readonly' => true]), 'handles boolean TRUE attribute value'); - $I->assertSame('', + $I->assertSame('', $form->render($field, ['readonly' => false]), 'handles boolean FALSE attribute value'); - $I->assertSame('', + $I->assertSame('', $form->render($field, ['foo' => null]), 'filters NULL-value attributes'); $form->xhtml = true; - $I->assertSame('', + $I->assertSame('', $form->render($field, ['readonly' => true]), 'renders value-less attributes as valid XHTML'); $form->xhtml = false; $I->assertSame('text', $form->getName($field), 'name without prefix'); + + $form->id_prefix = null; + $I->assertSame(null, $form->getId($field), 'no id attribute when $id_prefix is NULL'); $form->collection_name = 'form'; @@ -126,7 +129,7 @@ public function renderContainerTags(UnitTester $I) $I->assertSame('
foo & bar
', $form->divFor($field, 'foo & bar', ['data-foo' => 'bar'])); - $I->assertSame('
', + $I->assertSame('
', $form->renderDiv($field, ['data-input' => 'foo'], ['data-div' => 'bar'])); $field->setRequired(true); @@ -136,7 +139,7 @@ public function renderContainerTags(UnitTester $I) $I->assertSame('
foo & bar
', $form->divFor($field, 'foo & bar', ['data-foo' => 'bar'])); - $I->assertSame('
', + $I->assertSame('
', $form->renderDiv($field, ['class' => 'foo'], ['class' => ['foo', 'bar']])); } @@ -166,7 +169,7 @@ public function renderInputGroups(UnitTester $I) public function renderLabelTags(UnitTester $I) { - $form = new InputRenderer(); + $form = new InputRenderer(null, null, null); $field = new TextField('text'); $I->assertException( @@ -225,7 +228,7 @@ public function overridePlaceholders(UnitTester $I) $form->setPlaceholder($field, "Hello"); - $I->assertSame('', $form->render($field)); + $I->assertSame('', $form->render($field)); } public function overrideRequired(UnitTester $I) @@ -236,7 +239,7 @@ public function overrideRequired(UnitTester $I) $form->setRequired($field); - $I->assertSame('
', $form->renderDiv($field)); + $I->assertSame('
', $form->renderDiv($field)); } public function buildInput(UnitTester $I)