Skip to content

Commit a6babff

Browse files
committed
Merge branch 'bugfix/dashboard_card_empty' into develop
2 parents 103b9d5 + 7dd937c commit a6babff

2 files changed

Lines changed: 19 additions & 6 deletions

File tree

install/data/report_dashboard.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,14 @@
116116
"limit": "7"
117117
}
118118
},
119-
"plugin_carbon_report_usage_abiotic_depletion": {
119+
"plugin_carbon_report_usage_adp_impact": {
120120
"x": 10,
121121
"y": 3,
122122
"width": 5,
123123
"height": 3,
124124
"card_options": {
125125
"color": "#fccd3e",
126-
"widgettype": "usage_abiotic_depletion",
126+
"widgettype": "impact_criteria_number",
127127
"use_gradient": "0",
128128
"point_labels": "0",
129129
"limit": "7"

tests/install/PluginInstallTest.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
use DbUtils;
4343
use DisplayPreference;
4444
use Glpi\Dashboard\Dashboard;
45+
use Glpi\Dashboard\Grid;
4546
use Glpi\Dashboard\Item;
4647
use Glpi\Dashboard\Right;
4748
use Glpi\DBAL\QueryExpression as QueryExpression;
@@ -67,6 +68,7 @@
6768
use NetworkEquipmentType;
6869
use PHPUnit\Framework\Attributes\CoversClass;
6970
use PHPUnit\Framework\Attributes\CoversNothing;
71+
use PHPUnit\Framework\Attributes\Depends;
7072
use Plugin;
7173
use Profile;
7274
use ProfileRight;
@@ -117,7 +119,8 @@ protected function executeInstallation()
117119
ob_start();
118120
$plugin->install($plugin->fields['id']);
119121
$install_output = ob_get_clean();
120-
$this->assertTrue($plugin->isInstalled($plugin_name), $install_output);
122+
$session_messages = implode(PHP_EOL, $_SESSION['MESSAGE_AFTER_REDIRECT'][ERROR] ?? []);
123+
$this->assertTrue($plugin->isInstalled($plugin_name), $install_output . PHP_EOL . $session_messages);
121124

122125
// Enable the plugin
123126
$success = $plugin->activate($plugin->fields['id']);
@@ -144,7 +147,6 @@ public function testInstallPlugin()
144147

145148
$this->checkConfig();
146149
$this->checkAutomaticAction();
147-
$this->checkDashboard();
148150
$this->checkRights();
149151
$this->checkInitialDataSources();
150152
$this->checkInitialZones();
@@ -510,7 +512,7 @@ private function checkPredefinedUsageProfiles()
510512
$this->assertEquals(2, count($rows));
511513
}
512514

513-
public function checkBuitFiles()
515+
public function checkBuiltFiles()
514516
{
515517
global $PLUGIN_HOOKS;
516518

@@ -523,7 +525,8 @@ public function checkBuitFiles()
523525
$this->assertTrue(in_array('lib/apexcharts.js', $PLUGIN_HOOKS[Hooks::ADD_JAVASCRIPT]['carbon']));
524526
}
525527

526-
public function checkDashboard()
528+
#[Depends('testInstallPlugin')]
529+
public function test_dashboard_is_configured()
527530
{
528531
/** @var DBmysql $DB */
529532
global $DB;
@@ -581,6 +584,16 @@ public function checkDashboard()
581584
'dashboards_dashboards_id' => $dashboard->fields['id'],
582585
]);
583586
$this->assertCount($expected_cards_count, $rows);
587+
588+
// Check that all cards actually generate a valid content
589+
// Let the plugin believe we are viewing the reporting page
590+
$_SERVER['REQUEST_URI'] = 'https://localhost/carbon/front/report.php';
591+
$grid = new Grid();
592+
foreach ($rows as $row) {
593+
$dashboardItem->getFromDB($row['id']);
594+
$html = $grid->getCardHtml($row['card_id'], ['args' => json_decode($row['card_options'], true)]);
595+
$this->assertStringNotContainsString('empty card!', $html, "Card with id {$row['card_id']} returns empty content");
596+
}
584597
}
585598

586599
private $zones = [

0 commit comments

Comments
 (0)