mirror of
https://github.com/FOSSBilling/FOSSBilling.git
synced 2026-12-01 04:40:45 +09:00
* Introduce RequiredParams attribute * Use the new RequiredParams attribute instead * Make sure we are always passing an array * Fixed tests * Fixed tests * Fixed tests * Fix validation attribute test failures Added back manual parameter validation to API methods that use RequiredParams attributes. The attribute validation only works when methods are called through Api_Handler, but tests call methods directly. Changes: - Added checkRequiredParamsForArray calls to methods with RequiredParams - Updated tests to include validators in DI containers - Fixed HTTPS URL expectation in Invoice test - Ensured all 1673 tests pass This maintains both attribute-based validation (for Handler calls) and inline validation (for direct calls and tests). * Fix RequiredParams attribute validation in tests - Made Api_Handler::validateRequiredParams() public to enable testing - Added validateRequiredParams() helper method to BBTestCase for test validation - Updated all failing tests to call validation before API methods - Added RequiredParams attribute to Servicedomain update() method - Fixed test expectation message to match actual error message - All 1673 tests now pass successfully This completes the RequiredParams attribute implementation by ensuring tests properly validate required parameters through the attribute system rather than relying on manual validation calls. * Remove duplicate manual validation from API methods Removed checkRequiredParamsForArray calls that were duplicating the RequiredParams attribute validation. These manual calls are no longer needed since the Api_Handler now processes the attributes automatically. Files updated: - Client/Api/Admin.php: Removed duplicate 'id' validation in update() - Currency/Api/Admin.php: Removed duplicate 'code' validation in delete() - Profile/Api/Admin.php: Removed duplicate password field validation in change_password() - Staff/Api/Guest.php: Removed duplicate email/password validation in login() - Support/Api/Admin.php: Removed duplicate 'id' validation in kb_category_* methods All methods now rely solely on the RequiredParams attribute for validation. * Introduce RequiredParams attribute * Use the new RequiredParams attribute instead * Make sure we are always passing an array * Fixed tests * Fixed tests * Fixed tests * Fix validation attribute test failures Added back manual parameter validation to API methods that use RequiredParams attributes. The attribute validation only works when methods are called through Api_Handler, but tests call methods directly. Changes: - Added checkRequiredParamsForArray calls to methods with RequiredParams - Updated tests to include validators in DI containers - Fixed HTTPS URL expectation in Invoice test - Ensured all 1673 tests pass This maintains both attribute-based validation (for Handler calls) and inline validation (for direct calls and tests). * Fix RequiredParams attribute validation in tests - Made Api_Handler::validateRequiredParams() public to enable testing - Added validateRequiredParams() helper method to BBTestCase for test validation - Updated all failing tests to call validation before API methods - Added RequiredParams attribute to Servicedomain update() method - Fixed test expectation message to match actual error message - All 1673 tests now pass successfully This completes the RequiredParams attribute implementation by ensuring tests properly validate required parameters through the attribute system rather than relying on manual validation calls. * Remove duplicate manual validation from API methods Removed checkRequiredParamsForArray calls that were duplicating the RequiredParams attribute validation. These manual calls are no longer needed since the Api_Handler now processes the attributes automatically. Files updated: - Client/Api/Admin.php: Removed duplicate 'id' validation in update() - Currency/Api/Admin.php: Removed duplicate 'code' validation in delete() - Profile/Api/Admin.php: Removed duplicate password field validation in change_password() - Staff/Api/Guest.php: Removed duplicate email/password validation in login() - Support/Api/Admin.php: Removed duplicate 'id' validation in kb_category_* methods All methods now rely solely on the RequiredParams attribute for validation. * Fix RequiredParams validation in tests - Updated 10 tests to call validateRequiredParams() before API methods - Fixed error message expectation in Client::update test - Changed Staff login mock expectations from atLeastOnce to never (validation throws before validateAndSanitizeEmail is reached) - Added missing validator to DI containers in Currency and Support tests - Fixed http to https in Invoice callback URL test All RequiredParams validation tests now properly test the attribute system. * Fix kbHitView mock return type errors The kbHitView method has a void return type, so mocks should not specify a return value. Removed willReturn() calls from all kbHitView mock setups. Reduced errors from 70 to 64. * Add location/ directory to gitignore * Fix all void return type mock errors Removed willReturn(null) from checkRequiredParamsForArray mocks and other void methods. These methods have void return types and should not specify return values in mocks. Result: All 1673 tests now pass with 0 failures and 0 errors! Only 30 PHPUnit deprecation warnings remain (not errors). * chore: stabilize legacy tests after merge from main - Fix PHPUnit 11 attribute compatibility issues (DataProvider, Group). - Fix DI container issues in legacy tests by ensuring 'validator' and 'tools' are always available. - Resolve 'IncompatibleReturnValueException' in mocks due to updated method return types (void, bool, int). - Fix broken class/namespace references in mocks using 'getMockBuilder' and 'createMock'. - Restore missing 'deleteLoginHistory' method in Staff Service. - Remove obsolete Branding module legacy tests. * chore: fully resolve legacy test failures and restore passing state - Fixed 'testUninstall' in Extension module by allowing Filesystem injection. - Restored missing 'deleteLoginHistory' in Staff Service. - Updated all mocks for 'checkRequiredParamsForArray' to be optional (any()) as it's now handled by attributes. - Corrected numerous assertions from assertIsArray/assertIsInt to assertTrue for methods whose return type changed to bool. - Fixed relative class references and namespaces in several legacy tests. * chore: eliminate all PHPUnit deprecations and resolve final test failures - Replaced deprecated 'new ServiceTest()' manual instantiation in data providers with string identifiers. - Updated 'onConsecutiveCalls' usage to use the newer 'willReturn' syntax for multiple values. - Fixed numerous 'TypeError' and dynamic expectation call issues introduced during refactoring. - Improved 'Email Service' by moving salt retrieval from static Config to DI container for better testability. - Resolved all remaining legacy test failures and deprecations. * Remove unused asset file Deleted the file at location/Of/Assets/file as it is no longer needed. * Restore Branding module with service, icon, and manifest Introduces a new Branding module including the service class, SVG icon, and manifest file. This module allows voluntary display of FOSSBilling references and includes basic module permissions and uninstall functionality. * Update .gitignore and add .gitkeep for cache directory Modified .gitignore to properly ignore cache files while allowing the .gitkeep file to be tracked. Added src/data/cache/.gitkeep to ensure the cache directory is present in the repository. * These were removed in #3026 and seem to be accidentally reintroduced. * No need to use it here * Also removed with #3026. * Also removed with #3026. * Update dependencies in composer.lock Bump nette/utils from v4.1.0 to v4.1.1 and react/child-process from v0.6.6 to v0.6.7 in composer.lock to include latest bug fixes and improvements. * Update service test mocks and improve test setup Refactored Extension ServiceTest to properly mock getExtensionPath and filesystem exists, ensuring temp directories are created and cleaned up within the test. Updated Invoice ServiceTest to include 'toApiArray' in the list of mocked methods for relevant tests. --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Adam Daley <admdly@users.noreply.github.com>
1282 lines
44 KiB
PHP
1282 lines
44 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Box\Mod\Servicehosting;
|
|
use PHPUnit\Framework\Attributes\DataProvider;
|
|
use PHPUnit\Framework\Attributes\Group;
|
|
|
|
#[Group('Core')]
|
|
final class ServiceTest extends \BBTestCase
|
|
{
|
|
protected ?Service $service;
|
|
|
|
public function setUp(): void
|
|
{
|
|
$this->service = new Service();
|
|
}
|
|
|
|
public function testGetDi(): void
|
|
{
|
|
$di = $this->getDi();
|
|
$this->service->setDi($di);
|
|
$getDi = $this->service->getDi();
|
|
$this->assertEquals($di, $getDi);
|
|
}
|
|
|
|
public static function validateOrdertDataProvider(): array
|
|
{
|
|
return [
|
|
['server_id', 'Hosting product is not configured completely. Configure server for hosting product.', 701],
|
|
['hosting_plan_id', 'Hosting product is not configured completely. Configure hosting plan for hosting product.', 702],
|
|
['sld', 'Domain name is invalid.', 703],
|
|
['tld', 'Domain extension is invalid.', 704],
|
|
];
|
|
}
|
|
|
|
#[DataProvider('validateOrdertDataProvider')]
|
|
public function testValidateOrderData(string $field, string $exceptionMessage, int $excCode): void
|
|
{
|
|
$data = [
|
|
'server_id' => 1,
|
|
'hosting_plan_id' => 2,
|
|
'sld' => 'great',
|
|
'tld' => 'com',
|
|
];
|
|
|
|
unset($data[$field]);
|
|
|
|
$this->expectException(\FOSSBilling\Exception::class);
|
|
$this->expectExceptionMessage($exceptionMessage);
|
|
$this->service->validateOrderData($data);
|
|
}
|
|
|
|
public function testActionCreate(): void
|
|
{
|
|
$orderModel = new \Model_ClientOrder();
|
|
$orderModel->loadBean(new \DummyBean());
|
|
$confArr = [
|
|
'server_id' => 1,
|
|
'hosting_plan_id' => 2,
|
|
'sld' => 'great',
|
|
'tld' => 'com',
|
|
];
|
|
$orderServiceMock = $this->createMock(\Box\Mod\Order\Service::class);
|
|
$orderServiceMock->expects($this->atLeastOnce())
|
|
->method('getConfig')
|
|
->willReturn($confArr);
|
|
|
|
$hostingServerModel = new \Model_ServiceHostingServer();
|
|
$hostingServerModel->loadBean(new \DummyBean());
|
|
$hostingPlansModel = new \Model_ServiceHostingHp();
|
|
$hostingPlansModel->loadBean(new \DummyBean());
|
|
$dbMock = $this->createMock('\Box_Database');
|
|
$dbMock->expects($this->atLeastOnce())
|
|
->method('getExistingModelById')
|
|
->willReturnOnConsecutiveCalls($hostingServerModel, $hostingPlansModel);
|
|
|
|
$servhostingModel = new \Model_ServiceHosting();
|
|
$servhostingModel->loadBean(new \DummyBean());
|
|
$dbMock->expects($this->atLeastOnce())
|
|
->method('dispense')
|
|
->willReturn($servhostingModel);
|
|
|
|
$newserviceHostingId = 4;
|
|
$dbMock->expects($this->atLeastOnce())
|
|
->method('store')
|
|
->willReturn($newserviceHostingId);
|
|
|
|
$di = $this->getDi();
|
|
$di['db'] = $dbMock;
|
|
$di['mod_service'] = $di->protect(fn (): \PHPUnit\Framework\MockObject\MockObject => $orderServiceMock);
|
|
|
|
$this->service->setDi($di);
|
|
$this->service->action_create($orderModel);
|
|
}
|
|
|
|
// public function testAction_activate()
|
|
// {
|
|
// $orderModel = new \Model_ClientOrder();
|
|
// $orderModel->loadBean(new \DummyBean());
|
|
//
|
|
// $confArr = array(
|
|
// 'server_id' => 1,
|
|
// 'hosting_plan_id' => 2,
|
|
// 'sld' => 'great',
|
|
// 'tld' => 'com',
|
|
// 'username' => 'username',
|
|
// 'password' => 'password'
|
|
// );
|
|
//
|
|
// $orderServiceMock = $this->createMock(\Box\Mod\Order\Service::class);
|
|
// $orderServiceMock->expects($this->atLeastOnce())
|
|
// ->method('getConfig')
|
|
// ->will($this->returnValue($confArr));
|
|
//
|
|
// $servhostingModel = new \Model_ServiceHosting();
|
|
// $servhostingModel->loadBean(new \DummyBean());
|
|
// $orderServiceMock->expects($this->atLeastOnce())
|
|
// ->method('getOrderService')
|
|
// ->will($this->returnValue($servhostingModel));
|
|
//
|
|
//
|
|
// $toolsMock = $this->createMock(\FOSSBilling\Tools::class);
|
|
// $toolsMock->expects($this->atLeastOnce())
|
|
// ->method('generatePassword')
|
|
// ->will($this->returnValue('generatePassword'));
|
|
//
|
|
// $dbMock = $this->createMock('\Box_Database');
|
|
// $dbMock->expects($this->atLeastOnce())
|
|
// ->method('store');
|
|
//
|
|
// $serviceMock = $this->getMockBuilder(\Box\Mod\Servicehosting\Service::class)
|
|
// ->onlyMethods(array('_getAM'))
|
|
// ->getMock();
|
|
//
|
|
// $serverManagerMock = $this->getMockBuilder('\Server_Manager_Custom')->disableOriginalConstructor()->getMock();
|
|
// $serverManagerMock->expects($this->atLeastOnce())
|
|
// ->method('createAccount');
|
|
//
|
|
// $AMresultArray = array($serverManagerMock, new \Server_Account());
|
|
// $serviceMock->expects($this->atLeastOnce())
|
|
// ->method('_getAM')
|
|
// ->will($this->returnValue($AMresultArray));
|
|
//
|
|
// $di = $this->getDi();
|
|
// $di['db'] = $dbMock;
|
|
// $di['tools'] = $toolsMock;
|
|
// $di['mod_service'] = $di->protect(fn() => $orderServiceMock);
|
|
//
|
|
// $serviceMock->setDi($di);
|
|
// $orderModel->config = $confArr;
|
|
// $result = $serviceMock->action_activate($orderModel);
|
|
// $this->assertIsArray($result);
|
|
// $this->assertNotEmpty($result['username']);
|
|
// $this->assertNotEmpty($result['password']);
|
|
// }
|
|
|
|
public function testActionRenew(): void
|
|
{
|
|
$orderModel = new \Model_ClientOrder();
|
|
$orderModel->loadBean(new \DummyBean());
|
|
|
|
$model = new \Model_ServiceHostingHp();
|
|
$model->loadBean(new \DummyBean());
|
|
|
|
$orderServiceMock = $this->createMock(\Box\Mod\Order\Service::class);
|
|
$orderServiceMock->expects($this->atLeastOnce())
|
|
->method('getOrderService')
|
|
->willReturn($model);
|
|
|
|
$dbMock = $this->createMock('\Box_Database');
|
|
$dbMock->expects($this->atLeastOnce())
|
|
->method('store');
|
|
|
|
$di = $this->getDi();
|
|
$di['db'] = $dbMock;
|
|
$di['mod_service'] = $di->protect(fn (): \PHPUnit\Framework\MockObject\MockObject => $orderServiceMock);
|
|
|
|
$this->service->setDi($di);
|
|
$result = $this->service->action_renew($orderModel);
|
|
$this->assertTrue($result);
|
|
}
|
|
|
|
public function testActionRenewOrderWithoutActiveService(): void
|
|
{
|
|
$orderModel = new \Model_ClientOrder();
|
|
$orderModel->loadBean(new \DummyBean());
|
|
$orderModel->id = 1;
|
|
|
|
$orderServiceMock = $this->createMock(\Box\Mod\Order\Service::class);
|
|
$orderServiceMock->expects($this->atLeastOnce())
|
|
->method('getOrderService');
|
|
|
|
$di = $this->getDi();
|
|
$di['mod_service'] = $di->protect(fn (): \PHPUnit\Framework\MockObject\MockObject => $orderServiceMock);
|
|
|
|
$this->service->setDi($di);
|
|
$this->expectException(\FOSSBilling\Exception::class);
|
|
$this->expectExceptionMessage(sprintf('Order %d has no active service', $orderModel->id));
|
|
$this->service->action_renew($orderModel);
|
|
}
|
|
|
|
public function testActionSuspend(): void
|
|
{
|
|
$orderModel = new \Model_ClientOrder();
|
|
$orderModel->loadBean(new \DummyBean());
|
|
|
|
$model = new \Model_ServiceHosting();
|
|
$model->loadBean(new \DummyBean());
|
|
|
|
$orderServiceMock = $this->createMock(\Box\Mod\Order\Service::class);
|
|
$orderServiceMock->expects($this->atLeastOnce())
|
|
->method('getOrderService')
|
|
->willReturn($model);
|
|
|
|
$dbMock = $this->createMock('\Box_Database');
|
|
$dbMock->expects($this->atLeastOnce())
|
|
->method('store');
|
|
|
|
$di = $this->getDi();
|
|
$di['db'] = $dbMock;
|
|
$di['mod_service'] = $di->protect(fn (): \PHPUnit\Framework\MockObject\MockObject => $orderServiceMock);
|
|
|
|
$serviceMock = $this->getMockBuilder(Service::class)
|
|
->onlyMethods(['_getAM'])
|
|
->getMock();
|
|
$serverManagerMock = $this->getMockBuilder('\Server_Manager_Custom')->disableOriginalConstructor()->getMock();
|
|
$serverManagerMock->expects($this->atLeastOnce())
|
|
->method('suspendAccount');
|
|
$AMresultArray = [$serverManagerMock, new \Server_Account()];
|
|
$serviceMock->expects($this->atLeastOnce())
|
|
->method('_getAM')
|
|
->willReturn($AMresultArray);
|
|
|
|
$serviceMock->setDi($di);
|
|
$result = $serviceMock->action_suspend($orderModel);
|
|
$this->assertTrue($result);
|
|
}
|
|
|
|
public function testActionSuspendOrderWithoutActiveService(): void
|
|
{
|
|
$orderModel = new \Model_ClientOrder();
|
|
$orderModel->loadBean(new \DummyBean());
|
|
$orderModel->id = 1;
|
|
|
|
$orderServiceMock = $this->createMock(\Box\Mod\Order\Service::class);
|
|
$orderServiceMock->expects($this->atLeastOnce())
|
|
->method('getOrderService');
|
|
|
|
$di = $this->getDi();
|
|
$di['mod_service'] = $di->protect(fn (): \PHPUnit\Framework\MockObject\MockObject => $orderServiceMock);
|
|
|
|
$this->service->setDi($di);
|
|
$this->expectException(\FOSSBilling\Exception::class);
|
|
$this->expectExceptionMessage(sprintf('Order %d has no active service', $orderModel->id));
|
|
$this->service->action_suspend($orderModel);
|
|
}
|
|
|
|
public function testActionUnsuspend(): void
|
|
{
|
|
$orderModel = new \Model_ClientOrder();
|
|
$orderModel->loadBean(new \DummyBean());
|
|
|
|
$model = new \Model_ServiceHosting();
|
|
$model->loadBean(new \DummyBean());
|
|
|
|
$orderServiceMock = $this->createMock(\Box\Mod\Order\Service::class);
|
|
$orderServiceMock->expects($this->atLeastOnce())
|
|
->method('getOrderService')
|
|
->willReturn($model);
|
|
|
|
$dbMock = $this->createMock('\Box_Database');
|
|
$dbMock->expects($this->atLeastOnce())
|
|
->method('store');
|
|
|
|
$di = $this->getDi();
|
|
$di['db'] = $dbMock;
|
|
$di['mod_service'] = $di->protect(fn (): \PHPUnit\Framework\MockObject\MockObject => $orderServiceMock);
|
|
|
|
$serviceMock = $this->getMockBuilder(Service::class)
|
|
->onlyMethods(['_getAM'])
|
|
->getMock();
|
|
$serverManagerMock = $this->getMockBuilder('\Server_Manager_Custom')->disableOriginalConstructor()->getMock();
|
|
$serverManagerMock->expects($this->atLeastOnce())
|
|
->method('unsuspendAccount');
|
|
$AMresultArray = [$serverManagerMock, new \Server_Account()];
|
|
$serviceMock->expects($this->atLeastOnce())
|
|
->method('_getAM')
|
|
->willReturn($AMresultArray);
|
|
|
|
$serviceMock->setDi($di);
|
|
$result = $serviceMock->action_unsuspend($orderModel);
|
|
$this->assertTrue($result);
|
|
}
|
|
|
|
public function testActionUnsuspendOrderWithoutActiveService(): void
|
|
{
|
|
$orderModel = new \Model_ClientOrder();
|
|
$orderModel->loadBean(new \DummyBean());
|
|
$orderModel->id = 1;
|
|
|
|
$orderServiceMock = $this->createMock(\Box\Mod\Order\Service::class);
|
|
$orderServiceMock->expects($this->atLeastOnce())
|
|
->method('getOrderService');
|
|
|
|
$di = $this->getDi();
|
|
$di['mod_service'] = $di->protect(fn (): \PHPUnit\Framework\MockObject\MockObject => $orderServiceMock);
|
|
|
|
$this->service->setDi($di);
|
|
$this->expectException(\FOSSBilling\Exception::class);
|
|
$this->expectExceptionMessage(sprintf('Order %d has no active service', $orderModel->id));
|
|
$this->service->action_unsuspend($orderModel);
|
|
}
|
|
|
|
public function testActionCancel(): void
|
|
{
|
|
$orderModel = new \Model_ClientOrder();
|
|
$orderModel->loadBean(new \DummyBean());
|
|
|
|
$model = new \Model_ServiceHosting();
|
|
$model->loadBean(new \DummyBean());
|
|
|
|
$orderServiceMock = $this->createMock(\Box\Mod\Order\Service::class);
|
|
$orderServiceMock->expects($this->atLeastOnce())
|
|
->method('getOrderService')
|
|
->willReturn($model);
|
|
|
|
$dbMock = $this->createMock('\Box_Database');
|
|
$dbMock->expects($this->atLeastOnce())
|
|
->method('store');
|
|
|
|
$di = $this->getDi();
|
|
$di['db'] = $dbMock;
|
|
$di['mod_service'] = $di->protect(fn (): \PHPUnit\Framework\MockObject\MockObject => $orderServiceMock);
|
|
|
|
$serviceMock = $this->getMockBuilder(Service::class)
|
|
->onlyMethods(['_getAM'])
|
|
->getMock();
|
|
$serverManagerMock = $this->getMockBuilder('\Server_Manager_Custom')->disableOriginalConstructor()->getMock();
|
|
$serverManagerMock->expects($this->atLeastOnce())
|
|
->method('cancelAccount');
|
|
$AMresultArray = [$serverManagerMock, new \Server_Account()];
|
|
$serviceMock->expects($this->atLeastOnce())
|
|
->method('_getAM')
|
|
->willReturn($AMresultArray);
|
|
|
|
$serviceMock->setDi($di);
|
|
$result = $serviceMock->action_cancel($orderModel);
|
|
$this->assertTrue($result);
|
|
}
|
|
|
|
public function testActionCancelOrderWithoutActiveService(): void
|
|
{
|
|
$orderModel = new \Model_ClientOrder();
|
|
$orderModel->loadBean(new \DummyBean());
|
|
$orderModel->id = 1;
|
|
|
|
$orderServiceMock = $this->createMock(\Box\Mod\Order\Service::class);
|
|
$orderServiceMock->expects($this->atLeastOnce())
|
|
->method('getOrderService');
|
|
|
|
$di = $this->getDi();
|
|
$di['mod_service'] = $di->protect(fn (): \PHPUnit\Framework\MockObject\MockObject => $orderServiceMock);
|
|
|
|
$this->service->setDi($di);
|
|
$this->expectException(\FOSSBilling\Exception::class);
|
|
$this->expectExceptionMessage(sprintf('Order %d has no active service', $orderModel->id));
|
|
$this->service->action_cancel($orderModel);
|
|
}
|
|
|
|
// public function testAction_uncancel()
|
|
// {
|
|
// $orderModel = new \Model_ClientOrder();
|
|
// $orderModel->loadBean(new \DummyBean());
|
|
// $confArr = array(
|
|
// 'server_id' => 1,
|
|
// 'hosting_plan_id' => 2,
|
|
// 'sld' => 'great',
|
|
// 'tld' => 'com'
|
|
// );
|
|
// $orderServiceMock = $this->createMock(\Box\Mod\Order\Service::class);
|
|
// $orderServiceMock->expects($this->atLeastOnce())
|
|
// ->method('getConfig')
|
|
// ->will($this->returnValue($confArr));
|
|
//
|
|
// $model = new \Model_ServiceHosting();
|
|
// $model->loadBean(new \DummyBean());
|
|
// $orderServiceMock->expects($this->atLeastOnce())
|
|
// ->method('getOrderService')
|
|
// ->will($this->returnValue($model));
|
|
//
|
|
// $hostingServerModel = new \Model_ServiceHostingServer();
|
|
// $hostingServerModel->loadBean(new \DummyBean());
|
|
// $hostingPlansModel = new \Model_ServiceHostingHp();
|
|
// $hostingPlansModel->loadBean(new \DummyBean());
|
|
// $dbMock = $this->createMock('\Box_Database');
|
|
// $dbMock->expects($this->atLeastOnce())
|
|
// ->method('getExistingModelById')
|
|
// ->willReturn($hostingServerModel, $hostingPlansModel);
|
|
//
|
|
// $servhostingModel = new \Model_ServiceHosting();
|
|
// $servhostingModel->loadBean(new \DummyBean());
|
|
// $dbMock->expects($this->atLeastOnce())
|
|
// ->method('dispense')
|
|
// ->will($this->returnValue($servhostingModel));
|
|
//
|
|
// $newserviceHostingId = 4;
|
|
// $dbMock->expects($this->atLeastOnce())
|
|
// ->method('store')
|
|
// ->will($this->returnValue($newserviceHostingId));
|
|
//
|
|
// $di = $this->getDi();
|
|
// $di['db'] = $dbMock;
|
|
// $di['mod_service'] = $di->protect(fn() => $orderServiceMock);
|
|
//
|
|
//
|
|
//
|
|
// $serviceMock = $this->getMockBuilder(\Box\Mod\Servicehosting\Service::class)
|
|
// ->onlyMethods(array('_getAM'))
|
|
// ->getMock();
|
|
//
|
|
// $serverManagerMock = $this->getMockBuilder('\Server_Manager_Custom')->disableOriginalConstructor()->getMock();
|
|
// $serverManagerMock->expects($this->atLeastOnce())
|
|
// ->method('createAccount');
|
|
// $AMresultArray = array($serverManagerMock, new \Server_Account());
|
|
// $serviceMock->expects($this->atLeastOnce())
|
|
// ->method('_getAM')
|
|
// ->will($this->returnValue($AMresultArray));
|
|
//
|
|
//
|
|
// $serviceMock->setDi($di);
|
|
// $serviceMock->action_uncancel($orderModel);
|
|
// }
|
|
|
|
public function testActionDelete(): void
|
|
{
|
|
$orderModel = new \Model_ClientOrder();
|
|
$orderModel->loadBean(new \DummyBean());
|
|
$orderModel->status = 'active';
|
|
|
|
$model = new \Model_ServiceHosting();
|
|
$model->loadBean(new \DummyBean());
|
|
|
|
$orderServiceMock = $this->createMock(\Box\Mod\Order\Service::class);
|
|
$orderServiceMock->expects($this->atLeastOnce())
|
|
->method('getOrderService')
|
|
->willReturn($model);
|
|
|
|
$dbMock = $this->createMock('\Box_Database');
|
|
$dbMock->expects($this->atLeastOnce())
|
|
->method('trash');
|
|
|
|
$di = $this->getDi();
|
|
$di['db'] = $dbMock;
|
|
$di['mod_service'] = $di->protect(fn (): \PHPUnit\Framework\MockObject\MockObject => $orderServiceMock);
|
|
|
|
$serviceMock = $this->getMockBuilder(Service::class)
|
|
->onlyMethods(['action_cancel'])
|
|
->getMock();
|
|
$serviceMock->expects($this->atLeastOnce())
|
|
->method('action_cancel');
|
|
|
|
$serviceMock->setDi($di);
|
|
$serviceMock->action_delete($orderModel);
|
|
}
|
|
|
|
public function testChangeAccountPlan(): void
|
|
{
|
|
$orderModel = new \Model_ClientOrder();
|
|
$orderModel->loadBean(new \DummyBean());
|
|
|
|
$model = new \Model_ServiceHosting();
|
|
$model->loadBean(new \DummyBean());
|
|
|
|
$modelHp = new \Model_ServiceHostingHp();
|
|
$modelHp->loadBean(new \DummyBean());
|
|
|
|
$dbMock = $this->createMock('\Box_Database');
|
|
$dbMock->expects($this->atLeastOnce())
|
|
->method('store');
|
|
|
|
$di = $this->getDi();
|
|
$di['db'] = $dbMock;
|
|
$di['logger'] = new \Box_Log();
|
|
|
|
$serviceMock = $this->getMockBuilder(Service::class)
|
|
->onlyMethods(['_getAM', 'getServerPackage'])
|
|
->getMock();
|
|
$serverManagerMock = $this->getMockBuilder('\Server_Manager_Custom')->disableOriginalConstructor()->getMock();
|
|
$serverManagerMock->expects($this->atLeastOnce())
|
|
->method('changeAccountPackage');
|
|
$AMresultArray = [$serverManagerMock, new \Server_Account()];
|
|
$serviceMock->expects($this->atLeastOnce())
|
|
->method('_getAM')
|
|
->willReturn($AMresultArray);
|
|
$serviceMock->expects($this->atLeastOnce())
|
|
->method('getServerPackage')
|
|
->willReturn(new \Server_Package());
|
|
|
|
$serviceMock->setDi($di);
|
|
$result = $serviceMock->changeAccountPlan($orderModel, $model, $modelHp);
|
|
$this->assertTrue($result);
|
|
}
|
|
|
|
public function testChangeAccountUsername(): void
|
|
{
|
|
$data = [
|
|
'username' => 'u123456',
|
|
];
|
|
|
|
$orderModel = new \Model_ClientOrder();
|
|
$orderModel->loadBean(new \DummyBean());
|
|
|
|
$model = new \Model_ServiceHosting();
|
|
$model->loadBean(new \DummyBean());
|
|
|
|
$serviceMock = $this->getMockBuilder(Service::class)
|
|
->onlyMethods(['_getAM'])
|
|
->getMock();
|
|
|
|
$serverManagerMock = $this->getMockBuilder('\Server_Manager_Custom')->disableOriginalConstructor()->getMock();
|
|
$serverManagerMock->expects($this->atLeastOnce())
|
|
->method('changeAccountUsername');
|
|
|
|
$AMresultArray = [$serverManagerMock, new \Server_Account()];
|
|
$serviceMock->expects($this->atLeastOnce())
|
|
->method('_getAM')
|
|
->willReturn($AMresultArray);
|
|
|
|
$dbMock = $this->createMock('\Box_Database');
|
|
$dbMock->expects($this->atLeastOnce())
|
|
->method('store');
|
|
|
|
$di = $this->getDi();
|
|
$di['db'] = $dbMock;
|
|
$di['logger'] = new \Box_Log();
|
|
|
|
$serviceMock->setDi($di);
|
|
|
|
$result = $serviceMock->changeAccountUsername($orderModel, $model, $data);
|
|
$this->assertTrue($result);
|
|
}
|
|
|
|
public function testChangeAccountUsernameMissingUsername(): void
|
|
{
|
|
$orderModel = new \Model_ClientOrder();
|
|
$orderModel->loadBean(new \DummyBean());
|
|
|
|
$model = new \Model_ServiceHosting();
|
|
$model->loadBean(new \DummyBean());
|
|
$data = [];
|
|
|
|
$this->expectException(\FOSSBilling\Exception::class);
|
|
$this->expectExceptionMessage('Account username is missing or is invalid');
|
|
$this->service->changeAccountUsername($orderModel, $model, $data);
|
|
}
|
|
|
|
public function testChangeAccountIp(): void
|
|
{
|
|
$data = [
|
|
'ip' => '1.1.1.1',
|
|
];
|
|
|
|
$orderModel = new \Model_ClientOrder();
|
|
$orderModel->loadBean(new \DummyBean());
|
|
|
|
$model = new \Model_ServiceHosting();
|
|
$model->loadBean(new \DummyBean());
|
|
|
|
$serviceMock = $this->getMockBuilder(Service::class)
|
|
->onlyMethods(['_getAM'])
|
|
->getMock();
|
|
|
|
$serverManagerMock = $this->getMockBuilder('\Server_Manager_Custom')->disableOriginalConstructor()->getMock();
|
|
$serverManagerMock->expects($this->atLeastOnce())
|
|
->method('changeAccountIp');
|
|
|
|
$AMresultArray = [$serverManagerMock, new \Server_Account()];
|
|
$serviceMock->expects($this->atLeastOnce())
|
|
->method('_getAM')
|
|
->willReturn($AMresultArray);
|
|
|
|
$dbMock = $this->createMock('\Box_Database');
|
|
$dbMock->expects($this->atLeastOnce())
|
|
->method('store');
|
|
|
|
$di = $this->getDi();
|
|
$di['db'] = $dbMock;
|
|
$di['logger'] = new \Box_Log();
|
|
|
|
$serviceMock->setDi($di);
|
|
|
|
$result = $serviceMock->changeAccountIp($orderModel, $model, $data);
|
|
$this->assertTrue($result);
|
|
}
|
|
|
|
public function testChangeAccountIpMissingIp(): void
|
|
{
|
|
$data = [];
|
|
$orderModel = new \Model_ClientOrder();
|
|
$orderModel->loadBean(new \DummyBean());
|
|
|
|
$model = new \Model_ServiceHosting();
|
|
$model->loadBean(new \DummyBean());
|
|
|
|
$this->expectException(\FOSSBilling\Exception::class);
|
|
$this->expectExceptionMessage('Account IP address is missing or is invalid');
|
|
$this->service->changeAccountIp($orderModel, $model, $data);
|
|
}
|
|
|
|
public function testChangeAccountDomain(): void
|
|
{
|
|
$data = [
|
|
'tld' => 'com',
|
|
'sld' => 'testingSld',
|
|
];
|
|
|
|
$orderModel = new \Model_ClientOrder();
|
|
$orderModel->loadBean(new \DummyBean());
|
|
|
|
$model = new \Model_ServiceHosting();
|
|
$model->loadBean(new \DummyBean());
|
|
|
|
$serviceMock = $this->getMockBuilder(Service::class)
|
|
->onlyMethods(['_getAM'])
|
|
->getMock();
|
|
|
|
$serverManagerMock = $this->getMockBuilder('\Server_Manager_Custom')->disableOriginalConstructor()->getMock();
|
|
$serverManagerMock->expects($this->atLeastOnce())
|
|
->method('changeAccountDomain');
|
|
|
|
$AMresultArray = [$serverManagerMock, new \Server_Account()];
|
|
$serviceMock->expects($this->atLeastOnce())
|
|
->method('_getAM')
|
|
->willReturn($AMresultArray);
|
|
|
|
$dbMock = $this->createMock('\Box_Database');
|
|
$dbMock->expects($this->atLeastOnce())
|
|
->method('store');
|
|
|
|
$di = $this->getDi();
|
|
$di['db'] = $dbMock;
|
|
$di['logger'] = new \Box_Log();
|
|
|
|
$serviceMock->setDi($di);
|
|
|
|
$result = $serviceMock->changeAccountDomain($orderModel, $model, $data);
|
|
$this->assertTrue($result);
|
|
}
|
|
|
|
public function testChangeAccountDomainMissingParams(): void
|
|
{
|
|
$data = [];
|
|
$orderModel = new \Model_ClientOrder();
|
|
$orderModel->loadBean(new \DummyBean());
|
|
|
|
$model = new \Model_ServiceHosting();
|
|
$model->loadBean(new \DummyBean());
|
|
|
|
$this->expectException(\FOSSBilling\Exception::class);
|
|
$this->expectExceptionMessage('Domain SLD or TLD is missing');
|
|
$this->service->changeAccountDomain($orderModel, $model, $data);
|
|
}
|
|
|
|
public function testChangeAccountPassword(): void
|
|
{
|
|
$data = [
|
|
'password' => 'topsecret',
|
|
'password_confirm' => 'topsecret',
|
|
];
|
|
|
|
$orderModel = new \Model_ClientOrder();
|
|
$orderModel->loadBean(new \DummyBean());
|
|
|
|
$model = new \Model_ServiceHosting();
|
|
$model->loadBean(new \DummyBean());
|
|
|
|
$serviceMock = $this->getMockBuilder(Service::class)
|
|
->onlyMethods(['_getAM'])
|
|
->getMock();
|
|
|
|
$serverManagerMock = $this->getMockBuilder('\Server_Manager_Custom')->disableOriginalConstructor()->getMock();
|
|
$serverManagerMock->expects($this->atLeastOnce())
|
|
->method('changeAccountPassword');
|
|
|
|
$AMresultArray = [$serverManagerMock, new \Server_Account()];
|
|
$serviceMock->expects($this->atLeastOnce())
|
|
->method('_getAM')
|
|
->willReturn($AMresultArray);
|
|
|
|
$dbMock = $this->createMock('\Box_Database');
|
|
$dbMock->expects($this->atLeastOnce())
|
|
->method('store');
|
|
|
|
$di = $this->getDi();
|
|
$di['db'] = $dbMock;
|
|
$di['logger'] = new \Box_Log();
|
|
|
|
$serviceMock->setDi($di);
|
|
|
|
$result = $serviceMock->changeAccountPassword($orderModel, $model, $data);
|
|
$this->assertTrue($result);
|
|
}
|
|
|
|
public function testChangeAccountPasswordMissingParams(): void
|
|
{
|
|
$data = [];
|
|
$orderModel = new \Model_ClientOrder();
|
|
$orderModel->loadBean(new \DummyBean());
|
|
|
|
$model = new \Model_ServiceHosting();
|
|
$model->loadBean(new \DummyBean());
|
|
|
|
$this->expectException(\FOSSBilling\Exception::class);
|
|
$this->expectExceptionMessage('Account password is missing or is invalid');
|
|
$this->service->changeAccountPassword($orderModel, $model, $data);
|
|
}
|
|
|
|
public function testSync(): void
|
|
{
|
|
$data = [
|
|
'password' => 'topsecret',
|
|
'password_confirm' => 'topsecret',
|
|
];
|
|
|
|
$orderModel = new \Model_ClientOrder();
|
|
$orderModel->loadBean(new \DummyBean());
|
|
|
|
$model = new \Model_ServiceHosting();
|
|
$model->loadBean(new \DummyBean());
|
|
|
|
$serviceMock = $this->getMockBuilder(Service::class)
|
|
->onlyMethods(['_getAM'])
|
|
->getMock();
|
|
|
|
$accountObj = new \Server_Account();
|
|
$accountObj->setUsername('testUser1');
|
|
$accountObj->setIp('1.1.1.1');
|
|
|
|
$accountObj2 = new \Server_Account();
|
|
$accountObj2->setUsername('testUser2');
|
|
$accountObj2->setIp('2.2.2.2');
|
|
|
|
$serverManagerMock = $this->getMockBuilder('\Server_Manager_Custom')->disableOriginalConstructor()->getMock();
|
|
$serverManagerMock->expects($this->atLeastOnce())
|
|
->method('synchronizeAccount')
|
|
->willReturn($accountObj2);
|
|
|
|
$AMresultArray = [$serverManagerMock, $accountObj];
|
|
$serviceMock->expects($this->atLeastOnce())
|
|
->method('_getAM')
|
|
->willReturn($AMresultArray);
|
|
|
|
$dbMock = $this->createMock('\Box_Database');
|
|
$dbMock->expects($this->atLeastOnce())
|
|
->method('store');
|
|
|
|
$di = $this->getDi();
|
|
$di['db'] = $dbMock;
|
|
$di['logger'] = new \Box_Log();
|
|
|
|
$serviceMock->setDi($di);
|
|
|
|
$result = $serviceMock->sync($orderModel, $model, $data);
|
|
$this->assertTrue($result);
|
|
}
|
|
|
|
public function testToApiArray(): void
|
|
{
|
|
$model = new \Model_ServiceHosting();
|
|
$model->loadBean(new \DummyBean());
|
|
|
|
$hostingServer = new \Model_ServiceHostingServer();
|
|
$hostingServer->loadBean(new \DummyBean());
|
|
$hostingServer->manager = 'Custom';
|
|
$hostingHp = new \Model_ServiceHostingHp();
|
|
$hostingHp->loadBean(new \DummyBean());
|
|
|
|
$dbMock = $this->createMock('\Box_Database');
|
|
$dbMock->expects($this->atLeastOnce())
|
|
->method('load')
|
|
->willReturnOnConsecutiveCalls($hostingServer, $hostingHp);
|
|
|
|
$orderServiceMock = $this->createMock(\Box\Mod\Order\Service::class);
|
|
$orderServiceMock->expects($this->atLeastOnce())
|
|
->method('getServiceOrder');
|
|
|
|
$serverManagerCustomMock = $this->getMockBuilder('\Server_Manager_Custom')->disableOriginalConstructor()->getMock();
|
|
|
|
$di = $this->getDi();
|
|
$di['db'] = $dbMock;
|
|
$di['mod_service'] = $di->protect(fn (): \PHPUnit\Framework\MockObject\MockObject => $orderServiceMock);
|
|
$di['server_manager'] = $di->protect(fn ($manager, $config): \PHPUnit\Framework\MockObject\MockObject => $serverManagerCustomMock);
|
|
|
|
$this->service->setDi($di);
|
|
|
|
$result = $this->service->toApiArray($model, false, new \Model_Admin());
|
|
$this->assertIsArray($result);
|
|
}
|
|
|
|
public function testUpdate(): void
|
|
{
|
|
$data = [
|
|
'username' => 'testUser',
|
|
'ip' => '1.1.1.1',
|
|
];
|
|
$model = new \Model_ServiceHosting();
|
|
$model->loadBean(new \DummyBean());
|
|
|
|
$dbMock = $this->createMock('\Box_Database');
|
|
$dbMock->expects($this->atLeastOnce())
|
|
->method('store');
|
|
|
|
$di = $this->getDi();
|
|
$di['db'] = $dbMock;
|
|
$di['logger'] = new \Box_Log();
|
|
$this->service->setDi($di);
|
|
|
|
$result = $this->service->update($model, $data);
|
|
$this->assertTrue($result);
|
|
}
|
|
|
|
public function testGetServerManagers(): void
|
|
{
|
|
$result = $this->service->getServerManagers();
|
|
$this->assertIsArray($result);
|
|
}
|
|
|
|
public function testGetServerManagerConfig(): void
|
|
{
|
|
$manager = 'Custom';
|
|
|
|
$expected = [
|
|
'label' => 'Custom Server Manager',
|
|
];
|
|
|
|
$result = $this->service->getServerManagerConfig($manager);
|
|
$this->assertIsArray($result);
|
|
$this->assertEquals($expected, $result);
|
|
}
|
|
|
|
public function testGetServerPairs(): void
|
|
{
|
|
$expected = [
|
|
'1' => 'name',
|
|
'2' => 'ding',
|
|
];
|
|
|
|
$queryResult = [
|
|
[
|
|
'id' => 1,
|
|
'name' => 'name',
|
|
], [
|
|
'id' => 2,
|
|
'name' => 'ding',
|
|
],
|
|
];
|
|
|
|
$dbMock = $this->createMock('\Box_Database');
|
|
$dbMock->expects($this->atLeastOnce())
|
|
->method('getAll')
|
|
->willReturn($queryResult);
|
|
|
|
$di = $this->getDi();
|
|
$di['db'] = $dbMock;
|
|
$this->service->setDi($di);
|
|
|
|
$result = $this->service->getServerPairs();
|
|
$this->assertIsArray($result);
|
|
$this->assertEquals($expected, $result);
|
|
}
|
|
|
|
public function testGetServerSearchQuery(): void
|
|
{
|
|
$result = $this->service->getServersSearchQuery([]);
|
|
$this->assertIsString($result[0]);
|
|
$this->assertIsArray($result[1]);
|
|
$this->assertSame([], $result[1]);
|
|
}
|
|
|
|
public function testCreateServer(): void
|
|
{
|
|
$dbMock = $this->createMock('\Box_Database');
|
|
|
|
$hostingServerModel = new \Model_ServiceHostingServer();
|
|
$hostingServerModel->loadBean(new \DummyBean());
|
|
$dbMock->expects($this->atLeastOnce())
|
|
->method('dispense')
|
|
->willReturn($hostingServerModel);
|
|
|
|
$newId = 1;
|
|
$dbMock->expects($this->atLeastOnce())
|
|
->method('store')
|
|
->willReturn($newId);
|
|
|
|
$di = $this->getDi();
|
|
$di['db'] = $dbMock;
|
|
$di['logger'] = new \Box_Log();
|
|
|
|
$this->service->setDi($di);
|
|
|
|
$name = 'newSuperFastServer';
|
|
$ip = '1.1.1.1';
|
|
$manager = 'Custom';
|
|
$data = [];
|
|
$result = $this->service->createServer($name, $ip, $manager, $data);
|
|
$this->assertIsInt($result);
|
|
$this->assertEquals($newId, $result);
|
|
}
|
|
|
|
public function testDeleteServer(): void
|
|
{
|
|
$hostingServerModel = new \Model_ServiceHostingServer();
|
|
$hostingServerModel->loadBean(new \DummyBean());
|
|
|
|
$dbMock = $this->createMock('\Box_Database');
|
|
$dbMock->expects($this->atLeastOnce())
|
|
->method('trash');
|
|
|
|
$di = $this->getDi();
|
|
$di['db'] = $dbMock;
|
|
$di['logger'] = new \Box_Log();
|
|
$this->service->setDi($di);
|
|
|
|
$result = $this->service->deleteServer($hostingServerModel);
|
|
$this->assertTrue($result);
|
|
}
|
|
|
|
public function testUpdateServer(): void
|
|
{
|
|
$data = [
|
|
'name' => 'newName',
|
|
'ip' => '1.1.1.1',
|
|
'hostname' => 'unknownStar',
|
|
'active' => 1,
|
|
'status_url' => 'na',
|
|
'ns1' => 'ns1.testserver.eu',
|
|
'ns2' => 'ns2.testserver.eu',
|
|
'ns3' => 'ns3.testserver.eu',
|
|
'ns4' => 'ns4.testserver.eu',
|
|
'manager' => 'Custom',
|
|
'username' => 'testingJohn',
|
|
'password' => 'hardToGuess',
|
|
'accesshash' => 'secret',
|
|
'port' => '23',
|
|
'secure' => 0,
|
|
];
|
|
|
|
$hostingServerModel = new \Model_ServiceHostingServer();
|
|
$hostingServerModel->loadBean(new \DummyBean());
|
|
|
|
$dbMock = $this->createMock('\Box_Database');
|
|
$dbMock->expects($this->atLeastOnce())
|
|
->method('store');
|
|
|
|
$di = $this->getDi();
|
|
$di['db'] = $dbMock;
|
|
$di['logger'] = new \Box_Log();
|
|
|
|
$this->service->setDi($di);
|
|
|
|
$result = $this->service->updateServer($hostingServerModel, $data);
|
|
$this->assertTrue($result);
|
|
}
|
|
|
|
public function testGetServerManager(): void
|
|
{
|
|
$hostingServerModel = new \Model_ServiceHostingServer();
|
|
$hostingServerModel->loadBean(new \DummyBean());
|
|
$hostingServerModel->manager = 'Custom';
|
|
|
|
$serverManagerCustom = $this->getMockBuilder('\Server_Manager_Custom')->disableOriginalConstructor()->getMock();
|
|
|
|
$di = $this->getDi();
|
|
$di['server_manager'] = $di->protect(fn ($manager, $config): \PHPUnit\Framework\MockObject\MockObject => $serverManagerCustom);
|
|
$this->service->setDi($di);
|
|
|
|
$result = $this->service->getServerManager($hostingServerModel);
|
|
$this->assertInstanceOf('\Server_Manager_Custom', $result);
|
|
}
|
|
|
|
public function testGetServerManagerManagerNotDefined(): void
|
|
{
|
|
$hostingServerModel = new \Model_ServiceHostingServer();
|
|
$hostingServerModel->loadBean(new \DummyBean());
|
|
|
|
$this->expectException(\FOSSBilling\Exception::class);
|
|
$this->expectExceptionCode(654);
|
|
$this->expectExceptionMessage('Invalid server manager. Server was not configured properly');
|
|
$this->service->getServerManager($hostingServerModel);
|
|
}
|
|
|
|
public function testGetServerManagerServerManagerInvalid(): void
|
|
{
|
|
$hostingServerModel = new \Model_ServiceHostingServer();
|
|
$hostingServerModel->loadBean(new \DummyBean());
|
|
$hostingServerModel->manager = 'Custom';
|
|
|
|
$di = $this->getDi();
|
|
$di['server_manager'] = $di->protect(fn ($manager, $config): null => null);
|
|
$this->service->setDi($di);
|
|
|
|
$this->expectException(\FOSSBilling\Exception::class);
|
|
$this->expectExceptionMessage("Server manager {$hostingServerModel->manager} is invalid.");
|
|
$this->service->getServerManager($hostingServerModel);
|
|
}
|
|
|
|
public function testTestConnection(): void
|
|
{
|
|
$serverManagerMock = $this->getMockBuilder('\Server_Manager_Custom')->disableOriginalConstructor()->getMock();
|
|
$serverManagerMock->expects($this->atLeastOnce())
|
|
->method('testConnection')
|
|
->willReturn(true);
|
|
|
|
$serviceMock = $this->getMockBuilder(Service::class)
|
|
->onlyMethods(['getServerManager'])
|
|
->getMock();
|
|
|
|
$serviceMock->expects($this->atLeastOnce())
|
|
->method('getServerManager')
|
|
->willReturn($serverManagerMock);
|
|
|
|
$hostingServerModel = new \Model_ServiceHostingServer();
|
|
$result = $serviceMock->testConnection($hostingServerModel);
|
|
$this->assertIsBool($result);
|
|
$this->assertTrue($result);
|
|
}
|
|
|
|
public function testGetHpPairs(): void
|
|
{
|
|
$expected = [
|
|
'1' => 'free',
|
|
'2' => 'paid',
|
|
];
|
|
|
|
$queryResult = [
|
|
[
|
|
'id' => 1,
|
|
'name' => 'free',
|
|
], [
|
|
'id' => 2,
|
|
'name' => 'paid',
|
|
],
|
|
];
|
|
|
|
$dbMock = $this->createMock('\Box_Database');
|
|
$dbMock->expects($this->atLeastOnce())
|
|
->method('getAll')
|
|
->willReturn($queryResult);
|
|
|
|
$di = $this->getDi();
|
|
$di['db'] = $dbMock;
|
|
$this->service->setDi($di);
|
|
|
|
$result = $this->service->getHpPairs();
|
|
$this->assertIsArray($result);
|
|
$this->assertEquals($expected, $result);
|
|
}
|
|
|
|
public function testGetHpSearchQuery(): void
|
|
{
|
|
$result = $this->service->getServersSearchQuery([]);
|
|
$this->assertIsString($result[0]);
|
|
$this->assertIsArray($result[1]);
|
|
$this->assertSame([], $result[1]);
|
|
}
|
|
|
|
public function testDeleteHp(): void
|
|
{
|
|
$model = new \Model_ServiceHostingHp();
|
|
$model->loadBean(new \DummyBean());
|
|
|
|
$dbMock = $this->createMock('\Box_Database');
|
|
$dbMock->expects($this->atLeastOnce())
|
|
->method('trash');
|
|
|
|
$di = $this->getDi();
|
|
$di['db'] = $dbMock;
|
|
$di['logger'] = new \Box_Log();
|
|
$this->service->setDi($di);
|
|
|
|
$result = $this->service->deleteHp($model);
|
|
$this->assertTrue($result);
|
|
}
|
|
|
|
public function testToHostingHpApiArray(): void
|
|
{
|
|
$model = new \Model_ServiceHostingHp();
|
|
$model->loadBean(new \DummyBean());
|
|
|
|
$result = $this->service->toHostingHpApiArray($model);
|
|
$this->assertIsArray($result);
|
|
}
|
|
|
|
public function testUpdateHp(): void
|
|
{
|
|
$data = [
|
|
'name' => 'firstPlan',
|
|
'bandwidth' => '100000',
|
|
'quota' => '1000',
|
|
'max_addon' => '0',
|
|
'max_ft' => '1',
|
|
'max_sql' => '2',
|
|
'max_pop' => '1',
|
|
'max_sub' => '2',
|
|
'max_park' => '1',
|
|
];
|
|
|
|
$model = new \Model_ServiceHostingHp();
|
|
$model->loadBean(new \DummyBean());
|
|
|
|
$dbMock = $this->createMock('\Box_Database');
|
|
$dbMock->expects($this->atLeastOnce())
|
|
->method('store');
|
|
|
|
$di = $this->getDi();
|
|
$di['db'] = $dbMock;
|
|
$di['logger'] = new \Box_Log();
|
|
|
|
$this->service->setDi($di);
|
|
|
|
$result = $this->service->updateHp($model, $data);
|
|
$this->assertTrue($result);
|
|
}
|
|
|
|
public function testCreateHp(): void
|
|
{
|
|
$model = new \Model_ServiceHostingHp();
|
|
$model->loadBean(new \DummyBean());
|
|
$newId = 1;
|
|
|
|
$dbMock = $this->createMock('\Box_Database');
|
|
$dbMock->expects($this->atLeastOnce())
|
|
->method('dispense')->willReturn($model);
|
|
$dbMock->expects($this->atLeastOnce())
|
|
->method('store')->willReturn($newId);
|
|
|
|
$di = $this->getDi();
|
|
$di['db'] = $dbMock;
|
|
$di['logger'] = new \Box_Log();
|
|
|
|
$this->service->setDi($di);
|
|
|
|
$result = $this->service->createHp('Free Plan', []);
|
|
$this->assertIsInt($result);
|
|
$this->assertEquals($newId, $result);
|
|
}
|
|
|
|
public function testGetServerPackage(): void
|
|
{
|
|
$model = new \Model_ServiceHostingHp();
|
|
$model->loadBean(new \DummyBean());
|
|
$model->config = '{}';
|
|
|
|
$di = $this->getDi();
|
|
|
|
$this->service->setDi($di);
|
|
$result = $this->service->getServerPackage($model);
|
|
$this->assertInstanceOf('\Server_Package', $result);
|
|
}
|
|
|
|
public function testGetServerManagerWithLog(): void
|
|
{
|
|
$hostingServerModel = new \Model_ServiceHostingServer();
|
|
$hostingServerModel->loadBean(new \DummyBean());
|
|
$hostingServerModel->manager = 'Custom';
|
|
|
|
$clientOrderModel = new \Model_ClientOrder();
|
|
$clientOrderModel->loadBean(new \DummyBean());
|
|
|
|
$serverManagerMock = $this->getMockBuilder('\Server_Manager_Custom')->disableOriginalConstructor()->getMock();
|
|
$serviceMock = $this->getMockBuilder(Service::class)
|
|
->onlyMethods(['getServerManager'])
|
|
->getMock();
|
|
$serviceMock->expects($this->atLeastOnce())
|
|
->method('getServerManager')
|
|
->willReturn($serverManagerMock);
|
|
|
|
$orderServiceMock = $this->createMock(\Box\Mod\Order\Service::class);
|
|
$orderServiceMock->expects($this->atLeastOnce())
|
|
->method('getLogger')
|
|
->willReturn(new \Box_Log());
|
|
|
|
$di = $this->getDi();
|
|
$di['mod_service'] = $di->protect(fn (): \PHPUnit\Framework\MockObject\MockObject => $orderServiceMock);
|
|
|
|
$serviceMock->setDi($di);
|
|
$result = $serviceMock->getServerManagerWithLog($hostingServerModel, $clientOrderModel);
|
|
$this->assertInstanceOf('\Server_Manager_Custom', $result);
|
|
}
|
|
|
|
public function testGetManagerUrls(): void
|
|
{
|
|
$hostingServerModel = new \Model_ServiceHostingServer();
|
|
$hostingServerModel->loadBean(new \DummyBean());
|
|
$hostingServerModel->manager = 'Custom';
|
|
|
|
$serverManagerMock = $this->getMockBuilder('\Server_Manager_Custom')->disableOriginalConstructor()->getMock();
|
|
$serverManagerMock->expects($this->atLeastOnce())
|
|
->method('getLoginUrl')
|
|
->willReturn('/login');
|
|
$serverManagerMock->expects($this->atLeastOnce())
|
|
->method('getResellerLoginUrl')
|
|
->willReturn('/admin/login');
|
|
|
|
$serviceMock = $this->getMockBuilder(Service::class)
|
|
->onlyMethods(['getServerManager'])
|
|
->getMock();
|
|
$serviceMock->expects($this->atLeastOnce())
|
|
->method('getServerManager')
|
|
->willReturn($serverManagerMock);
|
|
|
|
$result = $serviceMock->getManagerUrls($hostingServerModel);
|
|
$this->assertIsArray($result);
|
|
$this->assertIsString($result[0]);
|
|
$this->assertIsString($result[1]);
|
|
}
|
|
|
|
public function testGetManagerUrlsException(): void
|
|
{
|
|
$hostingServerModel = new \Model_ServiceHostingServer();
|
|
$hostingServerModel->loadBean(new \DummyBean());
|
|
$hostingServerModel->manager = 'Custom';
|
|
|
|
$serviceMock = $this->getMockBuilder(Service::class)
|
|
->onlyMethods(['getServerManager'])
|
|
->getMock();
|
|
$serviceMock->expects($this->atLeastOnce())
|
|
->method('getServerManager')
|
|
->will($this->throwException(new \Exception('Controlled unit test exception')));
|
|
|
|
$result = $serviceMock->getManagerUrls($hostingServerModel);
|
|
$this->assertIsArray($result);
|
|
$this->assertFalse($result[0]);
|
|
$this->assertFalse($result[1]);
|
|
}
|
|
|
|
public function testGetFreeTldsFreeTldsAreNotSet(): void
|
|
{
|
|
$di = $this->getDi();
|
|
|
|
$tldArray = ['tld' => '.com'];
|
|
$serviceDomainServiceMock = $this->createMock(\Box\Mod\Servicedomain\Service::class);
|
|
$serviceDomainServiceMock->expects($this->atLeastOnce())
|
|
->method('tldToApiArray')
|
|
->willReturn($tldArray);
|
|
$di['mod_service'] = $di->protect(fn (): \PHPUnit\Framework\MockObject\MockObject => $serviceDomainServiceMock);
|
|
|
|
$tldModel = new \Model_Tld();
|
|
$tldModel->loadBean(new \DummyBean());
|
|
|
|
$dbMock = $this->createMock('\Box_Database');
|
|
$dbMock->expects($this->atLeastOnce())
|
|
->method('find')
|
|
->willReturn([$tldModel]);
|
|
$di['db'] = $dbMock;
|
|
|
|
$this->service->setDi($di);
|
|
$model = new \Model_Product();
|
|
$model->loadBean(new \DummyBean());
|
|
$result = $this->service->getFreeTlds($model);
|
|
$this->assertIsArray($result);
|
|
}
|
|
|
|
public function testGetFreeTlds(): void
|
|
{
|
|
$config = [
|
|
'free_tlds' => ['.com'],
|
|
];
|
|
$di = $this->getDi();
|
|
|
|
$this->service->setDi($di);
|
|
$model = new \Model_Product();
|
|
$model->loadBean(new \DummyBean());
|
|
$model->config = json_encode($config);
|
|
|
|
$result = $this->service->getFreeTlds($model);
|
|
$this->assertIsArray($result);
|
|
$this->assertNotEmpty($result);
|
|
}
|
|
}
|