mirror of
https://github.com/PhyreApps/PhyrePanel.git
synced 2024-11-21 23:20:24 +00:00
update
This commit is contained in:
parent
aad5b8b77a
commit
df34dfa71c
7 changed files with 479 additions and 2 deletions
|
@ -26,6 +26,14 @@ class NodeJsInstaller
|
|||
$commands[] = 'apt-get install -y nodejs' . $nodejsVersion;
|
||||
}
|
||||
|
||||
// Install Apache Passenger
|
||||
$commands[] = 'curl https://oss-binaries.phusionpassenger.com/auto-software-signing-gpg-key.txt | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/phusion.gpg >/dev/null';
|
||||
$commands[] = "sudo sh -c 'echo deb https://oss-binaries.phusionpassenger.com/apt/passenger jammy main > /etc/apt/sources.list.d/passenger.list'";
|
||||
$commands[] = 'apt-get update';
|
||||
$commands[] = 'sudo apt-get install -y libapache2-mod-passenger';
|
||||
$commands[] = 'sudo a2enmod passenger';
|
||||
$commands[] = 'sudo service apache2 restart';
|
||||
|
||||
$shellFileContent = '';
|
||||
foreach ($commands as $command) {
|
||||
$shellFileContent .= $command . PHP_EOL;
|
||||
|
|
|
@ -29,6 +29,14 @@ class PythonInstaller
|
|||
$commands[] = 'apt-get install -y python' . $pythonVersion . '-wheel';
|
||||
}
|
||||
|
||||
// Install Apache Passenger
|
||||
$commands[] = 'curl https://oss-binaries.phusionpassenger.com/auto-software-signing-gpg-key.txt | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/phusion.gpg >/dev/null';
|
||||
$commands[] = "sudo sh -c 'echo deb https://oss-binaries.phusionpassenger.com/apt/passenger jammy main > /etc/apt/sources.list.d/passenger.list'";
|
||||
$commands[] = 'apt-get update';
|
||||
$commands[] = 'sudo apt-get install -y libapache2-mod-passenger';
|
||||
$commands[] = 'sudo a2enmod passenger';
|
||||
$commands[] = 'sudo service apache2 restart';
|
||||
|
||||
$shellFileContent = '';
|
||||
foreach ($commands as $command) {
|
||||
$shellFileContent .= $command . PHP_EOL;
|
||||
|
|
|
@ -27,6 +27,14 @@ class RubyInstaller
|
|||
$commands[] = 'apt-get install -y ruby' . $rubyVersion . '-bundler';
|
||||
}
|
||||
|
||||
// Install Apache Passenger
|
||||
$commands[] = 'curl https://oss-binaries.phusionpassenger.com/auto-software-signing-gpg-key.txt | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/phusion.gpg >/dev/null';
|
||||
$commands[] = "sudo sh -c 'echo deb https://oss-binaries.phusionpassenger.com/apt/passenger jammy main > /etc/apt/sources.list.d/passenger.list'";
|
||||
$commands[] = 'apt-get update';
|
||||
$commands[] = 'sudo apt-get install -y libapache2-mod-passenger';
|
||||
$commands[] = 'sudo a2enmod passenger';
|
||||
$commands[] = 'sudo service apache2 restart';
|
||||
|
||||
$shellFileContent = '';
|
||||
foreach ($commands as $command) {
|
||||
$shellFileContent .= $command . PHP_EOL;
|
||||
|
|
|
@ -13,7 +13,7 @@ use Illuminate\Support\Str;
|
|||
use PHPUnit\Framework\TestCase;
|
||||
use Tests\Feature\Api\ActionTestCase;
|
||||
|
||||
class AHostingSubscriptionCreateTest extends ActionTestCase
|
||||
class HostingSubscriptionCreateTest extends ActionTestCase
|
||||
{
|
||||
function test_route_contains_middleware()
|
||||
{
|
227
web/tests/Unit/HostingSubscriptionWithNodeJSCreateTest.php
Normal file
227
web/tests/Unit/HostingSubscriptionWithNodeJSCreateTest.php
Normal file
|
@ -0,0 +1,227 @@
|
|||
<?php
|
||||
|
||||
namespace tests\Unit;
|
||||
|
||||
use App\Http\Middleware\ApiKeyMiddleware;
|
||||
use App\Installers\Server\Applications\NodeJsInstaller;
|
||||
use App\Installers\Server\Applications\PHPInstaller;
|
||||
use App\Installers\Server\Applications\PythonInstaller;
|
||||
use App\Models\Database;
|
||||
use App\Models\DatabaseUser;
|
||||
use App\Models\Domain;
|
||||
use App\Models\HostingPlan;
|
||||
use App\SupportedApplicationTypes;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Str;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Tests\Feature\Api\ActionTestCase;
|
||||
|
||||
class HostingSubscriptionWithNodeJSCreateTest extends ActionTestCase
|
||||
{
|
||||
function test_route_contains_middleware()
|
||||
{
|
||||
$this->assertRouteContainsMiddleware(
|
||||
'api.hosting-subscriptions.index',
|
||||
ApiKeyMiddleware::class
|
||||
);
|
||||
|
||||
$this->assertRouteContainsMiddleware(
|
||||
'api.hosting-subscriptions.store',
|
||||
ApiKeyMiddleware::class
|
||||
);
|
||||
|
||||
$this->assertRouteContainsMiddleware(
|
||||
'api.hosting-subscriptions.update',
|
||||
ApiKeyMiddleware::class
|
||||
);
|
||||
|
||||
$this->assertRouteContainsMiddleware(
|
||||
'api.hosting-subscriptions.destroy',
|
||||
ApiKeyMiddleware::class
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function test_create()
|
||||
{
|
||||
$this->assertTrue(Str::contains(php_uname(),'Ubuntu'));
|
||||
//
|
||||
// Make Apache+PHP Application Server with all supported php versions and modules
|
||||
$installLogFilePath = storage_path('install-apache-nodejs-log-unit-test.txt');
|
||||
$phpInstaller = new NodeJsInstaller();
|
||||
$phpInstaller->setNodeJsVersions(array_keys(SupportedApplicationTypes::getNodeJsVersions()));
|
||||
$phpInstaller->setLogFilePath($installLogFilePath);
|
||||
$phpInstaller->install();
|
||||
|
||||
$installationSuccess = false;
|
||||
for ($i = 1; $i <= 100; $i++) {
|
||||
$logContent = file_get_contents($installLogFilePath);
|
||||
if (str_contains($logContent, 'All packages installed successfully!')) {
|
||||
$installationSuccess = true;
|
||||
break;
|
||||
}
|
||||
sleep(3);
|
||||
}
|
||||
|
||||
if (!$installationSuccess) {
|
||||
$logContent = file_get_contents($installLogFilePath);
|
||||
$this->fail('Apache+NodeJS installation failed. Log: '.$logContent);
|
||||
}
|
||||
|
||||
$this->assertTrue($installationSuccess, 'Apache+NodeJS installation failed');
|
||||
|
||||
// Make unauthorized call
|
||||
$callUnauthorizedResponse = $this->callRouteAction('api.hosting-subscriptions.store')->json();
|
||||
$this->assertArrayHasKey('error', $callUnauthorizedResponse);
|
||||
$this->assertTrue($callUnauthorizedResponse['error'] == 'Unauthorized');
|
||||
|
||||
// Make authorized call without required parameters
|
||||
$callStoreResponse = $this->callApiAuthorizedRouteAction('api.hosting-subscriptions.store')->json();
|
||||
|
||||
$this->assertArrayHasKey('message', $callStoreResponse);
|
||||
$this->assertArrayHasKey('errors', $callStoreResponse);
|
||||
|
||||
$this->assertIsString($callStoreResponse['message']);
|
||||
$this->assertIsArray($callStoreResponse['errors']);
|
||||
|
||||
// Create a customer
|
||||
$randId = rand(1000, 9999);
|
||||
$callCustomerStoreResponse = $this->callApiAuthorizedRouteAction(
|
||||
'api.customers.store',
|
||||
[
|
||||
'name' => 'Phyre Unit Test #'.$randId,
|
||||
'email' => 'unit-test-'.$randId.'@phyre.com',
|
||||
]
|
||||
)->json();
|
||||
$this->assertArrayHasKey('status', $callCustomerStoreResponse);
|
||||
$this->assertTrue($callCustomerStoreResponse['status'] == 'ok');
|
||||
|
||||
$this->assertArrayHasKey('message', $callCustomerStoreResponse);
|
||||
$this->assertArrayHasKey('data', $callCustomerStoreResponse);
|
||||
$this->assertArrayHasKey('customer', $callCustomerStoreResponse['data']);
|
||||
$this->assertArrayHasKey('id', $callCustomerStoreResponse['data']['customer']);
|
||||
$this->assertIsInt($callCustomerStoreResponse['data']['customer']['id']);
|
||||
$customerId = $callCustomerStoreResponse['data']['customer']['id'];
|
||||
|
||||
// Create a hosting subscription
|
||||
$randId = rand(1000, 9999);
|
||||
$hostingPlanId = null;
|
||||
|
||||
$createHostingPlan = new HostingPlan();
|
||||
$createHostingPlan->name = 'Phyre Unit Test #'.$randId;
|
||||
$createHostingPlan->description = 'Unit Test Hosting Plan';
|
||||
$createHostingPlan->disk_space = 1000;
|
||||
$createHostingPlan->bandwidth = 1000;
|
||||
$createHostingPlan->default_server_application_type = 'apache_nodejs';
|
||||
$createHostingPlan->default_server_application_settings = [
|
||||
'nodejs_version' => '20',
|
||||
];
|
||||
$createHostingPlan->save();
|
||||
$hostingPlanId = $createHostingPlan->id;
|
||||
|
||||
|
||||
$hostingSubscriptionDomain = 'phyre-unit-test-'.$randId.'.com';
|
||||
$callHostingSubscriptionStoreResponse = $this->callApiAuthorizedRouteAction(
|
||||
'api.hosting-subscriptions.store',
|
||||
[
|
||||
'customer_id' => $customerId,
|
||||
'hosting_plan_id'=> $hostingPlanId,
|
||||
'domain' => $hostingSubscriptionDomain,
|
||||
]
|
||||
)->json();
|
||||
|
||||
$this->assertArrayHasKey('status', $callHostingSubscriptionStoreResponse);
|
||||
$this->assertTrue($callHostingSubscriptionStoreResponse['status'] == 'ok');
|
||||
|
||||
$this->assertArrayHasKey('message', $callHostingSubscriptionStoreResponse);
|
||||
$this->assertArrayHasKey('data', $callHostingSubscriptionStoreResponse);
|
||||
$this->assertArrayHasKey('hostingSubscription', $callHostingSubscriptionStoreResponse['data']);
|
||||
|
||||
$this->assertArrayHasKey('id', $callHostingSubscriptionStoreResponse['data']['hostingSubscription']);
|
||||
$this->assertIsInt($callHostingSubscriptionStoreResponse['data']['hostingSubscription']['id']);
|
||||
|
||||
$this->assertArrayHasKey('customer_id', $callHostingSubscriptionStoreResponse['data']['hostingSubscription']);
|
||||
$this->assertIsInt($callHostingSubscriptionStoreResponse['data']['hostingSubscription']['customer_id']);
|
||||
$this->assertTrue($callHostingSubscriptionStoreResponse['data']['hostingSubscription']['customer_id'] == $customerId);
|
||||
|
||||
$this->assertArrayHasKey('hosting_plan_id', $callHostingSubscriptionStoreResponse['data']['hostingSubscription']);
|
||||
$this->assertIsInt($callHostingSubscriptionStoreResponse['data']['hostingSubscription']['hosting_plan_id']);
|
||||
$this->assertTrue($callHostingSubscriptionStoreResponse['data']['hostingSubscription']['hosting_plan_id'] == $hostingPlanId);
|
||||
|
||||
$this->assertArrayHasKey('domain', $callHostingSubscriptionStoreResponse['data']['hostingSubscription']);
|
||||
|
||||
$this->assertIsString($callHostingSubscriptionStoreResponse['data']['hostingSubscription']['domain']);
|
||||
$this->assertTrue($callHostingSubscriptionStoreResponse['data']['hostingSubscription']['domain'] == $hostingSubscriptionDomain);
|
||||
|
||||
$hostingSubscriptionData = $callHostingSubscriptionStoreResponse['data']['hostingSubscription'];
|
||||
|
||||
// Get domain details
|
||||
$callDomainDetailsResponse = $this->callApiAuthorizedRouteAction(
|
||||
'api.domains.index',
|
||||
[
|
||||
'domain' => $hostingSubscriptionDomain,
|
||||
]
|
||||
)->json();
|
||||
$callDomainDetailsResponseData = $callDomainDetailsResponse['data']['domains'];
|
||||
$this->assertIsArray($callDomainDetailsResponseData);
|
||||
$this->assertNotEmpty($callDomainDetailsResponseData);
|
||||
$this->assertArrayHasKey('id', $callDomainDetailsResponseData[0]);
|
||||
$this->assertArrayHasKey('domain', $callDomainDetailsResponseData[0]);
|
||||
$this->assertArrayHasKey('hosting_subscription_id', $callDomainDetailsResponseData[0]);
|
||||
$this->assertArrayHasKey('status', $callDomainDetailsResponseData[0]);
|
||||
$this->assertArrayHasKey('created_at', $callDomainDetailsResponseData[0]);
|
||||
$this->assertArrayHasKey('updated_at', $callDomainDetailsResponseData[0]);
|
||||
$this->assertTrue($callDomainDetailsResponseData[0]['domain'] == $hostingSubscriptionDomain);
|
||||
$this->assertTrue($callDomainDetailsResponseData[0]['hosting_subscription_id'] == $hostingSubscriptionData['id']);
|
||||
$this->assertTrue($callDomainDetailsResponseData[0]['status'] == Domain::STATUS_ACTIVE);
|
||||
$this->assertTrue($callDomainDetailsResponseData[0]['is_main'] == 1);
|
||||
$domainData = $callDomainDetailsResponseData[0];
|
||||
|
||||
// Check virtual host is created
|
||||
$virtualHostFile = '/etc/apache2/apache2.conf';
|
||||
$this->assertFileExists($virtualHostFile);
|
||||
$virtualHostFileContent = file_get_contents($virtualHostFile);
|
||||
|
||||
|
||||
$this->assertStringContainsString('ServerName '.$hostingSubscriptionDomain, $virtualHostFileContent);
|
||||
//$this->assertStringContainsString('ServerAlias www.'.$hostingSubscriptionDomain, $virtualHostFileContent);
|
||||
|
||||
$this->assertStringContainsString('Directory '.$domainData['domain_public'], $virtualHostFileContent);
|
||||
$this->assertStringContainsString('DocumentRoot '.$domainData['domain_public'], $virtualHostFileContent);
|
||||
|
||||
// Check virtual host is enabled
|
||||
$this->assertFileExists('/etc/apache2/apache2.conf');
|
||||
|
||||
// Check apache config is valid
|
||||
shell_exec('apachectl -t >> /tmp/apache_config_check.txt 2>&1');
|
||||
$apacheConfigTest = file_get_contents('/tmp/apache_config_check.txt');
|
||||
unlink('/tmp/apache_config_check.txt');
|
||||
|
||||
$this->assertTrue(Str::contains($apacheConfigTest,'Syntax OK'));
|
||||
|
||||
// Check domain is accessible
|
||||
// shell_exec('sudo echo "0.0.0.0 '.$hostingSubscriptionDomain.'" | sudo tee -a /etc/hosts');
|
||||
//
|
||||
// $domainAccess = shell_exec('curl -s -o /dev/null -w "%{http_code}" http://'.$hostingSubscriptionDomain);
|
||||
// $this->assertTrue($domainAccess == 200);
|
||||
//
|
||||
// $indexPageContent = shell_exec('curl -s http://'.$hostingSubscriptionDomain);
|
||||
//
|
||||
// $this->assertTrue(Str::contains($indexPageContent,'Phyre Panel - PHP App'));
|
||||
|
||||
|
||||
// Check hosting subscription local database creation
|
||||
$newDatabase = new Database();
|
||||
$newDatabase->hosting_subscription_id = $hostingSubscriptionData['id'];
|
||||
$newDatabase->is_remote_database_server = 0;
|
||||
$newDatabase->database_name = 'ppdb'.$randId;
|
||||
$newDatabase->save();
|
||||
|
||||
$newDatabaseUser = new DatabaseUser();
|
||||
$newDatabaseUser->database_id = $newDatabase->id;
|
||||
$newDatabaseUser->username = 'pput'.$randId;
|
||||
$newDatabaseUser->password = Str::password(24);
|
||||
$newDatabaseUser->save();
|
||||
}
|
||||
|
||||
}
|
226
web/tests/Unit/HostingSubscriptionWithPythonCreateTest.php
Normal file
226
web/tests/Unit/HostingSubscriptionWithPythonCreateTest.php
Normal file
|
@ -0,0 +1,226 @@
|
|||
<?php
|
||||
|
||||
namespace tests\Unit;
|
||||
|
||||
use App\Http\Middleware\ApiKeyMiddleware;
|
||||
use App\Installers\Server\Applications\PHPInstaller;
|
||||
use App\Installers\Server\Applications\PythonInstaller;
|
||||
use App\Models\Database;
|
||||
use App\Models\DatabaseUser;
|
||||
use App\Models\Domain;
|
||||
use App\Models\HostingPlan;
|
||||
use App\SupportedApplicationTypes;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Str;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Tests\Feature\Api\ActionTestCase;
|
||||
|
||||
class HostingSubscriptionWithPythonCreateTest extends ActionTestCase
|
||||
{
|
||||
function test_route_contains_middleware()
|
||||
{
|
||||
$this->assertRouteContainsMiddleware(
|
||||
'api.hosting-subscriptions.index',
|
||||
ApiKeyMiddleware::class
|
||||
);
|
||||
|
||||
$this->assertRouteContainsMiddleware(
|
||||
'api.hosting-subscriptions.store',
|
||||
ApiKeyMiddleware::class
|
||||
);
|
||||
|
||||
$this->assertRouteContainsMiddleware(
|
||||
'api.hosting-subscriptions.update',
|
||||
ApiKeyMiddleware::class
|
||||
);
|
||||
|
||||
$this->assertRouteContainsMiddleware(
|
||||
'api.hosting-subscriptions.destroy',
|
||||
ApiKeyMiddleware::class
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function test_create()
|
||||
{
|
||||
$this->assertTrue(Str::contains(php_uname(),'Ubuntu'));
|
||||
//
|
||||
// Make Apache+PHP Application Server with all supported php versions and modules
|
||||
$installLogFilePath = storage_path('install-apache-python-log-unit-test.txt');
|
||||
$phpInstaller = new PythonInstaller();
|
||||
$phpInstaller->setPythonVersions(array_keys(SupportedApplicationTypes::getPythonVersions()));
|
||||
$phpInstaller->setLogFilePath($installLogFilePath);
|
||||
$phpInstaller->install();
|
||||
|
||||
$installationSuccess = false;
|
||||
for ($i = 1; $i <= 100; $i++) {
|
||||
$logContent = file_get_contents($installLogFilePath);
|
||||
if (str_contains($logContent, 'All packages installed successfully!')) {
|
||||
$installationSuccess = true;
|
||||
break;
|
||||
}
|
||||
sleep(3);
|
||||
}
|
||||
|
||||
if (!$installationSuccess) {
|
||||
$logContent = file_get_contents($installLogFilePath);
|
||||
$this->fail('Apache+PHP installation failed. Log: '.$logContent);
|
||||
}
|
||||
|
||||
$this->assertTrue($installationSuccess, 'Apache+Python installation failed');
|
||||
|
||||
// Make unauthorized call
|
||||
$callUnauthorizedResponse = $this->callRouteAction('api.hosting-subscriptions.store')->json();
|
||||
$this->assertArrayHasKey('error', $callUnauthorizedResponse);
|
||||
$this->assertTrue($callUnauthorizedResponse['error'] == 'Unauthorized');
|
||||
|
||||
// Make authorized call without required parameters
|
||||
$callStoreResponse = $this->callApiAuthorizedRouteAction('api.hosting-subscriptions.store')->json();
|
||||
|
||||
$this->assertArrayHasKey('message', $callStoreResponse);
|
||||
$this->assertArrayHasKey('errors', $callStoreResponse);
|
||||
|
||||
$this->assertIsString($callStoreResponse['message']);
|
||||
$this->assertIsArray($callStoreResponse['errors']);
|
||||
|
||||
// Create a customer
|
||||
$randId = rand(1000, 9999);
|
||||
$callCustomerStoreResponse = $this->callApiAuthorizedRouteAction(
|
||||
'api.customers.store',
|
||||
[
|
||||
'name' => 'Phyre Unit Test #'.$randId,
|
||||
'email' => 'unit-test-'.$randId.'@phyre.com',
|
||||
]
|
||||
)->json();
|
||||
$this->assertArrayHasKey('status', $callCustomerStoreResponse);
|
||||
$this->assertTrue($callCustomerStoreResponse['status'] == 'ok');
|
||||
|
||||
$this->assertArrayHasKey('message', $callCustomerStoreResponse);
|
||||
$this->assertArrayHasKey('data', $callCustomerStoreResponse);
|
||||
$this->assertArrayHasKey('customer', $callCustomerStoreResponse['data']);
|
||||
$this->assertArrayHasKey('id', $callCustomerStoreResponse['data']['customer']);
|
||||
$this->assertIsInt($callCustomerStoreResponse['data']['customer']['id']);
|
||||
$customerId = $callCustomerStoreResponse['data']['customer']['id'];
|
||||
|
||||
// Create a hosting subscription
|
||||
$randId = rand(1000, 9999);
|
||||
$hostingPlanId = null;
|
||||
|
||||
$createHostingPlan = new HostingPlan();
|
||||
$createHostingPlan->name = 'Phyre Unit Test #'.$randId;
|
||||
$createHostingPlan->description = 'Unit Test Hosting Plan';
|
||||
$createHostingPlan->disk_space = 1000;
|
||||
$createHostingPlan->bandwidth = 1000;
|
||||
$createHostingPlan->default_server_application_type = 'apache_python';
|
||||
$createHostingPlan->default_server_application_settings = [
|
||||
'python_version' => '3.9',
|
||||
];
|
||||
$createHostingPlan->save();
|
||||
$hostingPlanId = $createHostingPlan->id;
|
||||
|
||||
|
||||
$hostingSubscriptionDomain = 'phyre-unit-test-'.$randId.'.com';
|
||||
$callHostingSubscriptionStoreResponse = $this->callApiAuthorizedRouteAction(
|
||||
'api.hosting-subscriptions.store',
|
||||
[
|
||||
'customer_id' => $customerId,
|
||||
'hosting_plan_id'=> $hostingPlanId,
|
||||
'domain' => $hostingSubscriptionDomain,
|
||||
]
|
||||
)->json();
|
||||
|
||||
$this->assertArrayHasKey('status', $callHostingSubscriptionStoreResponse);
|
||||
$this->assertTrue($callHostingSubscriptionStoreResponse['status'] == 'ok');
|
||||
|
||||
$this->assertArrayHasKey('message', $callHostingSubscriptionStoreResponse);
|
||||
$this->assertArrayHasKey('data', $callHostingSubscriptionStoreResponse);
|
||||
$this->assertArrayHasKey('hostingSubscription', $callHostingSubscriptionStoreResponse['data']);
|
||||
|
||||
$this->assertArrayHasKey('id', $callHostingSubscriptionStoreResponse['data']['hostingSubscription']);
|
||||
$this->assertIsInt($callHostingSubscriptionStoreResponse['data']['hostingSubscription']['id']);
|
||||
|
||||
$this->assertArrayHasKey('customer_id', $callHostingSubscriptionStoreResponse['data']['hostingSubscription']);
|
||||
$this->assertIsInt($callHostingSubscriptionStoreResponse['data']['hostingSubscription']['customer_id']);
|
||||
$this->assertTrue($callHostingSubscriptionStoreResponse['data']['hostingSubscription']['customer_id'] == $customerId);
|
||||
|
||||
$this->assertArrayHasKey('hosting_plan_id', $callHostingSubscriptionStoreResponse['data']['hostingSubscription']);
|
||||
$this->assertIsInt($callHostingSubscriptionStoreResponse['data']['hostingSubscription']['hosting_plan_id']);
|
||||
$this->assertTrue($callHostingSubscriptionStoreResponse['data']['hostingSubscription']['hosting_plan_id'] == $hostingPlanId);
|
||||
|
||||
$this->assertArrayHasKey('domain', $callHostingSubscriptionStoreResponse['data']['hostingSubscription']);
|
||||
|
||||
$this->assertIsString($callHostingSubscriptionStoreResponse['data']['hostingSubscription']['domain']);
|
||||
$this->assertTrue($callHostingSubscriptionStoreResponse['data']['hostingSubscription']['domain'] == $hostingSubscriptionDomain);
|
||||
|
||||
$hostingSubscriptionData = $callHostingSubscriptionStoreResponse['data']['hostingSubscription'];
|
||||
|
||||
// Get domain details
|
||||
$callDomainDetailsResponse = $this->callApiAuthorizedRouteAction(
|
||||
'api.domains.index',
|
||||
[
|
||||
'domain' => $hostingSubscriptionDomain,
|
||||
]
|
||||
)->json();
|
||||
$callDomainDetailsResponseData = $callDomainDetailsResponse['data']['domains'];
|
||||
$this->assertIsArray($callDomainDetailsResponseData);
|
||||
$this->assertNotEmpty($callDomainDetailsResponseData);
|
||||
$this->assertArrayHasKey('id', $callDomainDetailsResponseData[0]);
|
||||
$this->assertArrayHasKey('domain', $callDomainDetailsResponseData[0]);
|
||||
$this->assertArrayHasKey('hosting_subscription_id', $callDomainDetailsResponseData[0]);
|
||||
$this->assertArrayHasKey('status', $callDomainDetailsResponseData[0]);
|
||||
$this->assertArrayHasKey('created_at', $callDomainDetailsResponseData[0]);
|
||||
$this->assertArrayHasKey('updated_at', $callDomainDetailsResponseData[0]);
|
||||
$this->assertTrue($callDomainDetailsResponseData[0]['domain'] == $hostingSubscriptionDomain);
|
||||
$this->assertTrue($callDomainDetailsResponseData[0]['hosting_subscription_id'] == $hostingSubscriptionData['id']);
|
||||
$this->assertTrue($callDomainDetailsResponseData[0]['status'] == Domain::STATUS_ACTIVE);
|
||||
$this->assertTrue($callDomainDetailsResponseData[0]['is_main'] == 1);
|
||||
$domainData = $callDomainDetailsResponseData[0];
|
||||
|
||||
// Check virtual host is created
|
||||
$virtualHostFile = '/etc/apache2/apache2.conf';
|
||||
$this->assertFileExists($virtualHostFile);
|
||||
$virtualHostFileContent = file_get_contents($virtualHostFile);
|
||||
|
||||
|
||||
$this->assertStringContainsString('ServerName '.$hostingSubscriptionDomain, $virtualHostFileContent);
|
||||
//$this->assertStringContainsString('ServerAlias www.'.$hostingSubscriptionDomain, $virtualHostFileContent);
|
||||
|
||||
$this->assertStringContainsString('Directory '.$domainData['domain_public'], $virtualHostFileContent);
|
||||
$this->assertStringContainsString('DocumentRoot '.$domainData['domain_public'], $virtualHostFileContent);
|
||||
|
||||
// Check virtual host is enabled
|
||||
$this->assertFileExists('/etc/apache2/apache2.conf');
|
||||
|
||||
// Check apache config is valid
|
||||
shell_exec('apachectl -t >> /tmp/apache_config_check.txt 2>&1');
|
||||
$apacheConfigTest = file_get_contents('/tmp/apache_config_check.txt');
|
||||
unlink('/tmp/apache_config_check.txt');
|
||||
|
||||
$this->assertTrue(Str::contains($apacheConfigTest,'Syntax OK'));
|
||||
|
||||
// Check domain is accessible
|
||||
// shell_exec('sudo echo "0.0.0.0 '.$hostingSubscriptionDomain.'" | sudo tee -a /etc/hosts');
|
||||
//
|
||||
// $domainAccess = shell_exec('curl -s -o /dev/null -w "%{http_code}" http://'.$hostingSubscriptionDomain);
|
||||
// $this->assertTrue($domainAccess == 200);
|
||||
//
|
||||
// $indexPageContent = shell_exec('curl -s http://'.$hostingSubscriptionDomain);
|
||||
//
|
||||
// $this->assertTrue(Str::contains($indexPageContent,'Phyre Panel - PHP App'));
|
||||
|
||||
|
||||
// Check hosting subscription local database creation
|
||||
$newDatabase = new Database();
|
||||
$newDatabase->hosting_subscription_id = $hostingSubscriptionData['id'];
|
||||
$newDatabase->is_remote_database_server = 0;
|
||||
$newDatabase->database_name = 'ppdb'.$randId;
|
||||
$newDatabase->save();
|
||||
|
||||
$newDatabaseUser = new DatabaseUser();
|
||||
$newDatabaseUser->database_id = $newDatabase->id;
|
||||
$newDatabaseUser->username = 'pput'.$randId;
|
||||
$newDatabaseUser->password = Str::password(24);
|
||||
$newDatabaseUser->save();
|
||||
}
|
||||
|
||||
}
|
|
@ -13,7 +13,7 @@ use Illuminate\Support\Facades\Artisan;
|
|||
use Illuminate\Support\Facades\Storage;
|
||||
use Tests\Feature\Api\ActionTestCase;
|
||||
|
||||
class BackupTest extends ActionTestCase
|
||||
class ZeroBackupTest extends ActionTestCase
|
||||
{
|
||||
public function testFullBackup()
|
||||
{
|
Loading…
Reference in a new issue