|
36 | 36 |
|
37 | 37 | use Change_Item;
|
38 | 38 | use DbTestCase;
|
| 39 | +use Glpi\Asset\AssetDefinitionManager; |
| 40 | +use Glpi\Asset\Capacity; |
| 41 | +use Glpi\Asset\Capacity\AbstractCapacity; |
| 42 | +use Glpi\Asset\CapacityConfig; |
39 | 43 | use Item_Problem;
|
40 | 44 | use Item_Ticket;
|
41 | 45 | use Profile;
|
@@ -214,4 +218,45 @@ public function testCommonITILTabRegistration(): void
|
214 | 218 | $this->assertEquals($expected_tabs, $tabs);
|
215 | 219 | }
|
216 | 220 | }
|
| 221 | + |
| 222 | + public function testRegisteredCapacity(): void |
| 223 | + { |
| 224 | + $definition = $this->initAssetDefinition(); |
| 225 | + $asset_classname = $definition->getAssetClassName(); |
| 226 | + |
| 227 | + $capacity_implementation = $this->createMock(AbstractCapacity::class); |
| 228 | + $capacity_config = new CapacityConfig(['foo' => 'bar']); |
| 229 | + |
| 230 | + // Register the capacity. |
| 231 | + $manager = AssetDefinitionManager::getInstance(); |
| 232 | + $manager->registerCapacity($capacity_implementation); |
| 233 | + |
| 234 | + $this->assertContains($capacity_implementation, $manager->getAvailableCapacities()); |
| 235 | + $this->assertEquals($capacity_implementation, $manager->getCapacity($capacity_implementation::class)); |
| 236 | + |
| 237 | + // `onCapacityEnabled` method is executed when the capacity is enabled. |
| 238 | + $capacity_implementation->expects($this->once()) |
| 239 | + ->method('onCapacityEnabled') |
| 240 | + ->with($asset_classname, $this->equalTo($capacity_config)); |
| 241 | + $this->enableCapacity($definition, $capacity_implementation::class, $capacity_config); |
| 242 | + |
| 243 | + // `onObjectInstanciation` method is executed when an asset constructor is used. |
| 244 | + $capacity_implementation->expects($this->once()) |
| 245 | + ->method('onObjectInstanciation') |
| 246 | + ->with($this->isInstanceOf($asset_classname), $this->equalTo($capacity_config)); |
| 247 | + new $asset_classname(); |
| 248 | + |
| 249 | + // `onCapacityUpdated` method is executed when the capacity config is updated. |
| 250 | + $new_config = new CapacityConfig(['bar' => 'baz']); |
| 251 | + $capacity_implementation->expects($this->once()) |
| 252 | + ->method('onCapacityUpdated') |
| 253 | + ->with($asset_classname, $this->equalTo($capacity_config), $this->equalTo($new_config)); |
| 254 | + $this->enableCapacity($definition, $capacity_implementation::class, $new_config); |
| 255 | + |
| 256 | + // `onCapacityDisabled` method is executed when the capacity is disabled. |
| 257 | + $capacity_implementation->expects($this->once()) |
| 258 | + ->method('onCapacityDisabled') |
| 259 | + ->with($asset_classname, $this->equalTo($new_config)); |
| 260 | + $this->disableCapacity($definition, $capacity_implementation::class); |
| 261 | + } |
217 | 262 | }
|
0 commit comments