74 lines
2.5 KiB
PHP
74 lines
2.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Belevo\EnelixUtils\Tests;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
final class CC100HardwareModulstrukturTest extends TestCase
|
|
{
|
|
public function testModuleMetadataAndFormAreComplete(): void
|
|
{
|
|
$module = json_decode(
|
|
file_get_contents(__DIR__ . '/../CC100Hardware/module.json'),
|
|
true,
|
|
512,
|
|
JSON_THROW_ON_ERROR
|
|
);
|
|
$form = json_decode(
|
|
file_get_contents(__DIR__ . '/../CC100Hardware/form.json'),
|
|
true,
|
|
512,
|
|
JSON_THROW_ON_ERROR
|
|
);
|
|
|
|
self::assertSame('{D62EA550-68A5-48E2-BF31-1C721AA1BD4E}', $module['id']);
|
|
self::assertSame('CC100 Hardware', $module['name']);
|
|
self::assertSame('CC100', $module['prefix']);
|
|
self::assertNotEmpty($form['elements']);
|
|
self::assertNotEmpty($form['status']);
|
|
}
|
|
|
|
public function testModuleProvidesEveryCc100IoGroupAndConfigurablePolling(): void
|
|
{
|
|
$module = file_get_contents(__DIR__ . '/../CC100Hardware/module.php');
|
|
$form = file_get_contents(__DIR__ . '/../CC100Hardware/form.json');
|
|
|
|
self::assertNotFalse($module);
|
|
self::assertNotFalse($form);
|
|
foreach ([
|
|
'DigitalInputPath',
|
|
'DigitalOutputPath',
|
|
'AI1Path',
|
|
'AI2Path',
|
|
'AO1ValuePath',
|
|
'AO2ValuePath',
|
|
'PT1Path',
|
|
'PT2Path',
|
|
] as $property) {
|
|
self::assertStringContainsString($property, $module);
|
|
self::assertStringContainsString($property, $form);
|
|
}
|
|
self::assertStringContainsString('Abfrageintervall', $form);
|
|
self::assertStringContainsString("RegisterTimer(\n 'PollChannels'", $module);
|
|
}
|
|
|
|
public function testOutputsAreOnlyWrittenByExplicitActions(): void
|
|
{
|
|
$module = file_get_contents(__DIR__ . '/../CC100Hardware/module.php');
|
|
self::assertNotFalse($module);
|
|
|
|
$applyStart = strpos($module, 'public function ApplyChanges');
|
|
$actionStart = strpos($module, 'public function RequestAction');
|
|
self::assertNotFalse($applyStart);
|
|
self::assertNotFalse($actionStart);
|
|
self::assertStringNotContainsString(
|
|
'writeFile(',
|
|
substr($module, $applyStart, $actionStart - $applyStart)
|
|
);
|
|
self::assertStringNotContainsString('TryWriteFile', $module);
|
|
self::assertStringNotContainsString('usleep(', $module);
|
|
}
|
|
}
|