mirror of
https://gitee.com/ShopeX/ECShopX
synced 2026-08-10 13:26:05 +08:00
4.7.0
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\DistributionBundle;
|
||||
|
||||
use DistributionBundle\Services\DistributorCloudShopStatusGuard;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class DistributorCloudShopStatusGuardTest extends TestCase
|
||||
{
|
||||
public function testIsValidValuesForCloudAllListFilterIncludesLegacyNumericStrings(): void
|
||||
{
|
||||
$values = DistributorCloudShopStatusGuard::isValidValuesForCloudAllListFilter();
|
||||
|
||||
$this->assertContains('true', $values);
|
||||
$this->assertContains('false', $values);
|
||||
$this->assertContains('closed', $values);
|
||||
$this->assertContains('1', $values);
|
||||
$this->assertContains('0', $values);
|
||||
$this->assertNotContains('delete', $values);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace DistributionBundle\Tests\Services;
|
||||
|
||||
use DistributionBundle\Services\DistributorCloudShopStatusGuard;
|
||||
|
||||
class DistributorCloudShopStatusGuardTest extends \TestCase
|
||||
{
|
||||
public function testNormalizeIsValidFromRowClosed()
|
||||
{
|
||||
$row = ['is_valid' => DistributorCloudShopStatusGuard::IS_VALID_CLOSED];
|
||||
$this->assertSame(DistributorCloudShopStatusGuard::IS_VALID_CLOSED, DistributorCloudShopStatusGuard::normalizeIsValidFromRow($row));
|
||||
}
|
||||
|
||||
public function testNormalizeIsValidFromRowFalse()
|
||||
{
|
||||
$row = ['is_valid' => DistributorCloudShopStatusGuard::IS_VALID_CLOUD_DISABLED];
|
||||
$this->assertSame(DistributorCloudShopStatusGuard::IS_VALID_CLOUD_DISABLED, DistributorCloudShopStatusGuard::normalizeIsValidFromRow($row));
|
||||
}
|
||||
|
||||
public function testRequiresOpenOrdersCheckForRevoke()
|
||||
{
|
||||
$this->assertTrue(DistributorCloudShopStatusGuard::requiresOpenNormalOrdersCheck(
|
||||
DistributorCloudShopStatusGuard::IS_VALID_CLOUD_ENABLED,
|
||||
DistributorCloudShopStatusGuard::IS_VALID_REVOKED
|
||||
));
|
||||
}
|
||||
|
||||
public function testRequiresOpenOrdersCheckForClosed()
|
||||
{
|
||||
$this->assertTrue(DistributorCloudShopStatusGuard::requiresOpenNormalOrdersCheck(
|
||||
DistributorCloudShopStatusGuard::IS_VALID_CLOUD_ENABLED,
|
||||
DistributorCloudShopStatusGuard::IS_VALID_CLOSED
|
||||
));
|
||||
}
|
||||
|
||||
public function testRequiresOpenOrdersCheckForDisable()
|
||||
{
|
||||
$this->assertTrue(DistributorCloudShopStatusGuard::requiresOpenNormalOrdersCheck(
|
||||
DistributorCloudShopStatusGuard::IS_VALID_CLOUD_ENABLED,
|
||||
DistributorCloudShopStatusGuard::IS_VALID_CLOUD_DISABLED
|
||||
));
|
||||
}
|
||||
|
||||
public function testNoOrderCheckWhenLeavingClosedToEnabled()
|
||||
{
|
||||
$this->assertFalse(DistributorCloudShopStatusGuard::requiresOpenNormalOrdersCheck(
|
||||
DistributorCloudShopStatusGuard::IS_VALID_CLOSED,
|
||||
DistributorCloudShopStatusGuard::IS_VALID_CLOUD_ENABLED
|
||||
));
|
||||
}
|
||||
|
||||
public function testNormalizeIncomingIsValidBoolean()
|
||||
{
|
||||
$this->assertSame(DistributorCloudShopStatusGuard::IS_VALID_CLOUD_ENABLED, DistributorCloudShopStatusGuard::normalizeIncomingIsValid(true));
|
||||
$this->assertSame(DistributorCloudShopStatusGuard::IS_VALID_CLOUD_DISABLED, DistributorCloudShopStatusGuard::normalizeIncomingIsValid(false));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\DistributionBundle;
|
||||
|
||||
use DistributionBundle\Services\VirtualDistributorUpdateStatusGuard;
|
||||
use Dingo\Api\Exception\StoreResourceFailedException;
|
||||
|
||||
/** @see .tasks/plans/shuyun-virtual-shop-open-sync.md V-STA-01、API-01V(多字段 PUT 下 has/is_valid 意图与原始取值) */
|
||||
class VirtualDistributorUpdateStatusGuardTest extends \TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider enabledSemanticProvider
|
||||
*
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function testIsEnabledSemanticAcceptsTrueOneAndStrings($value): void
|
||||
{
|
||||
$this->assertTrue(VirtualDistributorUpdateStatusGuard::isEnabledSemanticIsValidValue($value));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return iterable<string, array{0: mixed}>
|
||||
*/
|
||||
public static function enabledSemanticProvider(): iterable
|
||||
{
|
||||
yield 'bool true' => [true];
|
||||
yield 'int 1' => [1];
|
||||
yield 'string true' => ['true'];
|
||||
yield 'string TRUE' => ['TRUE'];
|
||||
yield 'string 1' => ['1'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider nonEnabledSemanticProvider
|
||||
*
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function testIsEnabledSemanticRejectsNonEnabled($value): void
|
||||
{
|
||||
$this->assertFalse(VirtualDistributorUpdateStatusGuard::isEnabledSemanticIsValidValue($value));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return iterable<string, array{0: mixed}>
|
||||
*/
|
||||
public static function nonEnabledSemanticProvider(): iterable
|
||||
{
|
||||
yield 'bool false' => [false];
|
||||
yield 'int 0' => [0];
|
||||
yield 'string false' => ['false'];
|
||||
yield 'string 0' => ['0'];
|
||||
yield 'closed' => ['closed'];
|
||||
yield 'delete' => ['delete'];
|
||||
}
|
||||
|
||||
public function testVirtualShopWithIsValidFalseThrows(): void
|
||||
{
|
||||
$this->expectException(StoreResourceFailedException::class);
|
||||
VirtualDistributorUpdateStatusGuard::forbidNonEnabledStatusIntentForVirtualShop(
|
||||
true,
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
''
|
||||
);
|
||||
}
|
||||
|
||||
public function testVirtualShopWithReviewRejectThrows(): void
|
||||
{
|
||||
$this->expectException(StoreResourceFailedException::class);
|
||||
VirtualDistributorUpdateStatusGuard::forbidNonEnabledStatusIntentForVirtualShop(
|
||||
true,
|
||||
false,
|
||||
null,
|
||||
true,
|
||||
'false'
|
||||
);
|
||||
}
|
||||
|
||||
public function testNonVirtualShopDoesNotThrowForIllegalIsValid(): void
|
||||
{
|
||||
VirtualDistributorUpdateStatusGuard::forbidNonEnabledStatusIntentForVirtualShop(
|
||||
false,
|
||||
true,
|
||||
'closed',
|
||||
false,
|
||||
''
|
||||
);
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
public function testVirtualShopProfileOnlyIntentDoesNotThrow(): void
|
||||
{
|
||||
VirtualDistributorUpdateStatusGuard::forbidNonEnabledStatusIntentForVirtualShop(
|
||||
true,
|
||||
false,
|
||||
null,
|
||||
false,
|
||||
''
|
||||
);
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
public function testVirtualShopIsValidTrueDoesNotThrow(): void
|
||||
{
|
||||
VirtualDistributorUpdateStatusGuard::forbidNonEnabledStatusIntentForVirtualShop(
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
false,
|
||||
''
|
||||
);
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user