Skip to content

Commit

Permalink
raise code coverage, fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
koertho committed Nov 15, 2024
1 parent 148acff commit e063745
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Util/BackendUiUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function popupWizardLink(array $parameter, PopupWizardLinkOptions $option
if (!empty($options->icon)) {
/** @var Image $image */
$image = $this->framework->getAdapter(Image::class);
$linkText .= $image->getHtml('alias.svg', $title, 'style="vertical-align:top"');
$linkText .= $image->getHtml($options->icon, $title, 'style="vertical-align:top"');
}

if (!empty($options->linkText)) {
Expand Down
27 changes: 24 additions & 3 deletions tests/Util/BackendUiUtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,20 @@ public function getTestInstance(array $parameters = [], ?MockBuilder $mockBuilde
public function testPopupWizardLinkReturnsCorrectUrlOnly()
{
$routingUtil = $this->createMock(RoutingUtil::class);
$routingUtil->method('generateBackendRoute')->willReturn('generated_url');
$routingUtil->method('generateBackendRoute')->willReturnArgument(3);

$backendUiUtil = $this->getTestInstance(['routingUtil' => $routingUtil]);

$config = new PopupWizardLinkOptions();
$config->setUrlOnly(true);

$this->assertEquals(
'generated_url',
'contao_backend',
$backendUiUtil->popupWizardLink(['param' => 'value'], $config)
);
$config->setRoute('utils_backend');
$this->assertEquals(
'utils_backend',
$backendUiUtil->popupWizardLink(['param' => 'value'], $config)
);
}
Expand Down Expand Up @@ -72,6 +77,12 @@ public function testPopupWizardLinkGeneratesCorrectLink()
'<a href="generated_url" title="Edit" style="border: 0;" onclick="Backend.openModalIframe({\'width\':800,\'title\':\'Edit\',\'url\':this.href});return false">Test Link Text</a>',
$backendUiUtil->popupWizardLink(['param' => 'value'], $config)
);

$config->setAttributes(['class' => 'test-class']);
$this->assertStringContainsString(
'class="test-class"',
$backendUiUtil->popupWizardLink(['param' => 'value'], $config)
);
}

public function testPopupWizardLinkGeneratesLinkWithIcon()
Expand All @@ -80,7 +91,11 @@ public function testPopupWizardLinkGeneratesLinkWithIcon()
$routingUtil->method('generateBackendRoute')->willReturn('generated_url');

$image = $this->mockAdapter(['getHtml']);
$image->method('getHtml')->willReturn('<img src="alias.svg" alt="Test Title" style="vertical-align:top">');

$image->method('getHtml')->willReturnCallback(function (string $image, string $alt = '', string $attributes = '') {
return '<img src="'.$image.'" alt="'.$alt.'" style="vertical-align:top">';
});

$framework = $this->mockContaoFramework([Image::class => $image]);

$config = new PopupWizardLinkOptions();
Expand All @@ -97,5 +112,11 @@ public function testPopupWizardLinkGeneratesLinkWithIcon()
'<a href="generated_url" title="Test Title" style="Test Style" onclick="Backend.openModalIframe({\'width\':800,\'title\':\'Test Popup Title\',\'url\':this.href});return false"><img src="alias.svg" alt="Test Title" style="vertical-align:top"> Test Link Text</a>',
$backendUiUtil->popupWizardLink(['param' => 'value'], $config)
);

$config->setIcon('edit.svg');
$this->assertStringContainsString(
'src="edit.svg"',
$backendUiUtil->popupWizardLink(['param' => 'value'], $config)
);
}
}

0 comments on commit e063745

Please sign in to comment.