Standardisiere Symcon-Modultests
Tests / test (push) Successful in 46s

This commit is contained in:
dh
2026-09-17 12:36:41 +00:00
parent 1baa63f23e
commit 9834cc0eb7
14 changed files with 987 additions and 2 deletions
+69
View File
@@ -0,0 +1,69 @@
<?php
declare(strict_types=1);
use Belevo\EnelixUtils\SymconTest\TestContext;
return static function (TestContext $test): void {
$instancesBefore = array_flip(IPS_GetInstanceList());
$mqttId = $test->createInstance(
'{C6D2AEB3-6E1F-4B2E-8E69-3A1A00246850}',
'MQTT-Testserver'
);
$ioId = (int) IPS_GetInstance($mqttId)['ConnectionID'];
if ($ioId > 0 && !isset($instancesBefore[$ioId])) {
IPS_SetParent($ioId, $test->rootId());
}
$moduleId = $test->createInstance(
'{21D82EDB-AC8E-4F3D-9FEE-D20BCAFC1C33}',
'Shelly Modul'
);
if ((int) IPS_GetInstance($moduleId)['ConnectionID'] !== $mqttId) {
IPS_DisconnectInstance($moduleId);
IPS_ConnectInstance($moduleId, $mqttId);
IPS_ApplyChanges($moduleId);
}
$test->runCase('Instanz wird mit eigener MQTT-Elterninstanz angelegt', static function (
TestContext $test
) use ($moduleId, $mqttId): void {
$connectionId = (int) IPS_GetInstance($moduleId)['ConnectionID'];
$test->assertSame($mqttId, $connectionId);
$test->assertTrue(IPS_InstanceExists($connectionId));
});
$test->runCase('Topicfilter wird angewendet und gespeichert', static function (
TestContext $test
) use ($moduleId): void {
$test->configureInstance($moduleId, [
'UseDeviceTopicFilter' => true,
'DeviceTopicPrefix' => 'shelly-test',
'CreateOther' => false,
]);
$test->assertSame(true, IPS_GetProperty($moduleId, 'UseDeviceTopicFilter'));
$test->assertSame('shelly-test', IPS_GetProperty($moduleId, 'DeviceTopicPrefix'));
});
$test->runCase('Öffentliche Schaltfunktion sendet an MQTT', static function (
TestContext $test
) use ($moduleId): void {
$test->assertTrue(
IPS_FunctionExists('SHELLY_SetOutput'),
'Die öffentliche Funktion SHELLY_SetOutput fehlt.'
);
SHELLY_SetOutput($moduleId, 'shelly-test-device', 0, true);
});
$test->runCase('Konfigurationsformular ist gültiges JSON', static function (
TestContext $test
) use ($moduleId): void {
$form = json_decode(
IPS_GetConfigurationForm($moduleId),
true,
512,
JSON_THROW_ON_ERROR
);
$test->assertTrue(is_array($form));
});
};
@@ -0,0 +1,66 @@
<?php
declare(strict_types=1);
use Belevo\EnelixUtils\SymconTest\TestContext;
return static function (TestContext $test): void {
$typeProfileExisted = IPS_VariableProfileExists('BELEVO.TariffType');
$priceProfileExisted = IPS_VariableProfileExists('BELEVO.TariffPrice');
$moduleId = $test->createInstance(
'{9DAC29C7-F381-F2A4-7CE2-F391C4123F38}',
'Verbrauchskostenreport'
);
$test->trackVariableProfile('BELEVO.TariffType', $typeProfileExisted);
$test->trackVariableProfile('BELEVO.TariffPrice', $priceProfileExisted);
$test->runCase('Instanz, Bedienvariablen und Reportmedium werden angelegt', static function (
TestContext $test
) use ($moduleId): void {
foreach ([
'FromDate', 'ToDate', 'LastResult', 'VisuTariffOverview',
'VisuTariffPayload', 'VisuUserOverview', 'CreateReport', 'ReportPDF',
] as $ident) {
$test->objectByIdent($ident, $moduleId);
}
$test->assertTrue(IPS_VariableProfileExists('BELEVO.TariffType'));
$test->assertTrue(IPS_VariableProfileExists('BELEVO.TariffPrice'));
});
$test->runCase('Datumsaktionen übernehmen Werte', static function (TestContext $test) use (
$moduleId
): void {
$from = strtotime('2026-01-01 00:00:00');
$to = strtotime('2026-01-31 23:59:59');
IPS_RequestAction($moduleId, 'FromDate', $from);
IPS_RequestAction($moduleId, 'ToDate', $to);
$test->assertSame($from, GetValue($test->objectByIdent('FromDate', $moduleId)));
$test->assertSame($to, GetValue($test->objectByIdent('ToDate', $moduleId)));
});
$test->runCase('Tariftabelle wird validiert und gespeichert', static function (
TestContext $test
) use ($moduleId): void {
$payload = json_encode([
[
'unit_type' => 'Netztarif',
'start' => '2026-01-01',
'end' => '2026-12-31',
'price' => '18.500',
],
], JSON_THROW_ON_ERROR);
IPS_RequestAction($moduleId, 'VisuTariffPayload', $payload);
$tariffs = json_decode(
(string) IPS_GetProperty($moduleId, 'Tariffs'),
true,
512,
JSON_THROW_ON_ERROR
);
$test->assertSame(1, count($tariffs));
$test->assertSame('Netztarif', $tariffs[0]['unit_type']);
$status = (string) GetValue($test->objectByIdent('VisuTariffStatus', $moduleId));
$test->assertTrue(str_contains($status, '1 Tarif'));
});
};