Skip to content

Commit d3932f8

Browse files
committed
test(Profile): add tests, fix text
1 parent a847457 commit d3932f8

File tree

2 files changed

+68
-1
lines changed

2 files changed

+68
-1
lines changed

src/Profile.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class Profile extends GlpiProfile
4242
{
4343
public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
4444
{
45-
return self::createTabEntry(__('Environnemental impact', 'carbon'), 0);
45+
return self::createTabEntry(__('Environmental impact', 'carbon'), 0);
4646
}
4747

4848
public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0)

tests/units/ProfileTest.php

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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\Profile;
36+
use Profile as GlpiProfile;
37+
use Symfony\Component\DomCrawler\Crawler;
38+
39+
class ProfileTest extends DbTestCase
40+
{
41+
public function testGetTabNameForItem()
42+
{
43+
$profile = new Profile();
44+
$item = new \GlpiPlugin\Carbon\ComputerUsageProfile();
45+
$tabName = $profile->getTabNameForItem($item);
46+
$this->assertEquals(__('Environmental impact', 'carbon'), $tabName);
47+
}
48+
49+
public function testShowForm()
50+
{
51+
$this->login('glpi', 'glpi');
52+
$profile = GlpiProfile::getById(4); // Super admin
53+
$output = '';
54+
ob_start(function ($buffer) use ($output) {
55+
$output .= $buffer;
56+
});
57+
$result = $profile->showForm($profile->getID());
58+
$output = ob_get_clean();
59+
$this->assertTrue($result);
60+
$crawler = new Crawler($output);
61+
$checkboxes = $crawler->filter('input[type="checkbox"]');
62+
$this->assertCount(3, $checkboxes);
63+
64+
$save = $crawler->filter('button[type="submit"]');
65+
$this->assertCount(1, $save);
66+
}
67+
}

0 commit comments

Comments
 (0)