mirror of
https://github.com/FOSSBilling/FOSSBilling.git
synced 2026-12-01 04:40:45 +09:00
* Began implementing Sentry.io support * Added to the installer * Added the ID to the bug report template and UI * Hook it into our error handler, added the ability to filter by error code * Attempting to add the DSN via GH actions * Spelling and making PHPstan happy * Skip exceptions for various incomplete configurations Also brings in some of the category suggestions made by @Anuril in #195 * Update tests to account for changes * Added & renamed exception classes * Fix tests * Change a bunch of items to be InformationExceptions * Use a lighter HTTP client, fixed API error reporting * I guess that's not needed now? Arighty then * Improvements, additional info added * Update SentryHelper.php * Improved error logging, added instance ID to error page Also made it so that errors are correctly sent to Sentry rather than exclusively exceptions * Make the tests happy * Added the link, improved wording Also removed the "performance" part of the reporting as it needs to be added to the front-end and I'm not currently implementing that * Began implementing UI alerts and info * Added the ability to toggle, fixed tests, use path constants * Added some useful info & links to the page * These should be InformationException * Fix the automated Sentry DSN entry * Fix the install number text * Minor cleanup, converted more to InformationException * Replaced some direct config references with constants We have the BB_DEBUG constant to indicate if we have debug mode enabled or not, so we shouldn't be directly referencing it in the config file unless we actually need to do so. Using the constant means there's less locations to update the reference if the config structure is changed * Bugfix * Consistency & fixed a PHPDoc * Corrections * We actually do want exceptions thrown here * Change how we get the instance ID * Stability improvements Having support for translatable error pages was proving to be problematic, so I had to remove it. I also had to update the exception class to handle cases where the trans function wasn't setup yet (needed for the /run-patcher page if an error occurs) * Missed this change on git * Also fix the variable names... * Re-added new deps after rebase * This should also accept "Error" types * Added more info to the bug report and removed a dug line * This wasn't supposed to get renamed * Updated some missed references to Box_Exception
703 lines
24 KiB
PHP
703 lines
24 KiB
PHP
<?php
|
|
|
|
|
|
namespace Box\Mod\Servicehosting\Api;
|
|
|
|
|
|
class AdminTest extends \BBTestCase
|
|
{
|
|
|
|
/**
|
|
* @var \Box\Mod\Servicehosting\Api\Admin
|
|
*/
|
|
protected $api = null;
|
|
|
|
public function setup(): void
|
|
{
|
|
$this->api = new \Box\Mod\Servicehosting\Api\Admin();
|
|
}
|
|
|
|
public function testgetDi()
|
|
{
|
|
$di = new \Pimple\Container();
|
|
$this->api->setDi($di);
|
|
$getDi = $this->api->getDi();
|
|
$this->assertEquals($di, $getDi);
|
|
}
|
|
|
|
public function testchange_plan()
|
|
{
|
|
$data = array(
|
|
'plan_id' => 1,
|
|
);
|
|
|
|
$getServiceReturnValue = array(new \Model_ClientOrder(), new \Model_ServiceHosting);
|
|
$apiMock = $this->getMockBuilder('\Box\Mod\Servicehosting\Api\Admin')
|
|
->setMethods(array('_getService'))
|
|
->getMock();
|
|
|
|
$apiMock->expects($this->atLeastOnce())
|
|
->method('_getService')
|
|
->will($this->returnValue($getServiceReturnValue));
|
|
|
|
$serviceMock = $this->getMockBuilder('\Box\Mod\Servicehosting\Service')->getMock();
|
|
$serviceMock->expects($this->atLeastOnce())
|
|
->method('changeAccountPlan')
|
|
->will($this->returnValue(true));
|
|
|
|
$dbMock = $this->getMockBuilder('\Box_Database')->getMock();
|
|
$dbMock->expects($this->atLeastOnce())
|
|
->method('getExistingModelById')
|
|
->will($this->returnValue(new \Model_ServiceHostingHp));
|
|
|
|
$di = new \Pimple\Container();
|
|
$di['db'] = $dbMock;
|
|
|
|
$apiMock->setDi($di);
|
|
$apiMock->setService($serviceMock);
|
|
|
|
$result = $apiMock->change_plan($data);
|
|
$this->assertIsBool($result);
|
|
$this->assertTrue($result);
|
|
}
|
|
|
|
public function testchange_planMissingPlanId()
|
|
{
|
|
$data = array();
|
|
|
|
$this->expectException(\FOSSBilling\Exception::class);
|
|
$this->expectExceptionMessage('plan_id is missing');
|
|
$this->api->change_plan($data);
|
|
}
|
|
|
|
public function testchange_username()
|
|
{
|
|
$getServiceReturnValue = array(new \Model_ClientOrder(), new \Model_ServiceHosting);
|
|
$apiMock = $this->getMockBuilder('\Box\Mod\Servicehosting\Api\Admin')
|
|
->setMethods(array('_getService'))
|
|
->getMock();
|
|
|
|
$apiMock->expects($this->atLeastOnce())
|
|
->method('_getService')
|
|
->will($this->returnValue($getServiceReturnValue));
|
|
|
|
$serviceMock = $this->getMockBuilder('\Box\Mod\Servicehosting\Service')->getMock();
|
|
$serviceMock->expects($this->atLeastOnce())
|
|
->method('changeAccountUsername')
|
|
->will($this->returnValue(true));
|
|
|
|
$apiMock->setService($serviceMock);
|
|
|
|
$result = $apiMock->change_username(array());
|
|
$this->assertIsBool($result);
|
|
$this->assertTrue($result);
|
|
}
|
|
|
|
public function testchange_ip()
|
|
{
|
|
$getServiceReturnValue = array(new \Model_ClientOrder(), new \Model_ServiceHosting);
|
|
$apiMock = $this->getMockBuilder('\Box\Mod\Servicehosting\Api\Admin')
|
|
->setMethods(array('_getService'))
|
|
->getMock();
|
|
|
|
$apiMock->expects($this->atLeastOnce())
|
|
->method('_getService')
|
|
->will($this->returnValue($getServiceReturnValue));
|
|
|
|
$serviceMock = $this->getMockBuilder('\Box\Mod\Servicehosting\Service')->getMock();
|
|
$serviceMock->expects($this->atLeastOnce())
|
|
->method('changeAccountIp')
|
|
->will($this->returnValue(true));
|
|
|
|
$apiMock->setService($serviceMock);
|
|
|
|
$result = $apiMock->change_ip(array());
|
|
$this->assertIsBool($result);
|
|
$this->assertTrue($result);
|
|
}
|
|
|
|
public function testchange_domain()
|
|
{
|
|
$getServiceReturnValue = array(new \Model_ClientOrder(), new \Model_ServiceHosting);
|
|
$apiMock = $this->getMockBuilder('\Box\Mod\Servicehosting\Api\Admin')
|
|
->setMethods(array('_getService'))
|
|
->getMock();
|
|
|
|
$apiMock->expects($this->atLeastOnce())
|
|
->method('_getService')
|
|
->will($this->returnValue($getServiceReturnValue));
|
|
|
|
$serviceMock = $this->getMockBuilder('\Box\Mod\Servicehosting\Service')->getMock();
|
|
$serviceMock->expects($this->atLeastOnce())
|
|
->method('changeAccountDomain')
|
|
->will($this->returnValue(true));
|
|
|
|
$apiMock->setService($serviceMock);
|
|
|
|
$result = $apiMock->change_domain(array());
|
|
$this->assertIsBool($result);
|
|
$this->assertTrue($result);
|
|
}
|
|
|
|
public function testchange_password()
|
|
{
|
|
$getServiceReturnValue = array(new \Model_ClientOrder(), new \Model_ServiceHosting);
|
|
$apiMock = $this->getMockBuilder('\Box\Mod\Servicehosting\Api\Admin')
|
|
->setMethods(array('_getService'))
|
|
->getMock();
|
|
|
|
$apiMock->expects($this->atLeastOnce())
|
|
->method('_getService')
|
|
->will($this->returnValue($getServiceReturnValue));
|
|
|
|
$serviceMock = $this->getMockBuilder('\Box\Mod\Servicehosting\Service')->getMock();
|
|
$serviceMock->expects($this->atLeastOnce())
|
|
->method('changeAccountPassword')
|
|
->will($this->returnValue(true));
|
|
|
|
$apiMock->setService($serviceMock);
|
|
|
|
$result = $apiMock->change_password(array());
|
|
$this->assertIsBool($result);
|
|
$this->assertTrue($result);
|
|
}
|
|
|
|
public function testsync()
|
|
{
|
|
$getServiceReturnValue = array(new \Model_ClientOrder(), new \Model_ServiceHosting);
|
|
$apiMock = $this->getMockBuilder('\Box\Mod\Servicehosting\Api\Admin')
|
|
->setMethods(array('_getService'))
|
|
->getMock();
|
|
|
|
$apiMock->expects($this->atLeastOnce())
|
|
->method('_getService')
|
|
->will($this->returnValue($getServiceReturnValue));
|
|
|
|
$serviceMock = $this->getMockBuilder('\Box\Mod\Servicehosting\Service')->getMock();
|
|
$serviceMock->expects($this->atLeastOnce())
|
|
->method('sync')
|
|
->will($this->returnValue(true));
|
|
|
|
$apiMock->setService($serviceMock);
|
|
|
|
$result = $apiMock->sync(array());
|
|
$this->assertIsBool($result);
|
|
$this->assertTrue($result);
|
|
}
|
|
|
|
public function testupdate()
|
|
{
|
|
$getServiceReturnValue = array(new \Model_ClientOrder(), new \Model_ServiceHosting);
|
|
$apiMock = $this->getMockBuilder('\Box\Mod\Servicehosting\Api\Admin')
|
|
->setMethods(array('_getService'))
|
|
->getMock();
|
|
|
|
$apiMock->expects($this->atLeastOnce())
|
|
->method('_getService')
|
|
->will($this->returnValue($getServiceReturnValue));
|
|
|
|
$serviceMock = $this->getMockBuilder('\Box\Mod\Servicehosting\Service')->getMock();
|
|
$serviceMock->expects($this->atLeastOnce())
|
|
->method('update')
|
|
->will($this->returnValue(true));
|
|
|
|
$apiMock->setService($serviceMock);
|
|
|
|
$result = $apiMock->update(array());
|
|
$this->assertIsBool($result);
|
|
$this->assertTrue($result);
|
|
}
|
|
|
|
public function testmanager_get_pairs()
|
|
{
|
|
$serviceMock = $this->getMockBuilder('\Box\Mod\Servicehosting\Service')->getMock();
|
|
$serviceMock->expects($this->atLeastOnce())
|
|
->method('getServerManagers')
|
|
->will($this->returnValue(array()));
|
|
|
|
$this->api->setService($serviceMock);
|
|
|
|
$result = $this->api->manager_get_pairs(array());
|
|
$this->assertIsArray($result);
|
|
}
|
|
|
|
public function testserver_get_pairs()
|
|
{
|
|
$serviceMock = $this->getMockBuilder('\Box\Mod\Servicehosting\Service')->getMock();
|
|
$serviceMock->expects($this->atLeastOnce())
|
|
->method('getServerPairs')
|
|
->will($this->returnValue(array()));
|
|
|
|
$this->api->setService($serviceMock);
|
|
|
|
$result = $this->api->server_get_pairs(array());
|
|
$this->assertIsArray($result);
|
|
}
|
|
|
|
public function testserver_get_list()
|
|
{
|
|
$serviceMock = $this->getMockBuilder('\Box\Mod\Servicehosting\Service')->getMock();
|
|
$serviceMock->expects($this->atLeastOnce())
|
|
->method('getServersSearchQuery')
|
|
->will($this->returnValue(array('SQLstring', array())));
|
|
|
|
$pagerMock = $this->getMockBuilder('\Box_Pagination')->getMock();
|
|
$pagerMock->expects($this->atLeastOnce())
|
|
->method('getSimpleResultSet')
|
|
->will($this->returnValue(array('list' => array())));
|
|
|
|
$dbMock = $this->getMockBuilder('\Box_Database')->getMock();
|
|
$dbMock->expects($this->atLeastOnce())
|
|
->method('find')
|
|
->will($this->returnValue(array()));
|
|
|
|
$di = new \Pimple\Container();
|
|
$di['pager'] = $pagerMock;
|
|
$di['db'] = $dbMock;
|
|
|
|
|
|
$this->api->setDi($di);
|
|
$this->api->setService($serviceMock);
|
|
|
|
$result = $this->api->server_get_list(array());
|
|
$this->assertIsArray($result);
|
|
}
|
|
|
|
public function testserver_create()
|
|
{
|
|
$data = array(
|
|
'name' => 'test',
|
|
'ip' => '1.1.1.1',
|
|
'manager' => 'ServerManagerCode',
|
|
);
|
|
|
|
$newServerId = 1;
|
|
|
|
$serviceMock = $this->getMockBuilder('\Box\Mod\Servicehosting\Service')->getMock();
|
|
$serviceMock->expects($this->atLeastOnce())
|
|
->method('createServer')
|
|
->will($this->returnValue($newServerId));
|
|
|
|
$validatorMock = $this->getMockBuilder('\FOSSBilling\Validate')->disableOriginalConstructor()->getMock();
|
|
$validatorMock->expects($this->atLeastOnce())
|
|
->method('checkRequiredParamsForArray')
|
|
->will($this->returnValue(null));
|
|
|
|
$di = new \Pimple\Container();
|
|
$di['validator'] = $validatorMock;
|
|
$this->api->setDi($di);
|
|
|
|
$this->api->setService($serviceMock);
|
|
|
|
$result = $this->api->server_create($data);
|
|
$this->assertIsInt($result);
|
|
$this->assertEquals($newServerId, $result);
|
|
}
|
|
|
|
public function testserver_get()
|
|
{
|
|
$data['id'] = 1;
|
|
|
|
$serviceMock = $this->getMockBuilder('\Box\Mod\Servicehosting\Service')->getMock();
|
|
$serviceMock->expects($this->atLeastOnce())
|
|
->method('toHostingServerApiArray')
|
|
->will($this->returnValue(array()));
|
|
|
|
$dbMock = $this->getMockBuilder('\Box_Database')->getMock();
|
|
$dbMock->expects($this->atLeastOnce())
|
|
->method('getExistingModelById')
|
|
->will($this->returnValue(new \Model_ServiceHostingServer));
|
|
|
|
$validatorMock = $this->getMockBuilder('\FOSSBilling\Validate')->disableOriginalConstructor()->getMock();
|
|
$validatorMock->expects($this->atLeastOnce())
|
|
->method('checkRequiredParamsForArray')
|
|
->will($this->returnValue(null));
|
|
|
|
$di = new \Pimple\Container();
|
|
$di['db'] = $dbMock;
|
|
$di['validator'] = $validatorMock;
|
|
|
|
$this->api->setDi($di);
|
|
$this->api->setService($serviceMock);
|
|
|
|
$result = $this->api->server_get($data);
|
|
$this->assertIsArray($result);
|
|
}
|
|
|
|
public function testServerDelete()
|
|
{
|
|
// Test case 1: Server can be deleted
|
|
$data['id'] = 1;
|
|
|
|
$serviceMock = $this->getMockBuilder('\Box\Mod\Servicehosting\Service')->getMock();
|
|
$serviceMock->expects($this->atLeastOnce())
|
|
->method('deleteServer')
|
|
->will($this->returnValue(true));
|
|
|
|
$dbMock = $this->getMockBuilder('\Box_Database')->getMock();
|
|
$dbMock->expects($this->atLeastOnce())
|
|
->method('getExistingModelById')
|
|
->will($this->returnValue(new \Model_ServiceHostingServer));
|
|
|
|
$validatorMock = $this->getMockBuilder('\FOSSBilling\Validate')->disableOriginalConstructor()->getMock();
|
|
$validatorMock->expects($this->atLeastOnce())
|
|
->method('checkRequiredParamsForArray')
|
|
->will($this->returnValue(null));
|
|
|
|
$di = new \Pimple\Container();
|
|
$di['db'] = $dbMock;
|
|
$di['validator'] = $validatorMock;
|
|
|
|
$this->api->setDi($di);
|
|
$this->api->setService($serviceMock);
|
|
|
|
$result = $this->api->server_delete($data);
|
|
$this->assertTrue($result);
|
|
|
|
// Test case 2: Server is used by service_hostings and cannot be deleted
|
|
$data['id'] = 2;
|
|
|
|
$dbMock = $this->getMockBuilder('\Box_Database')->getMock();
|
|
$dbMock->expects($this->atLeastOnce())
|
|
->method('getExistingModelById')
|
|
->will($this->returnValue(new \Model_ServiceHostingServer));
|
|
|
|
$validatorMock = $this->getMockBuilder('\FOSSBilling\Validate')->disableOriginalConstructor()->getMock();
|
|
$validatorMock->expects($this->atLeastOnce())
|
|
->method('checkRequiredParamsForArray')
|
|
->will($this->returnValue(null));
|
|
|
|
// Mock the 'find' method to return a non-empty array, simulating the server being used by service hostings
|
|
$dbMock->expects($this->atLeastOnce())
|
|
->method('find')
|
|
->will($this->returnValue(['dummy_data']));
|
|
|
|
$di = new \Pimple\Container();
|
|
$di['db'] = $dbMock;
|
|
$di['validator'] = $validatorMock;
|
|
|
|
$this->api->setDi($di);
|
|
|
|
// Now, we expect an exception to be thrown because the server is used by service_hostings
|
|
$this->expectException(\FOSSBilling\Exception::class);
|
|
$this->expectExceptionCode(704);
|
|
|
|
$this->api->server_delete($data);
|
|
}
|
|
|
|
|
|
public function testserver_update()
|
|
{
|
|
$data['id'] = 1;
|
|
|
|
$serviceMock = $this->getMockBuilder('\Box\Mod\Servicehosting\Service')->getMock();
|
|
$serviceMock->expects($this->atLeastOnce())
|
|
->method('updateServer')
|
|
->will($this->returnValue(true));
|
|
|
|
$dbMock = $this->getMockBuilder('\Box_Database')->getMock();
|
|
$dbMock->expects($this->atLeastOnce())
|
|
->method('getExistingModelById')
|
|
->will($this->returnValue(new \Model_ServiceHostingServer));
|
|
$validatorMock = $this->getMockBuilder('\FOSSBilling\Validate')->disableOriginalConstructor()->getMock();
|
|
$validatorMock->expects($this->atLeastOnce())
|
|
->method('checkRequiredParamsForArray')
|
|
->will($this->returnValue(null));
|
|
|
|
$di = new \Pimple\Container();
|
|
$di['db'] = $dbMock;
|
|
$di['validator'] = $validatorMock;
|
|
|
|
$this->api->setDi($di);
|
|
$this->api->setService($serviceMock);
|
|
|
|
$result = $this->api->server_update($data);
|
|
$this->assertIsBool($result);
|
|
$this->assertTrue($result);
|
|
}
|
|
|
|
public function testserver_test_connection()
|
|
{
|
|
$data['id'] = 1;
|
|
|
|
$serviceMock = $this->getMockBuilder('\Box\Mod\Servicehosting\Service')->getMock();
|
|
$serviceMock->expects($this->atLeastOnce())
|
|
->method('testConnection')
|
|
->will($this->returnValue(true));
|
|
|
|
$dbMock = $this->getMockBuilder('\Box_Database')->getMock();
|
|
$dbMock->expects($this->atLeastOnce())
|
|
->method('getExistingModelById')
|
|
->will($this->returnValue(new \Model_ServiceHostingServer));
|
|
$validatorMock = $this->getMockBuilder('\FOSSBilling\Validate')->disableOriginalConstructor()->getMock();
|
|
$validatorMock->expects($this->atLeastOnce())
|
|
->method('checkRequiredParamsForArray')
|
|
->will($this->returnValue(null));
|
|
|
|
$di = new \Pimple\Container();
|
|
$di['db'] = $dbMock;
|
|
$di['validator'] = $validatorMock;
|
|
|
|
$this->api->setDi($di);
|
|
$this->api->setService($serviceMock);
|
|
|
|
$result = $this->api->server_test_connection($data);
|
|
$this->assertIsBool($result);
|
|
$this->assertTrue($result);
|
|
}
|
|
|
|
public function testhp_get_pairs()
|
|
{
|
|
$serviceMock = $this->getMockBuilder('\Box\Mod\Servicehosting\Service')->getMock();
|
|
$serviceMock->expects($this->atLeastOnce())
|
|
->method('getHpPairs')
|
|
->will($this->returnValue(array()));
|
|
|
|
$this->api->setService($serviceMock);
|
|
$result = $this->api->hp_get_pairs(array());
|
|
$this->assertIsArray($result);
|
|
}
|
|
|
|
public function testhp_get_list()
|
|
{
|
|
$serviceMock = $this->getMockBuilder('\Box\Mod\Servicehosting\Service')->getMock();
|
|
$serviceMock->expects($this->atLeastOnce())
|
|
->method('getHpSearchQuery')
|
|
->will($this->returnValue(array('SQLstring', array())));
|
|
|
|
$pagerMock = $this->getMockBuilder('\Box_Pagination')->getMock();
|
|
$pagerMock->expects($this->atLeastOnce())
|
|
->method('getSimpleResultSet')
|
|
->will($this->returnValue(array('list' => array())));
|
|
|
|
|
|
$di = new \Pimple\Container();
|
|
$di['pager'] = $pagerMock;
|
|
|
|
|
|
$this->api->setDi($di);
|
|
$this->api->setService($serviceMock);
|
|
|
|
$result = $this->api->hp_get_list(array());
|
|
$this->assertIsArray($result);
|
|
}
|
|
|
|
public function testhp_delete()
|
|
{
|
|
$data = array(
|
|
'id' => 1,
|
|
);
|
|
|
|
$model = new \Model_ServiceHostingHp();
|
|
|
|
$serviceMock = $this->getMockBuilder('\Box\Mod\Servicehosting\Service')->getMock();
|
|
$serviceMock->expects($this->atLeastOnce())
|
|
->method('deleteHp')
|
|
->will($this->returnValue(true));
|
|
|
|
$dbMock = $this->getMockBuilder('\Box_Database')->getMock();
|
|
$dbMock->expects($this->atLeastOnce())
|
|
->method('getExistingModelById')
|
|
->will($this->returnValue($model));
|
|
$validatorMock = $this->getMockBuilder('\FOSSBilling\Validate')->disableOriginalConstructor()->getMock();
|
|
$validatorMock->expects($this->atLeastOnce())
|
|
->method('checkRequiredParamsForArray')
|
|
->will($this->returnValue(null));
|
|
|
|
$di = new \Pimple\Container();
|
|
$di['db'] = $dbMock;
|
|
$di['validator'] = $validatorMock;
|
|
|
|
$this->api->setDi($di);
|
|
$this->api->setService($serviceMock);
|
|
|
|
// Add a try-catch block to handle the exception thrown in the hp_delete function
|
|
try {
|
|
$result = $this->api->hp_delete($data);
|
|
|
|
// If the function doesn't throw an exception, then the test should assert the result
|
|
$this->assertIsBool($result);
|
|
$this->assertTrue($result);
|
|
} catch (\FOSSBilling\Exception $e) {
|
|
// If the function throws an exception, the test should fail
|
|
$this->fail("Exception thrown: " . $e->getMessage());
|
|
}
|
|
}
|
|
|
|
|
|
public function testhp_get()
|
|
{
|
|
$data = array(
|
|
'id' => 1,
|
|
);
|
|
|
|
$model = new \Model_ServiceHostingHp();
|
|
|
|
$serviceMock = $this->getMockBuilder('\Box\Mod\Servicehosting\Service')->getMock();
|
|
$serviceMock->expects($this->atLeastOnce())
|
|
->method('toHostingHpApiArray')
|
|
->will($this->returnValue(array()));
|
|
|
|
$dbMock = $this->getMockBuilder('\Box_Database')->getMock();
|
|
$dbMock->expects($this->atLeastOnce())
|
|
->method('getExistingModelById')
|
|
->will($this->returnValue($model));
|
|
|
|
$validatorMock = $this->getMockBuilder('\FOSSBilling\Validate')->disableOriginalConstructor()->getMock();
|
|
$validatorMock->expects($this->atLeastOnce())
|
|
->method('checkRequiredParamsForArray')
|
|
->will($this->returnValue(null));
|
|
|
|
$di = new \Pimple\Container();
|
|
$di['db'] = $dbMock;
|
|
$di['validator'] = $validatorMock;
|
|
|
|
$this->api->setDi($di);
|
|
$this->api->setService($serviceMock);
|
|
|
|
$result = $this->api->hp_get($data);
|
|
$this->assertIsArray($result);
|
|
}
|
|
|
|
public function testhp_update()
|
|
{
|
|
$data = array(
|
|
'id' => 1,
|
|
);
|
|
|
|
$model = new \Model_ServiceHostingHp();
|
|
|
|
$serviceMock = $this->getMockBuilder('\Box\Mod\Servicehosting\Service')->getMock();
|
|
$serviceMock->expects($this->atLeastOnce())
|
|
->method('updateHp')
|
|
->will($this->returnValue(true));
|
|
|
|
$dbMock = $this->getMockBuilder('\Box_Database')->getMock();
|
|
$dbMock->expects($this->atLeastOnce())
|
|
->method('getExistingModelById')
|
|
->will($this->returnValue($model));
|
|
|
|
$validatorMock = $this->getMockBuilder('\FOSSBilling\Validate')->disableOriginalConstructor()->getMock();
|
|
$validatorMock->expects($this->atLeastOnce())
|
|
->method('checkRequiredParamsForArray')
|
|
->will($this->returnValue(null));
|
|
|
|
$di = new \Pimple\Container();
|
|
$di['db'] = $dbMock;
|
|
$di['validator'] = $validatorMock;
|
|
|
|
$this->api->setDi($di);
|
|
$this->api->setService($serviceMock);
|
|
|
|
$result = $this->api->hp_update($data);
|
|
$this->assertIsBool($result);
|
|
$this->assertTrue($result);
|
|
}
|
|
|
|
|
|
public function testhp_create()
|
|
{
|
|
$data = array(
|
|
'name' => 'test',
|
|
);
|
|
|
|
$newHpId = 2;
|
|
|
|
$serviceMock = $this->getMockBuilder('\Box\Mod\Servicehosting\Service')->getMock();
|
|
$serviceMock->expects($this->atLeastOnce())
|
|
->method('createHp')
|
|
->will($this->returnValue($newHpId));
|
|
|
|
$validatorMock = $this->getMockBuilder('\FOSSBilling\Validate')->disableOriginalConstructor()->getMock();
|
|
$validatorMock->expects($this->atLeastOnce())
|
|
->method('checkRequiredParamsForArray')
|
|
->will($this->returnValue(null));
|
|
|
|
$di = new \Pimple\Container();
|
|
$di['validator'] = $validatorMock;
|
|
$this->api->setDi($di);
|
|
|
|
$this->api->setService($serviceMock);
|
|
|
|
$result = $this->api->hp_create($data);
|
|
$this->assertIsInt($result);
|
|
$this->assertEquals($newHpId, $result);
|
|
}
|
|
|
|
public function test_getService()
|
|
{
|
|
$data = array(
|
|
'order_id' => 1,
|
|
);
|
|
|
|
$clientOrderModel = new \Model_ClientOrder();
|
|
$dbMock = $this->getMockBuilder('\Box_Database')->getMock();
|
|
$dbMock->expects($this->atLeastOnce())
|
|
->method('getExistingModelById')
|
|
->will($this->returnValue($clientOrderModel));
|
|
|
|
|
|
$model = new \Model_ServiceHosting();
|
|
$orderServiceMock = $this->getMockBuilder('\Box\Mod\Order\Service')->getMock();
|
|
$orderServiceMock->expects($this->atLeastOnce())
|
|
->method('getOrderService')
|
|
->will($this->returnValue($model));
|
|
$validatorMock = $this->getMockBuilder('\FOSSBilling\Validate')->disableOriginalConstructor()->getMock();
|
|
$validatorMock->expects($this->atLeastOnce())
|
|
->method('checkRequiredParamsForArray')
|
|
->will($this->returnValue(null));
|
|
|
|
$di = new \Pimple\Container();
|
|
$di['mod_service'] = $di->protect(function () use ($orderServiceMock) {
|
|
return $orderServiceMock;
|
|
});
|
|
$di['db'] = $dbMock;
|
|
$di['validator'] = $validatorMock;
|
|
|
|
$this->api->setDi($di);
|
|
|
|
$result = $this->api->_getService($data);
|
|
$this->assertIsArray($result);
|
|
$this->assertInstanceOf('\Model_ClientOrder', $result[0]);
|
|
$this->assertInstanceOf('\Model_ServiceHosting', $result[1]);
|
|
}
|
|
|
|
public function test_getServiceOrderNotActivated()
|
|
{
|
|
$data = array(
|
|
'order_id' => 1,
|
|
);
|
|
|
|
$clientOrderModel = new \Model_ClientOrder();
|
|
$dbMock = $this->getMockBuilder('\Box_Database')->getMock();
|
|
$dbMock->expects($this->atLeastOnce())
|
|
->method('getExistingModelById')
|
|
->will($this->returnValue($clientOrderModel));
|
|
|
|
|
|
$model = null;
|
|
$orderServiceMock = $this->getMockBuilder('\Box\Mod\Order\Service')->getMock();
|
|
$orderServiceMock->expects($this->atLeastOnce())
|
|
->method('getOrderService')
|
|
->will($this->returnValue($model));
|
|
|
|
$validatorMock = $this->getMockBuilder('\FOSSBilling\Validate')->disableOriginalConstructor()->getMock();
|
|
$validatorMock->expects($this->atLeastOnce())
|
|
->method('checkRequiredParamsForArray')
|
|
->will($this->returnValue(null));
|
|
|
|
$di = new \Pimple\Container();
|
|
$di['mod_service'] = $di->protect(function () use ($orderServiceMock) {
|
|
return $orderServiceMock;
|
|
});
|
|
$di['db'] = $dbMock;
|
|
$di['validator'] = $validatorMock;
|
|
|
|
$this->api->setDi($di);
|
|
|
|
$this->expectException(\FOSSBilling\Exception::class);
|
|
$this->expectExceptionMessage('Order is not activated');
|
|
$this->api->_getService($data);
|
|
}
|
|
}
|