You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.9 KiB
PHP
56 lines
1.9 KiB
PHP
<?php
|
|
|
|
// Pure field-contract fixture: no Eloquent bootstrap or database connection.
|
|
namespace App\Models {
|
|
class User
|
|
{
|
|
public int $id = 0;
|
|
public int $is_admin = 0;
|
|
public int $restrict_recharge = 0;
|
|
public int $restrict_balance_purchase = 0;
|
|
public int $restrict_invite = 0;
|
|
public int $restrict_ticket = 0;
|
|
public int $restrict_transaction_records = 0;
|
|
}
|
|
}
|
|
|
|
namespace {
|
|
require dirname(__DIR__) . '/app/Services/UserFeatureRestrictionService.php';
|
|
|
|
use App\Models\User;
|
|
use App\Services\UserFeatureRestrictionService;
|
|
|
|
$fields = [
|
|
'restrict_recharge' => 'recharge',
|
|
'restrict_balance_purchase' => 'balance_purchase',
|
|
'restrict_invite' => 'invite',
|
|
'restrict_ticket' => 'ticket',
|
|
'restrict_transaction_records' => 'transaction_records',
|
|
];
|
|
foreach (array_merge([null], array_keys($fields)) as $restrictedField) {
|
|
$user = new User();
|
|
$user->id = 42;
|
|
$user->is_admin = 0;
|
|
foreach ($fields as $field => $statusKey) {
|
|
$user->$field = $field === $restrictedField ? 1 : 0;
|
|
}
|
|
$status = UserFeatureRestrictionService::status($user);
|
|
foreach ($fields as $field => $statusKey) {
|
|
if ($status[$statusKey] !== ($field === $restrictedField)) {
|
|
fwrite(STDERR, 'Manual restriction affected the wrong feature: ' . $statusKey . PHP_EOL);
|
|
exit(1);
|
|
}
|
|
}
|
|
if (UserFeatureRestrictionService::hasManualRestrictions($user) !== ($restrictedField !== null)) {
|
|
fwrite(STDERR, 'Manual restriction presence check failed.' . PHP_EOL);
|
|
exit(1);
|
|
}
|
|
}
|
|
if (method_exists(UserFeatureRestrictionService::class, 'isAutomaticCommerceRestricted')
|
|
|| method_exists(UserFeatureRestrictionService::class, 'isSubscriptionRestricted')) {
|
|
fwrite(STDERR, 'Retired membership/subscription restrictions remain.' . PHP_EOL);
|
|
exit(1);
|
|
}
|
|
echo 'Independent manual restrictions passed without membership or proxy fields.' . PHP_EOL;
|
|
}
|