-
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
Timm Ortloff
committed
Nov 24, 2022
1 parent
7b64689
commit e51b859
Showing
2 changed files
with
50 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,23 @@ | ||
<?php | ||
|
||
namespace ipl\Web\Common; | ||
|
||
use ipl\Html\Attribute; | ||
use ipl\Html\Contract\FormSubmitElement; | ||
use ipl\Html\FormElement\SubmitElement; | ||
|
||
trait PrefixSubmitButton | ||
{ | ||
protected function createSubmitButton(FormSubmitElement $originalSubmitButton): SubmitElement | ||
{ | ||
$attr = clone $originalSubmitButton->getAttributes(); | ||
$attr->setAttribute( | ||
Attribute::create('class', 'hidePrefixElement') | ||
); | ||
|
||
$submit = new SubmitElement($originalSubmitButton->getName(), $attr); | ||
$submit->setValue($originalSubmitButton->getValue()); | ||
|
||
return $submit; | ||
} | ||
} |
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 | ||
|
||
use ipl\Html\FormElement\SubmitElement; | ||
use ipl\Tests\Web\TestCase; | ||
use ipl\Web\Common\PrefixSubmitButton; | ||
|
||
class PrefixSubmitButtonTest extends TestCase | ||
{ | ||
use PrefixSubmitButton; | ||
|
||
public function testCreatingPrefixSubmitButton(): void | ||
{ | ||
$submitButton = new SubmitElement('test_submit', [ | ||
'class' => 'autosubmit' | ||
]); | ||
|
||
$prefixButton = $this->createSubmitButton($submitButton); | ||
|
||
// Name should stay the same | ||
$this->assertSame($submitButton->getName(), 'test_submit'); | ||
$this->assertSame($prefixButton->getName(), 'test_submit'); | ||
|
||
// Class Attribute should change to `hideElement` | ||
$this->assertSame($submitButton->getAttributes()->get('class')->getValue(), 'autosubmit'); | ||
$this->assertSame($prefixButton->getAttributes()->get('class')->getValue(), 'hideElement'); | ||
} | ||
} |