Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Fixed

- Alerts of a child entity are displayed on the central page, the helpdesk, the service catalog and above the ticket list
- Login form shifted to the left when no alert is displayed on the login page

## [1.15.1] - 2026-11-05

Expand Down
6 changes: 4 additions & 2 deletions templates/alerts.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@
</div>
{% endset %}

{% if wrapper == 'central' %}
{% if wrapper == 'login' and alerts is empty %}
{# Empty login wrapper would still reserve its fixed width next to the login form #}
{% elseif wrapper == 'central' %}
<tr><td colspan="2">{{ alerts_html }}</td></tr>
{% elseif wrapper == 'list' %}
<tr><th colspan="2">{{ alerts_html }}</th></tr>
Expand All @@ -61,7 +63,7 @@
{{ alerts_html }}
{% endif %}

{% if load_script %}
{% if load_script and alerts is not empty %}
{{ call('Html::script', ['/plugins/news/js/news.js'])|raw }}
{% endif %}

30 changes: 28 additions & 2 deletions tests/units/PluginNewsDisplayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@

class PluginNewsDisplayTest extends DbTestCase
{
private function createAlert(string $name): PluginNewsAlert
private function createAlert(string $name, array $fields = []): PluginNewsAlert
{
$alert = $this->createItem(PluginNewsAlert::class, [
$alert = $this->createItem(PluginNewsAlert::class, $fields + [
'name' => $name,
'message' => 'Alert message',
'type' => PluginNewsAlert::GENERAL,
Expand Down Expand Up @@ -94,6 +94,32 @@ public function testCentralContainerIsEmptyWithoutAlert(): void
$this->assertStringContainsString('<div class="plugin_news_alert-container row align-items-stretch"></div>', $output);
}

private function getLoginAlertsOutput(): string
{
ob_start();
PluginNewsAlert::displayOnLogin();

return (string) ob_get_clean();
}

public function testLoginOutputIsEmptyWithoutAlert(): void
{
$this->createAlert('Central only alert');

$this->assertSame('', trim($this->getLoginAlertsOutput()));
}

public function testLoginAlertIsDisplayed(): void
{
$this->createAlert('Login alert', ['is_displayed_onlogin' => 1]);

$output = $this->getLoginAlertsOutput();

$this->assertStringContainsString('<div class="plugin_news_alert-login">', $output);
$this->assertStringContainsString('Login alert', $output);
$this->assertStringContainsString('news.js', $output);
}

public function testCentralAlertIsDisplayedToTargetedProfiles(): void
{
$this->login('glpi');
Expand Down