diff --git a/web/tests/Unit/BackupTest.php b/web/tests/Unit/BackupTest.php index 4314380..1ddac3a 100644 --- a/web/tests/Unit/BackupTest.php +++ b/web/tests/Unit/BackupTest.php @@ -45,8 +45,7 @@ class BackupTest extends ActionTestCase $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; @@ -73,12 +72,6 @@ class BackupTest extends ActionTestCase 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')); - } diff --git a/web/tests/Unit/HostingSubscriptionBackupTest.php b/web/tests/Unit/HostingSubscriptionBackupTest.php new file mode 100644 index 0000000..0ebedbd --- /dev/null +++ b/web/tests/Unit/HostingSubscriptionBackupTest.php @@ -0,0 +1,85 @@ +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')); + + + } + +}