add unit-tests for CustomerBackup-ApiCommand
Signed-off-by: Michael Kaufmann (d00p) <d00p@froxlor.org>
This commit is contained in:
@@ -117,10 +117,10 @@ class CustomerBackups extends ApiCommand implements ResourceEntity
|
|||||||
{
|
{
|
||||||
// get planned backups
|
// get planned backups
|
||||||
$result = $this->apiCall('CustomerBackups.listing', $this->getParamList());
|
$result = $this->apiCall('CustomerBackups.listing', $this->getParamList());
|
||||||
|
|
||||||
$entry = $this->getParam('backup_job_entry');
|
$entry = $this->getParam('backup_job_entry');
|
||||||
$customer_ids = $this->getAllowedCustomerIds('extras.backup');
|
$customer_ids = $this->getAllowedCustomerIds('extras.backup');
|
||||||
|
|
||||||
if ($result['count'] > 0 && $entry > 0) {
|
if ($result['count'] > 0 && $entry > 0) {
|
||||||
// prepare statement
|
// prepare statement
|
||||||
$del_stmt = Database::prepare("DELETE FROM `" . TABLE_PANEL_TASKS . "` WHERE `id` = :tid");
|
$del_stmt = Database::prepare("DELETE FROM `" . TABLE_PANEL_TASKS . "` WHERE `id` = :tid");
|
||||||
@@ -130,6 +130,7 @@ class CustomerBackups extends ApiCommand implements ResourceEntity
|
|||||||
Database::pexecute($del_stmt, array(
|
Database::pexecute($del_stmt, array(
|
||||||
'tid' => $entry
|
'tid' => $entry
|
||||||
));
|
));
|
||||||
|
$this->logger()->logAction($this->isAdmin() ? ADM_ACTION : USR_ACTION, LOG_NOTICE, "[API] deleted planned customer-backup #" . $entry);
|
||||||
return $this->response(200, "successfull", true);
|
return $this->response(200, "successfull", true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
<directory>tests/Ftps</directory>
|
<directory>tests/Ftps</directory>
|
||||||
<directory>tests/Emails</directory>
|
<directory>tests/Emails</directory>
|
||||||
<directory>tests/Extras</directory>
|
<directory>tests/Extras</directory>
|
||||||
|
<directory>tests/Backup</directory>
|
||||||
</testsuite>
|
</testsuite>
|
||||||
</testsuites>
|
</testsuites>
|
||||||
|
|
||||||
|
|||||||
112
tests/Backup/CustomerBackupsTest.php
Normal file
112
tests/Backup/CustomerBackupsTest.php
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
<?php
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @covers ApiCommand
|
||||||
|
* @covers ApiParameter
|
||||||
|
* @covers CustomerBackups
|
||||||
|
*/
|
||||||
|
class CustomerBackupsTest extends TestCase
|
||||||
|
{
|
||||||
|
|
||||||
|
public function testCustomerCustomerBackupsAdd()
|
||||||
|
{
|
||||||
|
global $admin_userdata;
|
||||||
|
|
||||||
|
Database::query("TRUNCATE TABLE `panel_tasks`;");
|
||||||
|
|
||||||
|
// get customer
|
||||||
|
$json_result = Customers::getLocal($admin_userdata, array(
|
||||||
|
'loginname' => 'test1'
|
||||||
|
))->get();
|
||||||
|
$customer_userdata = json_decode($json_result, true)['data'];
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'path' => '/my-backup',
|
||||||
|
'backup_dbs' => 1,
|
||||||
|
'backup_mail' => 2,
|
||||||
|
'backup_web' => 1
|
||||||
|
];
|
||||||
|
$json_result = CustomerBackups::getLocal($customer_userdata, $data)->add();
|
||||||
|
$result = json_decode($json_result, true)['data'];
|
||||||
|
$this->assertEquals($customer_userdata['documentroot'] . 'my-backup/', $result['destdir']);
|
||||||
|
$this->assertEquals('1', $result['backup_dbs']);
|
||||||
|
$this->assertEquals('0', $result['backup_mail']);
|
||||||
|
$this->assertEquals('1', $result['backup_web']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAdminCustomerBackupsGet()
|
||||||
|
{
|
||||||
|
global $admin_userdata;
|
||||||
|
$this->expectExceptionCode(303);
|
||||||
|
CustomerBackups::getLocal($admin_userdata)->get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAdminCustomerBackupsUpdate()
|
||||||
|
{
|
||||||
|
global $admin_userdata;
|
||||||
|
$this->expectExceptionCode(303);
|
||||||
|
CustomerBackups::getLocal($admin_userdata)->update();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @depends testCustomerCustomerBackupsAdd
|
||||||
|
*/
|
||||||
|
public function testAdminCustomerBackupsListing()
|
||||||
|
{
|
||||||
|
global $admin_userdata;
|
||||||
|
|
||||||
|
$json_result = CustomerBackups::getLocal($admin_userdata)->listing();
|
||||||
|
$result = json_decode($json_result, true)['data'];
|
||||||
|
$this->assertEquals(1, $result['count']);
|
||||||
|
$this->assertEquals('1', $result['list'][0]['data']['backup_dbs']);
|
||||||
|
$this->assertEquals('0', $result['list'][0]['data']['backup_mail']);
|
||||||
|
$this->assertEquals('1', $result['list'][0]['data']['backup_web']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @depends testCustomerCustomerBackupsAdd
|
||||||
|
*/
|
||||||
|
public function testCustomerCustomerBackupsDelete()
|
||||||
|
{
|
||||||
|
global $admin_userdata;
|
||||||
|
|
||||||
|
// get customer
|
||||||
|
$json_result = Customers::getLocal($admin_userdata, array(
|
||||||
|
'loginname' => 'test1'
|
||||||
|
))->get();
|
||||||
|
$customer_userdata = json_decode($json_result, true)['data'];
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'backup_job_entry' => 1
|
||||||
|
];
|
||||||
|
$json_result = CustomerBackups::getLocal($customer_userdata, $data)->delete();
|
||||||
|
$result = json_decode($json_result, true)['data'];
|
||||||
|
$this->assertTrue($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @depends testAdminCustomerBackupsListing
|
||||||
|
*/
|
||||||
|
public function testCustomerCustomerBackupsDeleteNotFound()
|
||||||
|
{
|
||||||
|
global $admin_userdata;
|
||||||
|
|
||||||
|
// get customer
|
||||||
|
$json_result = Customers::getLocal($admin_userdata, array(
|
||||||
|
'loginname' => 'test1'
|
||||||
|
))->get();
|
||||||
|
$customer_userdata = json_decode($json_result, true)['data'];
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'backup_job_entry' => 1337
|
||||||
|
];
|
||||||
|
$this->expectExceptionCode(404);
|
||||||
|
$this->expectExceptionMessage('Backup job with id #1337 could not be found');
|
||||||
|
CustomerBackups::getLocal($customer_userdata, $data)->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user