Skip to content

Commit

Permalink
Merge pull request #19 from tales-from-a-dev/feature/id-on-errors
Browse files Browse the repository at this point in the history
✨ Add id on errors
  • Loading branch information
ker0x authored Dec 3, 2023
2 parents 5b8f131 + 50f4aa8 commit 063ac27
Show file tree
Hide file tree
Showing 24 changed files with 110 additions and 168 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[![Tests](https://img.shields.io/github/actions/workflow/status/tales-from-a-dev/flowbite-bundle/ci.yml?label=tests&style=for-the-badge)](https://github.com/tales-from-a-dev/flowbite-bundle/actions/workflows/ci.yml)
![PHP Version](https://img.shields.io/badge/php->=8.2-4f5b93.svg?style=for-the-badge)
![Symfony Version](https://img.shields.io/badge/symfony->=6.2-000.svg?style=for-the-badge)
![Symfony Version](https://img.shields.io/badge/symfony->=6.4-000.svg?style=for-the-badge)
[![Flowbite Version](https://img.shields.io/badge/flowbite->=1.6-1c64f2.svg?style=for-the-badge)](https://flowbite.com)
[![Packagist Version](https://img.shields.io/packagist/v/tales-from-a-dev/flowbite-bundle?style=for-the-badge)](https://packagist.org/packages/tales-from-a-dev/flowbite-bundle)
[![License](https://img.shields.io/github/license/talesfromadev/flowbite-bundle?style=for-the-badge)](https://github.com/tales-from-a-dev/flowbite-bundle/blob/main/LICENSE)
Expand Down
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@
],
"require": {
"php": ">=8.2",
"symfony/http-kernel": "^6.2 || ^7.0",
"symfony/twig-bridge": "^6.2 || ^7.0",
"symfony/http-kernel": "^6.4 || ^7.0",
"symfony/twig-bridge": "^6.4 || ^7.0",
"tales-from-a-dev/twig-tailwind-extra": "^0.2"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.15",
"phpunit/phpunit": "^10.0",
"symfony/form": "^6.2 || ^7.0",
"symfony/intl": "^6.2 || ^7.0",
"symfony/security-csrf": "^6.2 || ^7.0",
"symfony/translation": "^6.2 || ^7.0"
"symfony/form": "^6.4 || ^7.0",
"symfony/intl": "^6.4 || ^7.0",
"symfony/security-csrf": "^6.4 || ^7.0",
"symfony/translation": "^6.4 || ^7.0"
},
"config": {
"optimize-autoloader": true,
Expand Down
4 changes: 2 additions & 2 deletions templates/form/default.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@

{%- block form_errors -%}
{%- if errors|length > 0 -%}
{%- for error in errors -%}
<p class="{{ block('class_text_error') }}">{{ error.message }}</p>
{%- for key, error in errors -%}
<p id="{{ id }}_error_{{ key }}" class="{{ block('class_text_error') }}">{{ error.message }}</p>
{%- endfor -%}
{%- endif -%}
{%- endblock form_errors -%}
Expand Down
58 changes: 58 additions & 0 deletions tests/AbstractFlowbiteLayoutTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

declare(strict_types=1);

namespace TalesFromADev\FlowbiteBundle\Tests;

use Symfony\Bridge\Twig\Extension\FormExtension;
use Symfony\Bridge\Twig\Extension\TranslationExtension;
use Symfony\Bridge\Twig\Test\FormLayoutTestCase;
use Symfony\Component\Form\FormRenderer;
use Symfony\Component\Form\FormView;
use TalesFromADev\FlowbiteBundle\Tests\Fixtures\StubTranslator;
use TalesFromADev\Twig\Extra\Tailwind\TailwindExtension;
use TalesFromADev\Twig\Extra\Tailwind\TailwindRuntime;
use Twig\Environment;
use Twig\RuntimeLoader\RuntimeLoaderInterface;

abstract class AbstractFlowbiteLayoutTestCase extends FormLayoutTestCase
{
protected function registerTwigRuntimeLoader(Environment $environment, FormRenderer $renderer): void
{
parent::registerTwigRuntimeLoader($environment, $renderer);

$tailwindLoader = $this->createMock(RuntimeLoaderInterface::class);
$tailwindLoader->expects($this->any())->method('load')->willReturn(new TailwindRuntime());

$environment->addRuntimeLoader($tailwindLoader);
}

protected function assertWidgetMatchesXpath(FormView $view, array $vars, string $xpath): void
{
$this->assertMatchesXpath($this->renderWidget($view, array_merge([], $vars)), $xpath);
}

protected function getTemplatePaths(): array
{
return [
__DIR__.'/../vendor/symfony/twig-bridge/Resources/views/Form',
__DIR__.'/../templates/form',
];
}

protected function getTwigExtensions(): array
{
return [
new TranslationExtension(new StubTranslator()),
new FormExtension(),
new TailwindExtension(),
];
}

protected function getThemes(): array
{
return [
'default.html.twig',
];
}
}
5 changes: 3 additions & 2 deletions tests/FormLayout/BirthdayLayoutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
namespace TalesFromADev\FlowbiteBundle\Tests\FormLayout;

use Symfony\Component\Form\Extension\Core\Type\BirthdayType;
use TalesFromADev\FlowbiteBundle\Tests\FormLayoutTestCase;
use TalesFromADev\FlowbiteBundle\Tests\AbstractFlowbiteLayoutTestCase;

final class BirthdayLayoutTest extends FormLayoutTestCase
final class BirthdayLayoutTest extends AbstractFlowbiteLayoutTestCase
{
public function testBirthDay(): void
{
$form = $this->factory->createNamed('birthday', BirthdayType::class, '2000-02-03', [
'input' => 'string',
'widget' => 'choice',
]);

$this->assertWidgetMatchesXpath($form->createView(), [],
Expand Down
4 changes: 2 additions & 2 deletions tests/FormLayout/ButtonLayoutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
namespace TalesFromADev\FlowbiteBundle\Tests\FormLayout;

use Symfony\Component\Form\Extension\Core\Type\ButtonType;
use TalesFromADev\FlowbiteBundle\Tests\FormLayoutTestCase;
use TalesFromADev\FlowbiteBundle\Tests\AbstractFlowbiteLayoutTestCase;

final class ButtonLayoutTest extends FormLayoutTestCase
final class ButtonLayoutTest extends AbstractFlowbiteLayoutTestCase
{
public function testButton(): void
{
Expand Down
4 changes: 2 additions & 2 deletions tests/FormLayout/CheckboxLayoutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\FormError;
use TalesFromADev\FlowbiteBundle\Tests\FormLayoutTestCase;
use TalesFromADev\FlowbiteBundle\Tests\AbstractFlowbiteLayoutTestCase;

final class CheckboxLayoutTest extends FormLayoutTestCase
final class CheckboxLayoutTest extends AbstractFlowbiteLayoutTestCase
{
public function testCheckbox(): void
{
Expand Down
4 changes: 2 additions & 2 deletions tests/FormLayout/ChoiceLayoutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
namespace TalesFromADev\FlowbiteBundle\Tests\FormLayout;

use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use TalesFromADev\FlowbiteBundle\Tests\FormLayoutTestCase;
use TalesFromADev\FlowbiteBundle\Tests\AbstractFlowbiteLayoutTestCase;

final class ChoiceLayoutTest extends FormLayoutTestCase
final class ChoiceLayoutTest extends AbstractFlowbiteLayoutTestCase
{
public function testChoice(): void
{
Expand Down
5 changes: 3 additions & 2 deletions tests/FormLayout/DateLayoutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
namespace TalesFromADev\FlowbiteBundle\Tests\FormLayout;

use Symfony\Component\Form\Extension\Core\Type\DateType;
use TalesFromADev\FlowbiteBundle\Tests\FormLayoutTestCase;
use TalesFromADev\FlowbiteBundle\Tests\AbstractFlowbiteLayoutTestCase;

final class DateLayoutTest extends FormLayoutTestCase
final class DateLayoutTest extends AbstractFlowbiteLayoutTestCase
{
public function testDate(): void
{
$form = $this->factory->createNamed('date', DateType::class, date('Y').'-02-03', [
'input' => 'string',
'widget' => 'choice',
]);

$this->assertWidgetMatchesXpath($form->createView(), [],
Expand Down
4 changes: 2 additions & 2 deletions tests/FormLayout/FileLayoutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
namespace TalesFromADev\FlowbiteBundle\Tests\FormLayout;

use Symfony\Component\Form\Extension\Core\Type\FileType;
use TalesFromADev\FlowbiteBundle\Tests\FormLayoutTestCase;
use TalesFromADev\FlowbiteBundle\Tests\AbstractFlowbiteLayoutTestCase;

final class FileLayoutTest extends FormLayoutTestCase
final class FileLayoutTest extends AbstractFlowbiteLayoutTestCase
{
public function testFile(): void
{
Expand Down
4 changes: 2 additions & 2 deletions tests/FormLayout/MoneyLayoutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
namespace TalesFromADev\FlowbiteBundle\Tests\FormLayout;

use Symfony\Component\Form\Extension\Core\Type\MoneyType;
use TalesFromADev\FlowbiteBundle\Tests\FormLayoutTestCase;
use TalesFromADev\FlowbiteBundle\Tests\AbstractFlowbiteLayoutTestCase;

final class MoneyLayoutTest extends FormLayoutTestCase
final class MoneyLayoutTest extends AbstractFlowbiteLayoutTestCase
{
public function testMoney(): void
{
Expand Down
4 changes: 2 additions & 2 deletions tests/FormLayout/PercentLayoutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
namespace TalesFromADev\FlowbiteBundle\Tests\FormLayout;

use Symfony\Component\Form\Extension\Core\Type\PercentType;
use TalesFromADev\FlowbiteBundle\Tests\FormLayoutTestCase;
use TalesFromADev\FlowbiteBundle\Tests\AbstractFlowbiteLayoutTestCase;

final class PercentLayoutTest extends FormLayoutTestCase
final class PercentLayoutTest extends AbstractFlowbiteLayoutTestCase
{
public function testPercent(): void
{
Expand Down
4 changes: 2 additions & 2 deletions tests/FormLayout/RadioLayoutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
namespace TalesFromADev\FlowbiteBundle\Tests\FormLayout;

use Symfony\Component\Form\Extension\Core\Type\RadioType;
use TalesFromADev\FlowbiteBundle\Tests\FormLayoutTestCase;
use TalesFromADev\FlowbiteBundle\Tests\AbstractFlowbiteLayoutTestCase;

final class RadioLayoutTest extends FormLayoutTestCase
final class RadioLayoutTest extends AbstractFlowbiteLayoutTestCase
{
public function testRadio(): void
{
Expand Down
4 changes: 2 additions & 2 deletions tests/FormLayout/RangeLayoutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
namespace TalesFromADev\FlowbiteBundle\Tests\FormLayout;

use Symfony\Component\Form\Extension\Core\Type\RangeType;
use TalesFromADev\FlowbiteBundle\Tests\FormLayoutTestCase;
use TalesFromADev\FlowbiteBundle\Tests\AbstractFlowbiteLayoutTestCase;

final class RangeLayoutTest extends FormLayoutTestCase
final class RangeLayoutTest extends AbstractFlowbiteLayoutTestCase
{
public function testRange(): void
{
Expand Down
4 changes: 2 additions & 2 deletions tests/FormLayout/ResetLayoutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
namespace TalesFromADev\FlowbiteBundle\Tests\FormLayout;

use Symfony\Component\Form\Extension\Core\Type\ResetType;
use TalesFromADev\FlowbiteBundle\Tests\FormLayoutTestCase;
use TalesFromADev\FlowbiteBundle\Tests\AbstractFlowbiteLayoutTestCase;

final class ResetLayoutTest extends FormLayoutTestCase
final class ResetLayoutTest extends AbstractFlowbiteLayoutTestCase
{
public function testReset(): void
{
Expand Down
4 changes: 2 additions & 2 deletions tests/FormLayout/SelectLayoutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
use Symfony\Component\Form\Extension\Core\Type\LocaleType;
use Symfony\Component\Form\Extension\Core\Type\TimezoneType;
use Symfony\Component\Form\FormError;
use TalesFromADev\FlowbiteBundle\Tests\FormLayoutTestCase;
use TalesFromADev\FlowbiteBundle\Tests\AbstractFlowbiteLayoutTestCase;

final class SelectLayoutTest extends FormLayoutTestCase
final class SelectLayoutTest extends AbstractFlowbiteLayoutTestCase
{
#[DataProvider('selectProvider')]
public function testSelect(string $classType): void
Expand Down
4 changes: 2 additions & 2 deletions tests/FormLayout/SubmitLayoutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
namespace TalesFromADev\FlowbiteBundle\Tests\FormLayout;

use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use TalesFromADev\FlowbiteBundle\Tests\FormLayoutTestCase;
use TalesFromADev\FlowbiteBundle\Tests\AbstractFlowbiteLayoutTestCase;

final class SubmitLayoutTest extends FormLayoutTestCase
final class SubmitLayoutTest extends AbstractFlowbiteLayoutTestCase
{
public function testSubmit(): void
{
Expand Down
4 changes: 2 additions & 2 deletions tests/FormLayout/SupportLayoutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormError;
use TalesFromADev\FlowbiteBundle\Tests\FormLayoutTestCase;
use TalesFromADev\FlowbiteBundle\Tests\AbstractFlowbiteLayoutTestCase;

final class SupportLayoutTest extends FormLayoutTestCase
final class SupportLayoutTest extends AbstractFlowbiteLayoutTestCase
{
public function testLabel(): void
{
Expand Down
4 changes: 2 additions & 2 deletions tests/FormLayout/SwitchLayoutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
namespace TalesFromADev\FlowbiteBundle\Tests\FormLayout;

use TalesFromADev\FlowbiteBundle\Form\Type\SwitchType;
use TalesFromADev\FlowbiteBundle\Tests\FormLayoutTestCase;
use TalesFromADev\FlowbiteBundle\Tests\AbstractFlowbiteLayoutTestCase;

final class SwitchLayoutTest extends FormLayoutTestCase
final class SwitchLayoutTest extends AbstractFlowbiteLayoutTestCase
{
public function testSwitch(): void
{
Expand Down
5 changes: 3 additions & 2 deletions tests/FormLayout/TextLayoutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\UrlType;
use Symfony\Component\Form\FormError;
use TalesFromADev\FlowbiteBundle\Tests\FormLayoutTestCase;
use TalesFromADev\FlowbiteBundle\Tests\AbstractFlowbiteLayoutTestCase;

final class TextLayoutTest extends FormLayoutTestCase
final class TextLayoutTest extends AbstractFlowbiteLayoutTestCase
{
#[DataProvider('inputProvider')]
public function testInput(string $classType, mixed $data, string $inputType): void
Expand Down Expand Up @@ -63,6 +63,7 @@ public function testTextError(): void

$this->assertMatchesXpath($html,
'/p
[@id="name_error_0"]
[@class="mt-2 text-sm text-red-600 dark:text-red-500"]
[.="[trans]Error message[/trans]"]
'
Expand Down
4 changes: 2 additions & 2 deletions tests/FormLayout/TextareaLayoutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
namespace TalesFromADev\FlowbiteBundle\Tests\FormLayout;

use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use TalesFromADev\FlowbiteBundle\Tests\FormLayoutTestCase;
use TalesFromADev\FlowbiteBundle\Tests\AbstractFlowbiteLayoutTestCase;

final class TextareaLayoutTest extends FormLayoutTestCase
final class TextareaLayoutTest extends AbstractFlowbiteLayoutTestCase
{
public function testTextarea(): void
{
Expand Down
6 changes: 4 additions & 2 deletions tests/FormLayout/TimeLayoutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
namespace TalesFromADev\FlowbiteBundle\Tests\FormLayout;

use Symfony\Component\Form\Extension\Core\Type\TimeType;
use TalesFromADev\FlowbiteBundle\Tests\FormLayoutTestCase;
use TalesFromADev\FlowbiteBundle\Tests\AbstractFlowbiteLayoutTestCase;

final class TimeLayoutTest extends FormLayoutTestCase
final class TimeLayoutTest extends AbstractFlowbiteLayoutTestCase
{
public function testTime(): void
{
$form = $this->factory->createNamed('name', TimeType::class, '04:05:06', [
'input' => 'string',
'with_seconds' => false,
'widget' => 'choice',
]);

$this->assertWidgetMatchesXpath($form->createView(), [],
Expand Down Expand Up @@ -55,6 +56,7 @@ public function testTimeWithSeconds(): void
$form = $this->factory->createNamed('name', TimeType::class, '04:05:06', [
'input' => 'string',
'with_seconds' => true,
'widget' => 'choice',
]);

$this->assertWidgetMatchesXpath($form->createView(), [],
Expand Down
4 changes: 2 additions & 2 deletions tests/FormLayout/WeekLayoutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
namespace TalesFromADev\FlowbiteBundle\Tests\FormLayout;

use Symfony\Component\Form\Extension\Core\Type\WeekType;
use TalesFromADev\FlowbiteBundle\Tests\FormLayoutTestCase;
use TalesFromADev\FlowbiteBundle\Tests\AbstractFlowbiteLayoutTestCase;

final class WeekLayoutTest extends FormLayoutTestCase
final class WeekLayoutTest extends AbstractFlowbiteLayoutTestCase
{
public function testWeek(): void
{
Expand Down
Loading

0 comments on commit 063ac27

Please sign in to comment.