-
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.
- Loading branch information
Showing
4 changed files
with
156 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,64 @@ | ||
<?php | ||
|
||
namespace ipl\Tests\Html; | ||
|
||
use ipl\Html\Form; | ||
use ipl\Tests\Html\TestDummy\PositionedFormElementDecorator; | ||
use ipl\Tests\Html\TestDummy\SimpleFormElementDecorator; | ||
use ipl\Tests\Html\TestDummy\WithinContainerFormElementDecorator; | ||
|
||
class FormElementDecoratorTest extends TestCase | ||
{ | ||
public function testPositionedFormElementDecorator() | ||
{ | ||
$form = (new Form()) | ||
->setDefaultElementDecorator(new PositionedFormElementDecorator()) | ||
->addElement('text', 'decorated-form-element'); | ||
|
||
$html = <<<'HTML' | ||
<form method="POST"> | ||
<div class="positioned-decorator"> | ||
<input type="text" name="decorated-form-element"> | ||
</div> | ||
</form> | ||
HTML; | ||
|
||
$this->assertHtml($html, $form); | ||
} | ||
|
||
public function testSimpleFormElementDecorator() | ||
{ | ||
$form = (new Form()) | ||
->setDefaultElementDecorator(new SimpleFormElementDecorator()) | ||
->addElement('text', 'decorated-form-element'); | ||
|
||
$html = <<<'HTML' | ||
<form method="POST"> | ||
<div class="simple-decorator"> | ||
<input type="text" name="decorated-form-element"> | ||
</div> | ||
</form> | ||
HTML; | ||
|
||
$this->assertHtml($html, $form); | ||
} | ||
|
||
public function testWithinContainerFormElementDecorator() | ||
{ | ||
$form = (new Form()) | ||
->setDefaultElementDecorator(new WithinContainerFormElementDecorator()) | ||
->addElement('text', 'decorated-form-element'); | ||
|
||
$html = <<<'HTML' | ||
<form method="POST"> | ||
<div class="within-container-decorator"> | ||
<div class="container"> | ||
<input type="text" name="decorated-form-element"> | ||
</div> | ||
</div> | ||
</form> | ||
HTML; | ||
|
||
$this->assertHtml($html, $form); | ||
} | ||
} |
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,32 @@ | ||
<?php | ||
|
||
namespace ipl\Tests\Html\TestDummy; | ||
|
||
use ipl\Html\BaseHtmlElement; | ||
use ipl\Html\Contract\FormElement; | ||
use ipl\Html\Contract\FormElementDecorator; | ||
|
||
class PositionedFormElementDecorator extends BaseHtmlElement implements FormElementDecorator | ||
{ | ||
protected $tag = 'div'; | ||
|
||
protected $defaultAttributes = ['class' => 'positioned-decorator']; | ||
|
||
/** @var FormElement */ | ||
protected $formElement; | ||
|
||
public function decorate(FormElement $formElement) | ||
{ | ||
$decorator = new static(); | ||
$decorator->formElement = $formElement; | ||
|
||
$formElement->prependWrapper($decorator); | ||
|
||
return $decorator; | ||
} | ||
|
||
protected function assemble() | ||
{ | ||
$this->add($this->formElement); | ||
} | ||
} |
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,27 @@ | ||
<?php | ||
|
||
namespace ipl\Tests\Html\TestDummy; | ||
|
||
use ipl\Html\BaseHtmlElement; | ||
use ipl\Html\Contract\FormElement; | ||
use ipl\Html\Contract\FormElementDecorator; | ||
|
||
class SimpleFormElementDecorator extends BaseHtmlElement implements FormElementDecorator | ||
{ | ||
protected $tag = 'div'; | ||
|
||
protected $defaultAttributes = ['class' => 'simple-decorator']; | ||
|
||
/** @var FormElement */ | ||
protected $formElement; | ||
|
||
public function decorate(FormElement $formElement) | ||
{ | ||
$decorator = new static(); | ||
$decorator->formElement = $formElement; | ||
|
||
$formElement->prependWrapper($decorator); | ||
|
||
return $decorator; | ||
} | ||
} |
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,33 @@ | ||
<?php | ||
|
||
namespace ipl\Tests\Html\TestDummy; | ||
|
||
use ipl\Html\BaseHtmlElement; | ||
use ipl\Html\Contract\FormElement; | ||
use ipl\Html\Contract\FormElementDecorator; | ||
use ipl\Html\Html; | ||
|
||
class WithinContainerFormElementDecorator extends BaseHtmlElement implements FormElementDecorator | ||
{ | ||
protected $tag = 'div'; | ||
|
||
protected $defaultAttributes = ['class' => 'within-container-decorator']; | ||
|
||
/** @var FormElement */ | ||
protected $formElement; | ||
|
||
public function decorate(FormElement $formElement) | ||
{ | ||
$decorator = new static(); | ||
$decorator->formElement = $formElement; | ||
|
||
$formElement->prependWrapper($decorator); | ||
|
||
return $decorator; | ||
} | ||
|
||
protected function assemble() | ||
{ | ||
$this->add(Html::tag('div', ['class' => 'container'], $this->formElement)); | ||
} | ||
} |