149 lines
3.8 KiB
PHP
149 lines
3.8 KiB
PHP
<?php
|
|
|
|
namespace tests\flow\nodes;
|
|
|
|
use tests\flow\TestCase;
|
|
use app\flow\nodes\FinalRinseNode;
|
|
use app\flow\DbOperationType;
|
|
|
|
/**
|
|
* 终末漂洗节点单元测试
|
|
*/
|
|
class FinalRinseNodeTest extends TestCase
|
|
{
|
|
protected FinalRinseNode $node;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
$this->node = new FinalRinseNode();
|
|
}
|
|
|
|
/**
|
|
* 测试消毒后可以刷终末漂洗
|
|
*/
|
|
public function testCanHandleAfterDisinfect(): void
|
|
{
|
|
$context = $this->createContext([
|
|
'readerType' => '终末漂洗',
|
|
'currentStep' => '消毒',
|
|
]);
|
|
|
|
$this->assertTrue($this->node->canHandle($context));
|
|
}
|
|
|
|
/**
|
|
* 测试机洗后可以刷终末漂洗(默认配置)
|
|
*/
|
|
public function testCanHandleAfterMachineWashByDefault(): void
|
|
{
|
|
$context = $this->createContext([
|
|
'readerType' => '终末漂洗',
|
|
'currentStep' => '机洗',
|
|
]);
|
|
|
|
$this->assertTrue($this->node->canHandle($context));
|
|
}
|
|
|
|
/**
|
|
* 测试禁用的节点不会处理任何请求(特殊医院配置)
|
|
*/
|
|
public function testCannotHandleAfterMachineWashWhenDisabled(): void
|
|
{
|
|
$node = new FinalRinseNode();
|
|
$node->setEnabled(false); // 禁用节点
|
|
|
|
$context = $this->createContext([
|
|
'readerType' => '终末漂洗',
|
|
'currentStep' => '机洗',
|
|
]);
|
|
|
|
// 禁用的节点不处理请求:handle 直接将上下文传递给下一节点,不更改 currentStep
|
|
$result = $node->handle($context);
|
|
$this->assertEquals('机洗', $result->currentStep); // 步骤不变
|
|
$this->assertFalse($result->needDatabaseOperation); // 不写库
|
|
}
|
|
|
|
/**
|
|
* 测试不能处理非终末漂洗读卡器
|
|
*/
|
|
public function testCannotHandleNonFinalRinseReader(): void
|
|
{
|
|
$context = $this->createContext([
|
|
'readerType' => '清洗',
|
|
'currentStep' => '消毒',
|
|
]);
|
|
|
|
$this->assertFalse($this->node->canHandle($context));
|
|
}
|
|
|
|
/**
|
|
* 测试处理流程
|
|
*/
|
|
public function testHandleProcess(): void
|
|
{
|
|
$context = $this->createContext([
|
|
'readerType' => '终末漂洗',
|
|
'currentStep' => '消毒',
|
|
]);
|
|
|
|
$result = $this->node->handle($context);
|
|
|
|
$this->assertSuccess($result);
|
|
$this->assertStep($result, '终末漂洗');
|
|
$this->assertNotNull($result->getStepLastTime('终末漂洗'));
|
|
}
|
|
|
|
/**
|
|
* 测试清洗后不能直接刷终末漂洗
|
|
*/
|
|
public function testCannotHandleAfterWash(): void
|
|
{
|
|
$context = $this->createContext([
|
|
'readerType' => '终末漂洗',
|
|
'currentStep' => '清洗',
|
|
]);
|
|
|
|
$this->assertFalse($this->node->canHandle($context));
|
|
}
|
|
|
|
/**
|
|
* 测试数据库操作标记
|
|
*/
|
|
public function testDatabaseOperationFlags(): void
|
|
{
|
|
$context = $this->createContext([
|
|
'readerType' => '终末漂洗',
|
|
'currentStep' => '消毒',
|
|
]);
|
|
|
|
$this->node->handle($context);
|
|
|
|
$this->assertTrue($context->needDatabaseOperation);
|
|
$this->assertEquals(DbOperationType::INSERT, $context->dbOperation);
|
|
}
|
|
|
|
/**
|
|
* 测试 WebSocket 通知标记
|
|
*/
|
|
public function testWebSocketNotifyFlag(): void
|
|
{
|
|
$context = $this->createContext([
|
|
'readerType' => '终末漂洗',
|
|
'currentStep' => '消毒',
|
|
]);
|
|
|
|
$this->node->handle($context);
|
|
|
|
$this->assertTrue($context->needWebSocketNotify);
|
|
}
|
|
|
|
/**
|
|
* 测试节点名称和编码
|
|
*/
|
|
public function testNodeIdentity(): void
|
|
{
|
|
$this->assertEquals('终末漂洗', $this->node->getName());
|
|
$this->assertEquals('终末漂洗', $this->node->getCode());
|
|
}
|
|
}
|