-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: Add new case
FormElementsTest
- Loading branch information
Showing
1 changed file
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
}; | ||
} | ||
} |