Skip to content

Commit

Permalink
Add PrefixSubmitButton with Test
Browse files Browse the repository at this point in the history
  • Loading branch information
Timm Ortloff committed Nov 24, 2022
1 parent 7b64689 commit e51b859
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/Common/PrefixSubmitButton.php
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;
}
}
27 changes: 27 additions & 0 deletions tests/common/PrefixSubmitButtonTest.php
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');
}
}

0 comments on commit e51b859

Please sign in to comment.