|
| 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\Impact\Engine; |
| 34 | + |
| 35 | +use DBmysql; |
| 36 | +use GlpiPlugin\Carbon\EmbodiedImpact; |
| 37 | +use GlpiPlugin\Carbon\Impact\Embodied\AbstractEmbodiedImpact; |
| 38 | +use GlpiPlugin\Carbon\Tests\DbTestCase; |
| 39 | +use PHPUnit\Framework\Attributes\CoversClass; |
| 40 | + |
| 41 | +#[CoversClass(AbstractEmbodiedImpact::class)] |
| 42 | +class AbstractEmbodiedImpactTest extends DbTestCase |
| 43 | +{ |
| 44 | + protected static string $itemtype = ''; |
| 45 | + protected static string $itemtype_type = ''; |
| 46 | + protected static string $itemtype_model = ''; |
| 47 | + |
| 48 | + public function testGetEvaluableItems() |
| 49 | + { |
| 50 | + /** @var DBmysql $DB */ |
| 51 | + global $DB; |
| 52 | + |
| 53 | + if (static::$itemtype === '' || static::$itemtype_type === '' || static::$itemtype_model === '') { |
| 54 | + // Ensure that the inherited test class is properly implemented for this test |
| 55 | + $this->fail('Itemtype properties not set in ' . static::class); |
| 56 | + } |
| 57 | + |
| 58 | + // Test the asset is evaluable when no embodied impact is in the DB |
| 59 | + $glpi_asset_type = $this->createItem(static::$itemtype_type); |
| 60 | + $asset_type = $this->createItem('GlpiPlugin\\Carbon\\' . static::$itemtype_type, [ |
| 61 | + getForeignKeyFieldForItemType(static::$itemtype_type) => $glpi_asset_type->getID(), |
| 62 | + ]); |
| 63 | + $asset = $this->createItem(static::$itemtype, [ |
| 64 | + getForeignKeyFieldForItemType(static::$itemtype_type) => $glpi_asset_type->getID(), |
| 65 | + ]); |
| 66 | + $instance = new ('GlpiPlugin\\Carbon\\Impact\\Embodied\\Boavizta\\' . static::$itemtype)(); |
| 67 | + $iterator = $instance->getEvaluateItems([ |
| 68 | + $asset->getTableField('id') => $asset->getID(), |
| 69 | + ]); |
| 70 | + $this->assertEquals(1, $iterator->count()); |
| 71 | + |
| 72 | + // Test the asset is no longer evaluable when no embodied impact is in the DB |
| 73 | + $glpi_asset_type = $this->createItem(static::$itemtype_type); |
| 74 | + $asset_type = $this->createItem('GlpiPlugin\\Carbon\\' . static::$itemtype_type, [ |
| 75 | + getForeignKeyFieldForItemType(static::$itemtype_type) => $glpi_asset_type->getID(), |
| 76 | + ]); |
| 77 | + $asset = $this->createItem(static::$itemtype, [ |
| 78 | + getForeignKeyFieldForItemType(static::$itemtype_type) => $glpi_asset_type->getID(), |
| 79 | + ]); |
| 80 | + $instance = new ('GlpiPlugin\\Carbon\\Impact\\Embodied\\Boavizta\\' . static::$itemtype)(); |
| 81 | + $embodied_impact = $this->createItem(EmbodiedImpact::class, [ |
| 82 | + 'itemtype' => $asset->getType(), |
| 83 | + 'items_id' => $asset->getID(), |
| 84 | + ]); |
| 85 | + $iterator = $instance->getEvaluateItems([ |
| 86 | + $asset::getTableField('id') => $asset->getID(), |
| 87 | + ]); |
| 88 | + $this->assertEquals(0, $iterator->count()); |
| 89 | + |
| 90 | + } |
| 91 | +} |
0 commit comments