This commit is contained in:
@@ -0,0 +1,143 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Belevo\EnelixEMS\Tests;
|
||||
|
||||
use Belevo\EnelixEMS\Lizenzpruefung;
|
||||
use DateTimeImmutable;
|
||||
use InvalidArgumentException;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class LizenzpruefungTest extends TestCase
|
||||
{
|
||||
private const INSTALLATION_ID = '123e4567-e89b-42d3-a456-426614174000';
|
||||
|
||||
public function testStandardLizenzGibtGrundregelungFrei(): void
|
||||
{
|
||||
Lizenzpruefung::pruefeLease(
|
||||
$this->lease('manager_standard'),
|
||||
self::INSTALLATION_ID,
|
||||
0,
|
||||
$this->zeit('2026-09-19T12:00:00Z')
|
||||
);
|
||||
|
||||
self::assertTrue(true);
|
||||
}
|
||||
|
||||
public function testPeakLizenzGibtLastspitzenmodusFrei(): void
|
||||
{
|
||||
Lizenzpruefung::pruefeLease(
|
||||
$this->lease('manager_peak'),
|
||||
self::INSTALLATION_ID,
|
||||
2,
|
||||
$this->zeit('2026-09-19T12:00:00Z')
|
||||
);
|
||||
|
||||
self::assertTrue(true);
|
||||
}
|
||||
|
||||
public function testStandardLizenzSperrtLastspitzenmodus(): void
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('Peak Shaving ist nicht lizenziert.');
|
||||
|
||||
Lizenzpruefung::pruefeLease(
|
||||
$this->lease('manager_standard'),
|
||||
self::INSTALLATION_ID,
|
||||
1,
|
||||
$this->zeit('2026-09-19T12:00:00Z')
|
||||
);
|
||||
}
|
||||
|
||||
public function testAbgelaufeneOfflineFreigabeWirdAbgelehnt(): void
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('Offline-Freigabe ist abgelaufen.');
|
||||
|
||||
Lizenzpruefung::pruefeLease(
|
||||
$this->lease('manager_peak'),
|
||||
self::INSTALLATION_ID,
|
||||
0,
|
||||
$this->zeit('2026-10-03T12:00:00Z')
|
||||
);
|
||||
}
|
||||
|
||||
public function testAndereInstallationWirdAbgelehnt(): void
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('anderen Installation');
|
||||
|
||||
Lizenzpruefung::pruefeLease(
|
||||
$this->lease('manager_standard'),
|
||||
'223e4567-e89b-42d3-a456-426614174000',
|
||||
0,
|
||||
$this->zeit('2026-09-19T12:00:00Z')
|
||||
);
|
||||
}
|
||||
|
||||
public function testErneuerungWirdAbRefreshAfterFaellig(): void
|
||||
{
|
||||
$lease = $this->lease('manager_standard');
|
||||
|
||||
self::assertFalse(Lizenzpruefung::erneuerungFaellig(
|
||||
$lease,
|
||||
$this->zeit('2026-09-20T11:59:59Z')
|
||||
));
|
||||
self::assertTrue(Lizenzpruefung::erneuerungFaellig(
|
||||
$lease,
|
||||
$this->zeit('2026-09-20T12:00:00Z')
|
||||
));
|
||||
}
|
||||
|
||||
public function testLeaseOhneManagerBerechtigungWirdAbgelehnt(): void
|
||||
{
|
||||
$lease = $this->lease('consumer_single');
|
||||
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('Manager-Berechtigung fehlt.');
|
||||
Lizenzpruefung::pruefeLease(
|
||||
$lease,
|
||||
self::INSTALLATION_ID,
|
||||
0,
|
||||
$this->zeit('2026-09-19T12:00:00Z')
|
||||
);
|
||||
}
|
||||
|
||||
public function testLizenzcodeWirdWieAufDemServerNormalisiert(): void
|
||||
{
|
||||
self::assertSame(
|
||||
'ENX23456789ABCDEFGH',
|
||||
Lizenzpruefung::normalisiereCode('enx-2345-6789-abcd-efgh')
|
||||
);
|
||||
self::assertTrue(Lizenzpruefung::istLizenzcodeGueltig('ENX-2345-6789-ABCD-EFGH'));
|
||||
self::assertFalse(Lizenzpruefung::istLizenzcodeGueltig('ENX-OOOO-OOOO-OOOO-OOOO'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function lease(string $sku): array
|
||||
{
|
||||
return [
|
||||
'status' => 'active',
|
||||
'development' => true,
|
||||
'installationId' => self::INSTALLATION_ID,
|
||||
'orderId' => '323e4567-e89b-42d3-a456-426614174000',
|
||||
'entitlements' => [[
|
||||
'sku' => $sku,
|
||||
'catalog_key' => $sku,
|
||||
'quantity' => 1,
|
||||
'status' => 'active',
|
||||
]],
|
||||
'issuedAt' => '2026-09-19T12:00:00.000Z',
|
||||
'refreshAfter' => '2026-09-20T12:00:00.000Z',
|
||||
'offlineUntil' => '2026-10-03T12:00:00.000Z',
|
||||
];
|
||||
}
|
||||
|
||||
private function zeit(string $wert): int
|
||||
{
|
||||
return (new DateTimeImmutable($wert))->getTimestamp();
|
||||
}
|
||||
}
|
||||
@@ -50,12 +50,16 @@ final class ManagerModulstrukturTest extends TestCase
|
||||
'Umschaltdifferenz',
|
||||
'DiagnosevariablenAnzeigen',
|
||||
'LoggingEin',
|
||||
'Lizenzcode',
|
||||
'LizenzPruefen',
|
||||
'LizenzInstallationID',
|
||||
'LizenzInformation',
|
||||
'VerbraucherAktualisieren',
|
||||
] as $property) {
|
||||
self::assertStringContainsString($property, $json);
|
||||
}
|
||||
foreach (['Regelintervall', 'Vorgabeintervall', 'UmschaltschwelleUeberschuss',
|
||||
'UmschaltschwelleLastspitze', 'Optionale obere Anschluesse'] as $entfernt
|
||||
'UmschaltschwelleLastspitze', 'Optionale obere Anschluesse', 'LizenzAnschluss'] as $entfernt
|
||||
) {
|
||||
self::assertStringNotContainsString($entfernt, $json);
|
||||
}
|
||||
@@ -89,6 +93,27 @@ final class ManagerModulstrukturTest extends TestCase
|
||||
self::assertStringContainsString('SendDebug(', $inhalt);
|
||||
}
|
||||
|
||||
public function testManagerBindetDieLizenzierungFailClosedAn(): void
|
||||
{
|
||||
$inhalt = (string) file_get_contents(__DIR__ . '/../Manager/module.php');
|
||||
|
||||
self::assertFileExists(__DIR__ . '/../libs/Lizenzpruefung.php');
|
||||
self::assertStringContainsString(
|
||||
"RegisterPropertyString('Lizenzcode', '')",
|
||||
$inhalt
|
||||
);
|
||||
self::assertStringContainsString(
|
||||
"https://license.enelix.ch/api/v1/licenses/activate",
|
||||
$inhalt
|
||||
);
|
||||
self::assertStringContainsString("RegisterAttributeString('LizenzInstallationID'", $inhalt);
|
||||
self::assertStringContainsString("RegisterAttributeString('LizenzLease'", $inhalt);
|
||||
self::assertStringContainsString("RegisterAttributeString('LizenzcodeHash'", $inhalt);
|
||||
self::assertStringContainsString('STATUS_LIZENZ_UNGUELTIG', $inhalt);
|
||||
self::assertStringContainsString('aktualisiereLizenzfreigabe(', $inhalt);
|
||||
self::assertStringNotContainsString("'publicKey' =>", $inhalt);
|
||||
}
|
||||
|
||||
public function testManagerVerwendetDieNeuenZeitdefaults(): void
|
||||
{
|
||||
$inhalt = (string) file_get_contents(__DIR__ . '/../Manager/module.php');
|
||||
|
||||
@@ -7,6 +7,7 @@ return [
|
||||
'file' => __DIR__ . '/modules/Manager.php',
|
||||
'paths' => [
|
||||
'Manager/*',
|
||||
'libs/Lizenzpruefung.php',
|
||||
'libs/ManagerRegler.php',
|
||||
'libs/ManagerSchnittstelle.php',
|
||||
'libs/Nachrichtenvertrag.php',
|
||||
|
||||
@@ -48,11 +48,13 @@ return static function (TestContext $test): void {
|
||||
['InstanzID' => $einStufigId, 'Aktiv' => true],
|
||||
['InstanzID' => $warmwasserId, 'Aktiv' => true],
|
||||
];
|
||||
$lizenzcode = trim((string) getenv('ENELIX_TEST_LICENSE_CODE'));
|
||||
$managerId = $test->createInstance(
|
||||
'{6F771B18-59D4-4C8A-B951-3B2FE9F6A2C4}',
|
||||
'Manager',
|
||||
[
|
||||
'NetzleistungVariableID' => $netzleistungId,
|
||||
'Lizenzcode' => $lizenzcode,
|
||||
'AutomatischeSuche' => false,
|
||||
'VerbraucherZuordnung' => json_encode($zuordnung, JSON_THROW_ON_ERROR),
|
||||
'KeepAlive' => 30,
|
||||
@@ -130,6 +132,22 @@ return static function (TestContext $test): void {
|
||||
return null;
|
||||
};
|
||||
|
||||
if ($lizenzcode === '') {
|
||||
$test->runCase('Manager bleibt ohne Lizenz sicher gesperrt', static function (
|
||||
TestContext $test
|
||||
) use ($managerId): void {
|
||||
IPS_RequestAction($managerId, 'Aktiv', true);
|
||||
IPS_RequestAction($managerId, 'Regeln', true);
|
||||
$test->assertInstanceStatus($managerId, 203);
|
||||
$test->assertSame(
|
||||
'Inaktiv',
|
||||
GetValue($test->objectByIdent('Betriebsart', $managerId))
|
||||
);
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$test->runCase('Manager und alle vorhandenen Verbrauchertypen sind verknüpft', static function (
|
||||
TestContext $test
|
||||
) use ($managerId, $einStufigId, $warmwasserId, $melden): void {
|
||||
|
||||
@@ -63,6 +63,14 @@ final class SymconTestContractTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function testAffectedModuleResolverSelectsManagerForLicenseChecks(): void
|
||||
{
|
||||
self::assertSame(
|
||||
['Manager'],
|
||||
$this->resolveAffectedModules(['libs/Lizenzpruefung.php'])
|
||||
);
|
||||
}
|
||||
|
||||
public function testAffectedModuleResolverSelectsAllModulesForFrameworkChanges(): void
|
||||
{
|
||||
self::assertSame(
|
||||
|
||||
Reference in New Issue
Block a user