Skip to content

Commit

Permalink
Update renderLabelTag method access modifier. (#203)
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw committed Jan 5, 2024
1 parent 57a5472 commit 87235fc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Attribute/Custom/HasLabel.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function isNotLabel(): bool
*
* @return string The rendered label tag.
*/
private function renderLabelTag(string $labelFor = null): string
protected function renderLabelTag(string $labelFor = null): string
{
if ($this->labelContent === '' || $this->isNotLabel()) {
return '';
Expand Down
25 changes: 19 additions & 6 deletions tests/Attribute/Custom/HasLabelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace PHPForge\Html\Tests\Attribute\Custom;

use PHPForge\Html\Attribute\Custom\HasLabel;
use PHPForge\Html\Input\Base\AbstractButton;
use PHPForge\Html\Span;
use PHPUnit\Framework\TestCase;

Expand All @@ -23,17 +24,17 @@ public function getLabelClass(): string

$this->assertEmpty($instance->getLabelClass());

$instance = $instance->labelClass('test-class');
$instance = $instance->labelClass('class');

$this->assertSame('test-class', $instance->getLabelClass());
$this->assertSame('class', $instance->getLabelClass());

$instance = $instance->labelClass('test-class-1');
$instance = $instance->labelClass('class-1');

$this->assertSame('test-class test-class-1', $instance->getLabelClass());
$this->assertSame('class class-1', $instance->getLabelClass());

$instance = $instance->labelClass('test-override-class', true);
$instance = $instance->labelClass('override-class', true);

$this->assertSame('test-override-class', $instance->getLabelClass());
$this->assertSame('override-class', $instance->getLabelClass());
}

public function testContent(): void
Expand Down Expand Up @@ -90,6 +91,18 @@ public function testNotLabel(): void
$this->assertTrue($instance->notLabel()->isNotLabel());
}

public function testRenderLabelTag(): void
{
$instance = new class () extends AbstractButton {
public function run(): string
{
return $this->renderLabelTag();
}
};

$this->assertSame('<label>content</label>', $instance->labelContent('content')->run());
}

public function testXSS(): void
{
$instance = new class () {
Expand Down

0 comments on commit 87235fc

Please sign in to comment.