55 lines
2.4 KiB
PHP
55 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit\EcommerceFinance;
|
|
|
|
use Modules\EcommerceFinance\Services\DingPayableWorkflowStatus;
|
|
use PHPUnit\Framework\Attributes\DataProvider;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class DingPayableWorkflowStatusTest extends TestCase
|
|
{
|
|
#[DataProvider('statusLabelProvider')]
|
|
public function test_label_follows_ding_talk_lifecycle_and_result(
|
|
array $workflow,
|
|
string $expected,
|
|
): void {
|
|
$this->assertSame($expected, DingPayableWorkflowStatus::label($workflow));
|
|
}
|
|
|
|
public static function statusLabelProvider(): array
|
|
{
|
|
return [
|
|
'new keeps the existing label' => [['status' => 'NEW'], '待提交'],
|
|
'draft keeps the existing label' => [['status' => 'DRAFT'], '草稿'],
|
|
'running' => [['status' => 'RUNNING', 'result' => ''], '进行中'],
|
|
'completed and agreed' => [['status' => 'COMPLETED', 'result' => 'agree'], '已完成'],
|
|
'completed and refused' => [['status' => 'COMPLETED', 'result' => 'refuse'], '已拒绝'],
|
|
'terminated' => [['status' => 'TERMINATED', 'result' => ''], '已撤回'],
|
|
'canceled' => [['status' => 'CANCELED', 'result' => ''], '已撤回'],
|
|
'legacy rejected status' => [['status' => 'REJECTED', 'result' => ''], '已拒绝'],
|
|
'failed' => [['status' => 'FAILED', 'result' => ''], '失败'],
|
|
'empty' => [[], '-'],
|
|
];
|
|
}
|
|
|
|
#[DataProvider('statusFilterProvider')]
|
|
public function test_filter_uses_the_same_canonical_status(
|
|
array $workflow,
|
|
string $requested,
|
|
bool $expected,
|
|
): void {
|
|
$this->assertSame($expected, DingPayableWorkflowStatus::matchesFilter($workflow, $requested));
|
|
}
|
|
|
|
public static function statusFilterProvider(): array
|
|
{
|
|
return [
|
|
'refused is not completed' => [['status' => 'COMPLETED', 'result' => 'refuse'], 'COMPLETED', false],
|
|
'refused matches rejected' => [['status' => 'COMPLETED', 'result' => 'refuse'], 'REJECTED', true],
|
|
'terminated matches withdrawn' => [['status' => 'TERMINATED', 'result' => ''], 'WITHDRAWN', true],
|
|
'legacy terminated filter remains compatible' => [['status' => 'TERMINATED', 'result' => ''], 'TERMINATED', true],
|
|
'running matches pending alias' => [['status' => 'RUNNING', 'result' => ''], 'PENDING', true],
|
|
];
|
|
}
|
|
}
|