Skip to content

Commit 26b0a2a

Browse files
committed
test(UsageInfo): add tests
1 parent ab27f56 commit 26b0a2a

File tree

3 files changed

+114
-3
lines changed

3 files changed

+114
-3
lines changed

tests/units/ProfileTest.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,36 @@
3232

3333
namespace GlpiPlugin\Carbon\Tests;
3434

35+
use GlpiPlugin\Carbon\ComputerUsageProfile;
3536
use GlpiPlugin\Carbon\Profile;
3637
use Profile as GlpiProfile;
3738
use Symfony\Component\DomCrawler\Crawler;
3839

3940
class ProfileTest extends DbTestCase
4041
{
42+
/**
43+
* @covers GlpiPlugin\Carbon\Profile::getTabNameForItem
44+
*
45+
* @return void
46+
*/
4147
public function testGetTabNameForItem()
4248
{
4349
$profile = new Profile();
44-
$item = new \GlpiPlugin\Carbon\ComputerUsageProfile();
50+
$item = new GlpiProfile();
4551
$tabName = $profile->getTabNameForItem($item);
4652
$this->assertEquals(__('Environmental impact', 'carbon'), $tabName);
4753
}
4854

55+
/**
56+
* @covers GlpiPlugin\Carbon\Profile::showForm
57+
*
58+
* @return void
59+
*/
4960
public function testShowForm()
5061
{
5162
$this->login('glpi', 'glpi');
52-
$profile = GlpiProfile::getById(4); // Super admin
63+
$glpi_profile = GlpiProfile::getById(4); // Super admin
64+
$profile = new Profile();
5365
$output = '';
5466
ob_start(function ($buffer) use ($output) {
5567
$output .= $buffer;
@@ -59,7 +71,7 @@ public function testShowForm()
5971
$this->assertTrue($result);
6072
$crawler = new Crawler($output);
6173
$checkboxes = $crawler->filter('input[type="checkbox"]');
62-
$this->assertCount(3, $checkboxes);
74+
$this->assertCount(4, $checkboxes);
6375

6476
$save = $crawler->filter('button[type="submit"]');
6577
$this->assertCount(1, $save);

tests/units/ReportTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,22 @@ public function testGetTypeName()
5252
$this->assertEquals('Carbon reports', $result);
5353
}
5454

55+
/**
56+
* @covers GlpiPlugin\Carbon\Report::getIcon
57+
*
58+
* @return void
59+
*/
5560
public function testGetIcon()
5661
{
5762
$result = Report::getIcon();
5863
$this->assertEquals('fa-solid fa-solar-panel', $result);
5964
}
6065

66+
/**
67+
* @covers GlpiPlugin\Carbon\Report::getMenuContent
68+
*
69+
* @return void
70+
*/
6171
public function testGetMenuContent()
6272
{
6373
$this->login('glpi', 'glpi');
@@ -67,6 +77,11 @@ public function testGetMenuContent()
6777
$this->assertEquals('fa-solid fa-solar-panel', $result['icon']);
6878
}
6979

80+
/**
81+
* @covers GlpiPlugin\Carbon\Report::showInstantReport
82+
*
83+
* @return void
84+
*/
7085
public function testShowInstantReport()
7186
{
7287
$this->login('glpi', 'glpi');

tests/units/UsageInfoTest.php

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
3+
/**
4+
* -------------------------------------------------------------------------
5+
* Carbon plugin for GLPI
6+
*
7+
* @copyright Copyright (C) 2024-2025 Teclib' and contributors.
8+
* @license https://www.gnu.org/licenses/gpl-3.0.txt GPLv3+
9+
* @link https://github.com/pluginsGLPI/carbon
10+
*
11+
* -------------------------------------------------------------------------
12+
*
13+
* LICENSE
14+
*
15+
* This file is part of Carbon plugin for GLPI.
16+
*
17+
* This program is free software: you can redistribute it and/or modify
18+
* it under the terms of the GNU General Public License as published by
19+
* the Free Software Foundation, either version 3 of the License, or
20+
* (at your option) any later version.
21+
*
22+
* This program is distributed in the hope that it will be useful,
23+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
24+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25+
* GNU General Public License for more details.
26+
*
27+
* You should have received a copy of the GNU General Public License
28+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
29+
*
30+
* -------------------------------------------------------------------------
31+
*/
32+
33+
namespace GlpiPlugin\Carbon\Tests;
34+
35+
use GlpiPlugin\Carbon\ComputerUsageProfile;
36+
use GlpiPlugin\Carbon\Profile;
37+
use GlpiPlugin\Carbon\UsageInfo;
38+
use Computer as GlpiComputer;
39+
use Contact;
40+
use Symfony\Component\DomCrawler\Crawler;
41+
42+
class UsageInfoTest extends DbTestCase
43+
{
44+
/**
45+
* @covers GlpiPlugin\Carbon\UsageInfo::getTypeName
46+
*
47+
* @return void
48+
*/
49+
public function testGetTypeName()
50+
{
51+
$usageInfo = new UsageInfo();
52+
$typeName = $usageInfo->getTypeName();
53+
$this->assertEquals(__('Usage informations', 'Carbon'), $typeName);
54+
}
55+
56+
/**
57+
* @covers GlpiPlugin\Carbon\UsageInfo::getIcon
58+
*
59+
* @return void
60+
*/
61+
public function testGetIcon()
62+
{
63+
$usageInfo = new UsageInfo();
64+
$icon = $usageInfo->getIcon();
65+
$this->assertEquals('fa-solid fa-solar-panel', $icon);
66+
}
67+
68+
/**
69+
* @covers GlpiPlugin\Carbon\UsageInfo::getTabNameForItem
70+
*
71+
* @return void
72+
*/
73+
public function testGetTabNameForItem()
74+
{
75+
$usageInfo = new UsageInfo();
76+
$item = new GlpiComputer();
77+
$tabName = $usageInfo->getTabNameForItem($item);
78+
$this->assertEquals('Environmental impact', $tabName);
79+
80+
$item = new Contact();
81+
$tabName = $usageInfo->getTabNameForItem($item);
82+
$this->assertEquals('', $tabName);
83+
}
84+
}

0 commit comments

Comments
 (0)