Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
bobimicroweber committed Apr 25, 2024
1 parent 91deabb commit 878b98a
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 8 deletions.
9 changes: 1 addition & 8 deletions web/tests/Unit/BackupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ public function testBackup()
$hostingSubscription->save();

$backup = new Backup();
$backup->backup_type = 'hosting_subscription';
$backup->hosting_subscription_id = $hostingSubscription->id;
$backup->backup_type = 'full';
$backup->save();

$backupId = $backup->id;
Expand All @@ -73,12 +72,6 @@ public function testBackup()

Helpers::extractTar($findBackup->filepath, $findBackup->path . '/unit-test');

$this->assertTrue(is_dir($findBackup->path . '/unit-test'));
$this->assertTrue(is_dir($findBackup->path . '/unit-test/' . $hostingSubscription->system_username));
$this->assertTrue(is_dir($findBackup->path . '/unit-test/' . $hostingSubscription->system_username . '/public_html'));
$this->assertTrue(is_dir($findBackup->path . '/unit-test/' . $hostingSubscription->system_username . '/public_html/cgi-bin'));
$this->assertTrue(is_file($findBackup->path . '/unit-test/' . $hostingSubscription->system_username . '/public_html/index.php'));


}

Expand Down
85 changes: 85 additions & 0 deletions web/tests/Unit/HostingSubscriptionBackupTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

namespace tests\Unit;

use App\Filament\Enums\BackupStatus;
use App\Helpers;
use App\Models\Customer;
use App\Models\HostingPlan;
use App\Models\HostingSubscription;
use App\Models\HostingSubscriptionBackup;
use Faker\Factory;
use Tests\Feature\Api\ActionTestCase;

class HostingSubscriptionBackupTest extends ActionTestCase
{
public function testBackup()
{
$backup = new HostingSubscriptionBackup();
$checkCronJob = $backup->checkCronJob();
$this->assertTrue($checkCronJob);

$customer = new Customer();
$customer->name = 'UnitBackupTest' . time();
$customer->email = 'UnitBackupTest' . time() . '@unit-test.com';
$customer->save();

$hostingPlan = new HostingPlan();
$hostingPlan->name = 'UnitBackupTest' . time();
$hostingPlan->description = 'Unit Backup Test';
$hostingPlan->disk_space = 1000;
$hostingPlan->bandwidth = 1000;
$hostingPlan->databases = 1;
$hostingPlan->additional_services = ['daily_backups'];
$hostingPlan->features = [];
$hostingPlan->default_server_application_type = 'apache_php';
$hostingPlan->default_server_application_settings = [
'php_version' => '8.3',
];
$hostingPlan->save();

$hostingSubscription = new HostingSubscription();
$hostingSubscription->customer_id = $customer->id;
$hostingSubscription->hosting_plan_id = $hostingPlan->id;
$hostingSubscription->domain = 'unit-backup-test' . time() . '.com';
$hostingSubscription->save();

$backup = new HostingSubscriptionBackup();
$backup->backup_type = 'full';
$backup->hosting_subscription_id = $hostingSubscription->id;
$backup->save();

$backupId = $backup->id;

$findBackup = false;
$backupCompleted = false;
for ($i = 0; $i < 50; $i++) {
$findBackup = HostingSubscriptionBackup::where('id', $backupId)->first();
$findBackup->checkBackup();
if ($findBackup->status == BackupStatus::Completed) {
$backupCompleted = true;
break;
}
sleep(1);
}

$this->assertTrue($backupCompleted);
$this->assertNotEmpty($findBackup->filepath);
$this->assertTrue(file_exists($findBackup->filepath));

$getFilesize = filesize($findBackup->filepath);
$this->assertGreaterThan(0, $getFilesize);
$this->assertSame(Helpers::checkPathSize($findBackup->path), $findBackup->size);

Helpers::extractTar($findBackup->filepath, $findBackup->path . '/unit-test');

$this->assertTrue(is_dir($findBackup->path . '/unit-test'));
$this->assertTrue(is_dir($findBackup->path . '/unit-test/' . $hostingSubscription->system_username));
$this->assertTrue(is_dir($findBackup->path . '/unit-test/' . $hostingSubscription->system_username . '/public_html'));
$this->assertTrue(is_dir($findBackup->path . '/unit-test/' . $hostingSubscription->system_username . '/public_html/cgi-bin'));
$this->assertTrue(is_file($findBackup->path . '/unit-test/' . $hostingSubscription->system_username . '/public_html/index.php'));


}

}

0 comments on commit 878b98a

Please sign in to comment.