Skip to content
Open
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 src/Impact/Embodied/AbstractEmbodiedImpact.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ abstract protected function getVersion(): string;
*/
final public function getUnit(int $type, bool $short = true): ?string
{
// TODO: This methos is probably never called now. Check and drop.
switch ($type) {
case Type::IMPACT_GWP:
return $short ? 'gCO2eq' : __('grams of carbon dioxyde equivalent', 'carbon');
Expand Down
2 changes: 1 addition & 1 deletion src/Impact/Embodied/Engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static function getAvailableBackends(): array
}

/**
* Get an instance of the engine to calculate imapcts for the given itemtype
* Get an instance of the engine to calculate impacts for the given itemtype
*
* Returns null if no engine found
*
Expand Down
4 changes: 2 additions & 2 deletions src/Impact/Embodied/Internal/AbstractAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ protected function doEvaluation(): array
return [];
}

/** @var CommonDBTM $model */
$model = getItemForItemtype($glpi_model_itemtype);
/** @var CommonDBTM|false $model */
$model = getItemForItemtype('GlpiPlugin\\Carbon\\' . $glpi_model_itemtype);
$model->getFromDBByCrit([
$glpi_model_fk => $this->item->fields[$glpi_model_fk],
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,22 @@
use PHPUnit\Framework\Attributes\CoversClass;

#[CoversClass(AbstractEmbodiedImpact::class)]
class AbstractEmbodiedImpactTest extends DbTestCase
class AbstractCommonEmbodiedImpactTest extends DbTestCase
{
protected static string $itemtype = '';
protected static string $itemtype_type = '';
protected static string $itemtype_model = '';

public function testGetItemsToEvaluate()
public static function setUpBeforeClass(): void
{
if (static::$itemtype === '' || static::$itemtype_type === '' || static::$itemtype_model === '') {
// Ensure that the inherited test class is properly implemented for this test
$this->fail('Itemtype properties not set in ' . static::class);
self::fail('Itemtype properties not set in ' . static::class);
}
}

public function test_GetItemsToEvaluate_evaluates_asset_when_no_embodied_impact_exists()
{
// Test the asset is evaluable when no embodied impact is in the DB
$glpi_asset_type = $this->createItem(static::$itemtype_type);
$asset_type = $this->createItem('GlpiPlugin\\Carbon\\' . static::$itemtype_type, [
Expand All @@ -64,7 +67,10 @@ public function testGetItemsToEvaluate()
$asset->getTableField('id') => $asset->getID(),
]);
$this->assertEquals(1, $iterator->count());
}

public function test_GetItemsToEvaluate_does_not_evaluates_asset_when_embodied_impact_exists()
{
// Test the asset is no longer evaluable when there is embodied impact in the DB
$glpi_asset_type = $this->createItem(static::$itemtype_type);
$asset_type = $this->createItem('GlpiPlugin\\Carbon\\' . static::$itemtype_type, [
Expand All @@ -82,8 +88,11 @@ public function testGetItemsToEvaluate()
$asset::getTableField('id') => $asset->getID(),
]);
$this->assertEquals(0, $iterator->count());
}

// Test the asset is evaluable when there is embodied impact in the DB but recamculate is set
public function test_GetItemsToEvaluate_evaluates_asset_when_embodied_impact_exists_and_marked_for_recalculation()
{
// Test the asset is evaluable when there is embodied impact in the DB but recalculate is set
$glpi_asset_type = $this->createItem(static::$itemtype_type);
$asset_type = $this->createItem('GlpiPlugin\\Carbon\\' . static::$itemtype_type, [
getForeignKeyFieldForItemType(static::$itemtype_type) => $glpi_asset_type->getID(),
Expand Down
45 changes: 45 additions & 0 deletions tests/src/Impact/Embodied/Boavizta/AbstractEmbodiedImpactTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

/**
* -------------------------------------------------------------------------
* Carbon plugin for GLPI
*
* @copyright Copyright (C) 2024-2025 Teclib' and contributors.
* @license https://www.gnu.org/licenses/gpl-3.0.txt GPLv3+
* @link https://github.com/pluginsGLPI/carbon
*
* -------------------------------------------------------------------------
*
* LICENSE
*
* This file is part of Carbon plugin for GLPI.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* -------------------------------------------------------------------------
*/

namespace GlpiPlugin\Carbon\Tests\Impact\Embodied\Boavizta;

use GlpiPlugin\Carbon\Impact\Embodied\AbstractEmbodiedImpact;
use GlpiPlugin\Carbon\Tests\Impact\Embodied\AbstractCommonEmbodiedImpactTest;
use PHPUnit\Framework\Attributes\CoversClass;

#[CoversClass(AbstractEmbodiedImpact::class)]
class AbstractEmbodiedImpactTest extends AbstractCommonEmbodiedImpactTest
{
protected static string $itemtype = '';
protected static string $itemtype_type = '';
protected static string $itemtype_model = '';
}
45 changes: 45 additions & 0 deletions tests/src/Impact/Embodied/Internal/AbstractEmbodiedImpactTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

/**
* -------------------------------------------------------------------------
* Carbon plugin for GLPI
*
* @copyright Copyright (C) 2024-2025 Teclib' and contributors.
* @license https://www.gnu.org/licenses/gpl-3.0.txt GPLv3+
* @link https://github.com/pluginsGLPI/carbon
*
* -------------------------------------------------------------------------
*
* LICENSE
*
* This file is part of Carbon plugin for GLPI.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* -------------------------------------------------------------------------
*/

namespace GlpiPlugin\Carbon\Tests\Impact\Embodied\Internal;

use GlpiPlugin\Carbon\Impact\Embodied\AbstractEmbodiedImpact;
use GlpiPlugin\Carbon\Tests\Impact\Embodied\AbstractCommonEmbodiedImpactTest;
use PHPUnit\Framework\Attributes\CoversClass;

#[CoversClass(AbstractEmbodiedImpact::class)]
class AbstractEmbodiedImpactTest extends AbstractCommonEmbodiedImpactTest
{
protected static string $itemtype = '';
protected static string $itemtype_type = '';
protected static string $itemtype_model = '';
}
2 changes: 1 addition & 1 deletion tests/units/Impact/Embodied/Boavizta/ComputerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
use ComputerModel as GlpiComputerModel;
use ComputerType as GlpiComputerType;
use GlpiPlugin\Carbon\Impact\Embodied\Boavizta\Computer as BoaviztaComputer;
use GlpiPlugin\Carbon\Tests\Impact\Embodied\AbstractEmbodiedImpactTest;
use GlpiPlugin\Carbon\Tests\Impact\Embodied\Boavizta\AbstractEmbodiedImpactTest;
use PHPUnit\Framework\Attributes\CoversClass;

#[CoversClass(BoaviztaComputer::class)]
Expand Down
2 changes: 1 addition & 1 deletion tests/units/Impact/Embodied/Boavizta/MonitorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
namespace GlpiPlugin\Carbon\Impact\Embodied\Boavizta\Tests;

use GlpiPlugin\Carbon\Impact\Embodied\Boavizta\Monitor as BoaviztaMonitor;
use GlpiPlugin\Carbon\Tests\Impact\Embodied\AbstractEmbodiedImpactTest;
use GlpiPlugin\Carbon\Tests\Impact\Embodied\Boavizta\AbstractEmbodiedImpactTest;
use Monitor as GlpiMonitor;
use MonitorModel as glpiMonitorModel;
use MonitorType as GlpiMonitorType;
Expand Down
48 changes: 48 additions & 0 deletions tests/units/Impact/Embodied/Internal/ComputerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

/**
* -------------------------------------------------------------------------
* Carbon plugin for GLPI
*
* @copyright Copyright (C) 2024-2025 Teclib' and contributors.
* @license https://www.gnu.org/licenses/gpl-3.0.txt GPLv3+
* @link https://github.com/pluginsGLPI/carbon
*
* -------------------------------------------------------------------------
*
* LICENSE
*
* This file is part of Carbon plugin for GLPI.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* -------------------------------------------------------------------------
*/

namespace GlpiPlugin\Carbon\Impact\Embodied\Internal\Tests;

use Computer as GlpiComputer;
use ComputerModel as GlpiComputerModel;
use ComputerType as GlpiComputerType;
use GlpiPlugin\Carbon\Impact\Embodied\Internal\Computer as InternalComputer;
use GlpiPlugin\Carbon\Tests\Impact\Embodied\Internal\AbstractEmbodiedImpactTest;
use PHPUnit\Framework\Attributes\CoversClass;

#[CoversClass(InternalComputer::class)]
class ComputerTest extends AbstractEmbodiedImpactTest
{
protected static string $itemtype = GlpiComputer::class;
protected static string $itemtype_type = GlpiComputerType::class;
protected static string $itemtype_model = GlpiComputerModel::class;
}