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.
virt/web/tests/CloudPaidIpChangeFeatureTes...

63 lines
1.8 KiB
PHP

<?php
require dirname(__DIR__) . '/vendor/autoload.php';
use App\Services\Cloud\CloudError;
use App\Services\Cloud\CloudPaidIpChangeFeature;
use Illuminate\Database\Capsule\Manager as Capsule;
use Illuminate\Database\Schema\Blueprint;
$assert = static function (bool $condition, string $message): void {
if (!$condition) {
throw new RuntimeException($message);
}
};
$capsule = new Capsule();
$capsule->addConnection([
'driver' => 'sqlite',
'database' => ':memory:',
], 'default');
$capsule->setAsGlobal();
$capsule->bootEloquent();
$capsule->getConnection('default')->getSchemaBuilder()
->create('configurations', static function (Blueprint $table): void {
$table->increments('id');
$table->string('name')->unique();
$table->string('value')->nullable();
});
$assert(
CloudPaidIpChangeFeature::visible(),
'A missing visibility row must preserve the existing tenant entry.'
);
Capsule::table('configurations')->insert([
'name' => CloudPaidIpChangeFeature::CONFIG_KEY,
'value' => 'false',
]);
$assert(
!CloudPaidIpChangeFeature::visible(),
'The disabled visibility row did not hide the tenant feature.'
);
try {
CloudPaidIpChangeFeature::assertVisible();
$assert(false, 'The hidden tenant feature did not reject direct access.');
} catch (CloudError $error) {
$assert(
$error->httpStatus === 403,
'The hidden tenant feature returned the wrong HTTP status.'
);
}
Capsule::table('configurations')
->where('name', CloudPaidIpChangeFeature::CONFIG_KEY)
->update(['value' => 'true']);
$assert(
CloudPaidIpChangeFeature::visible(),
'The enabled visibility row did not expose the tenant feature.'
);
CloudPaidIpChangeFeature::assertVisible();
echo "Cloud paid IP-change visibility tests passed.\n";