Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
- Bug #37: Apply last changes from `ui-awesome/html-core` package to `ui-awesome/html` package (@terabytesoftw)
- Bug #38: Remove redundant `afterRun()` method from `Dl`, `Ol`, and `Ul` classes (@terabytesoftw)
- Enh #39: Add `InputMonth` class for HTML `<input type="month">` element with attributes and rendering capabilities (@terabytesoftw)
- Bug #40: Refactor tests to use `assertSame()` for rendering with `testRenderWithGlobalDefaultsAreApplied()` and `testRenderWithUserOverridesGlobalDefaults()` (@terabytesoftw)

## 0.3.0 March 31, 2024

Expand Down
44 changes: 33 additions & 11 deletions tests/Form/InputCheckboxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -636,15 +636,25 @@ public function testRenderWithGenerateId(): void

public function testRenderWithGlobalDefaultsAreApplied(): void
{
SimpleFactory::setDefaults(InputCheckbox::class, ['class' => 'default-class']);
SimpleFactory::setDefaults(
InputCheckbox::class,
['class' => 'default-class'],
);

self::assertStringContainsString(
'class="default-class"',
InputCheckbox::tag()->render(),
self::assertSame(
<<<HTML
<input class="default-class" id="inputcheckbox" type="checkbox">
HTML,
InputCheckbox::tag()
->id('inputcheckbox')
->render(),
'Failed asserting that global defaults are applied correctly.',
);

SimpleFactory::setDefaults(InputCheckbox::class, []);
SimpleFactory::setDefaults(
InputCheckbox::class,
[],
);
}

public function testRenderWithHidden(): void
Expand Down Expand Up @@ -1089,14 +1099,26 @@ public function testRenderWithUncheckedValueAndEnclosedByLabel(): void

public function testRenderWithUserOverridesGlobalDefaults(): void
{
SimpleFactory::setDefaults(InputCheckbox::class, ['class' => 'from-global', 'id' => 'id-global']);

$output = InputCheckbox::tag(['id' => 'id-user'])->render();
SimpleFactory::setDefaults(
InputCheckbox::class,
[
'class' => 'from-global',
'id' => 'id-global',
],
);

self::assertStringContainsString('class="from-global"', $output);
self::assertStringContainsString('id="id-user"', $output);
self::assertSame(
<<<HTML
<input class="from-global" id="id-user" type="checkbox">
HTML,
InputCheckbox::tag(['id' => 'id-user'])->render(),
'Failed asserting that user-defined attributes override global defaults correctly.',
);

SimpleFactory::setDefaults(InputCheckbox::class, []);
SimpleFactory::setDefaults(
InputCheckbox::class,
[],
);
}

public function testRenderWithValue(): void
Expand Down
48 changes: 34 additions & 14 deletions tests/Form/InputHiddenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -435,15 +435,25 @@ public function testRenderWithGenerateId(): void

public function testRenderWithGlobalDefaultsAreApplied(): void
{
SimpleFactory::setDefaults(InputHidden::class, ['class' => 'default-class']);
SimpleFactory::setDefaults(
InputHidden::class,
['class' => 'default-class'],
);

self::assertStringContainsString(
'class="default-class"',
InputHidden::tag()->render(),
self::assertSame(
<<<HTML
<input class="default-class" id="inputhidden" type="hidden">
HTML,
InputHidden::tag()
->id('inputhidden')
->render(),
'Failed asserting that global defaults are applied correctly.',
);

SimpleFactory::setDefaults(InputHidden::class, []);
SimpleFactory::setDefaults(
InputHidden::class,
[],
);
}

public function testRenderWithHidden(): void
Expand Down Expand Up @@ -607,9 +617,7 @@ public function testRenderWithToString(): void
<<<HTML
<input type="hidden">
HTML,
InputHidden::tag()
->id(null)
->render(),
(string) InputHidden::tag()->id(null),
"Failed asserting that '__toString()' method renders correctly.",
);
}
Expand Down Expand Up @@ -638,14 +646,26 @@ public function testRenderWithTranslateUsingEnum(): void

public function testRenderWithUserOverridesGlobalDefaults(): void
{
SimpleFactory::setDefaults(InputHidden::class, ['class' => 'from-global', 'id' => 'id-global']);

$output = InputHidden::tag(['id' => 'id-user'])->render();
SimpleFactory::setDefaults(
InputHidden::class,
[
'class' => 'from-global',
'id' => 'id-global',
],
);

self::assertStringContainsString('class="from-global"', $output);
self::assertStringContainsString('id="id-user"', $output);
self::assertSame(
<<<HTML
<input class="from-global" id="id-user" type="hidden">
HTML,
InputHidden::tag(['id' => 'id-user'])->render(),
'Failed asserting that user-defined attributes override global defaults correctly.',
);

SimpleFactory::setDefaults(InputHidden::class, []);
SimpleFactory::setDefaults(
InputHidden::class,
[],
);
}

public function testRenderWithValue(): void
Expand Down
43 changes: 30 additions & 13 deletions tests/Form/InputNumberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -506,15 +506,25 @@ public function testRenderWithGenerateId(): void

public function testRenderWithGlobalDefaultsAreApplied(): void
{
SimpleFactory::setDefaults(InputNumber::class, ['class' => 'default-class']);
SimpleFactory::setDefaults(
InputNumber::class,
['class' => 'default-class'],
);

self::assertStringContainsString(
'class="default-class"',
InputNumber::tag()->render(),
self::assertSame(
<<<HTML
<input class="default-class" id="inputnumber" type="number">
HTML,
InputNumber::tag()
->id('inputnumber')
->render(),
'Failed asserting that global defaults are applied correctly.',
);

SimpleFactory::setDefaults(InputNumber::class, []);
SimpleFactory::setDefaults(
InputNumber::class,
[],
);
}

public function testRenderWithHidden(): void
Expand Down Expand Up @@ -848,9 +858,7 @@ public function testRenderWithToString(): void
<<<HTML
<input type="number">
HTML,
InputNumber::tag()
->id(null)
->render(),
(string) InputNumber::tag()->id(null),
"Failed asserting that '__toString()' method renders correctly.",
);
}
Expand Down Expand Up @@ -885,12 +893,21 @@ public function testRenderWithTranslateUsingEnum(): void

public function testRenderWithUserOverridesGlobalDefaults(): void
{
SimpleFactory::setDefaults(InputNumber::class, ['class' => 'from-global', 'id' => 'id-global']);

$output = InputNumber::tag(['id' => 'id-user'])->render();
SimpleFactory::setDefaults(
InputNumber::class,
[
'class' => 'from-global',
'id' => 'id-global',
],
);

self::assertStringContainsString('class="from-global"', $output);
self::assertStringContainsString('id="id-user"', $output);
self::assertSame(
<<<HTML
<input class="from-global" id="id-user" type="number">
HTML,
InputNumber::tag(['id' => 'id-user'])->render(),
'Failed asserting that user-defined attributes override global defaults correctly.',
);

SimpleFactory::setDefaults(InputNumber::class, []);
}
Expand Down
48 changes: 34 additions & 14 deletions tests/Form/InputPasswordTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -458,15 +458,25 @@ public function testRenderWithGenerateId(): void

public function testRenderWithGlobalDefaultsAreApplied(): void
{
SimpleFactory::setDefaults(InputPassword::class, ['class' => 'default-class']);
SimpleFactory::setDefaults(
InputPassword::class,
['class' => 'default-class'],
);

self::assertStringContainsString(
'class="default-class"',
InputPassword::tag()->render(),
self::assertSame(
<<<HTML
<input class="default-class" id="inputpassword" type="password">
HTML,
InputPassword::tag()
->id('inputpassword')
->render(),
'Failed asserting that global defaults are applied correctly.',
);

SimpleFactory::setDefaults(InputPassword::class, []);
SimpleFactory::setDefaults(
InputPassword::class,
[],
);
}

public function testRenderWithHidden(): void
Expand Down Expand Up @@ -740,9 +750,7 @@ public function testRenderWithToString(): void
<<<HTML
<input type="password">
HTML,
InputPassword::tag()
->id(null)
->render(),
(string) InputPassword::tag()->id(null),
"Failed asserting that '__toString()' method renders correctly.",
);
}
Expand Down Expand Up @@ -771,14 +779,26 @@ public function testRenderWithTranslateUsingEnum(): void

public function testRenderWithUserOverridesGlobalDefaults(): void
{
SimpleFactory::setDefaults(InputPassword::class, ['class' => 'from-global', 'id' => 'id-global']);

$output = InputPassword::tag(['id' => 'id-user'])->render();
SimpleFactory::setDefaults(
InputPassword::class,
[
'class' => 'from-global',
'id' => 'id-global',
],
);

self::assertStringContainsString('class="from-global"', $output);
self::assertStringContainsString('id="id-user"', $output);
self::assertSame(
<<<HTML
<input class="from-global" id="id-user" type="password">
HTML,
InputPassword::tag(['id' => 'id-user'])->render(),
'Failed asserting that user-defined attributes override global defaults correctly.',
);

SimpleFactory::setDefaults(InputPassword::class, []);
SimpleFactory::setDefaults(
InputPassword::class,
[],
);
}

public function testRenderWithValue(): void
Expand Down
43 changes: 30 additions & 13 deletions tests/Form/InputRadioTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -646,15 +646,25 @@ public function testRenderWithGenerateId(): void

public function testRenderWithGlobalDefaultsAreApplied(): void
{
SimpleFactory::setDefaults(InputRadio::class, ['class' => 'default-class']);
SimpleFactory::setDefaults(
InputRadio::class,
['class' => 'default-class'],
);

self::assertStringContainsString(
'class="default-class"',
InputRadio::tag()->render(),
self::assertSame(
<<<HTML
<input class="default-class" id="inputradio" type="radio">
HTML,
InputRadio::tag()
->id('inputradio')
->render(),
'Failed asserting that global defaults are applied correctly.',
);

SimpleFactory::setDefaults(InputRadio::class, []);
SimpleFactory::setDefaults(
InputRadio::class,
[],
);
}

public function testRenderWithHidden(): void
Expand Down Expand Up @@ -1026,9 +1036,7 @@ public function testRenderWithToString(): void
<<<HTML
<input type="radio">
HTML,
InputRadio::tag()
->id(null)
->render(),
(string) InputRadio::tag()->id(null),
"Failed asserting that '__toString()' method renders correctly.",
);
}
Expand Down Expand Up @@ -1101,12 +1109,21 @@ public function testRenderWithUncheckedValueAndEnclosedByLabel(): void

public function testRenderWithUserOverridesGlobalDefaults(): void
{
SimpleFactory::setDefaults(InputRadio::class, ['class' => 'from-global', 'id' => 'id-global']);

$output = InputRadio::tag(['id' => 'id-user'])->render();
SimpleFactory::setDefaults(
InputRadio::class,
[
'class' => 'from-global',
'id' => 'id-global',
],
);

self::assertStringContainsString('class="from-global"', $output);
self::assertStringContainsString('id="id-user"', $output);
self::assertSame(
<<<HTML
<input class="from-global" id="id-user" type="radio">
HTML,
InputRadio::tag(['id' => 'id-user'])->render(),
'Failed asserting that user-defined attributes override global defaults correctly.',
);

SimpleFactory::setDefaults(InputRadio::class, []);
}
Expand Down
Loading
Loading