Skip to content

Commit

Permalink
tests: Add new case FormElementsTest
Browse files Browse the repository at this point in the history
  • Loading branch information
nilmerg committed Jun 23, 2023
1 parent 914f083 commit 9cc37f2
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions tests/FormElementsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

namespace ipl\Tests\Html;

use ipl\Html\Form;
use ipl\Html\FormElement\FormElements;

class FormElementsTest extends TestCase
{
public function testFormWithCustomElementLoader()
{
$form = $this->getFormWithCustomElementAndDecoratorLoader();

$form->addElement('text', 'test');

$this->assertTrue($form->hasEnsureDefaultElementLoaderRegisteredRun());
}

public function testFormWithCustomDecoratorLoader()
{
$form = $this->getFormWithCustomElementAndDecoratorLoader();

$form->setDefaultElementDecorator('div');

$this->assertTrue($form->hasEnsureDefaultElementDecoratorLoaderRegisteredRun());
}

private function getFormWithCustomElementAndDecoratorLoader()
{
return new class extends Form {
use FormElements;

/** @var bool */
private $ensureDefaultElementLoaderRegisteredRun = false;

/** @var bool */
private $ensureDefaultElementDecoratorLoaderRegisteredRun = false;

public function hasEnsureDefaultElementLoaderRegisteredRun(): bool
{
return $this->ensureDefaultElementLoaderRegisteredRun;
}

public function hasEnsureDefaultElementDecoratorLoaderRegisteredRun(): bool
{
return $this->ensureDefaultElementDecoratorLoaderRegisteredRun;
}

protected function ensureDefaultElementLoaderRegistered()
{
if (! $this->defaultElementLoaderRegistered) {
$this->ensureDefaultElementLoaderRegisteredRun = true;

parent::ensureDefaultElementLoaderRegistered();
}

return $this;
}

protected function ensureDefaultElementDecoratorLoaderRegistered()
{
if (! $this->defaultElementDecoratorLoaderRegistered) {
$this->ensureDefaultElementDecoratorLoaderRegisteredRun = true;

parent::ensureDefaultElementDecoratorLoaderRegistered();
}

return $this;
}
};
}
}

0 comments on commit 9cc37f2

Please sign in to comment.