finished unit-tests for Mysqls-ApiCommand

Signed-off-by: Michael Kaufmann (d00p) <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann (d00p)
2018-03-26 09:53:09 +02:00
parent 6006b16c95
commit c98be3c04f
3 changed files with 122 additions and 1 deletions

View File

@@ -348,7 +348,10 @@ class Mysqls extends ApiCommand implements ResourceEntity
Database::pexecute($stmt, $params, true, true);
$this->logger()->logAction($this->isAdmin() ? ADM_ACTION : USR_ACTION, LOG_WARNING, "[API] updated mysql-database '" . $result['databasename'] . "'");
return $this->response(200, "successfull", $params);
$result = $this->apiCall('Mysqls.get', array(
'dbname' => $result['databasename']
));
return $this->response(200, "successfull", $result);
}
/**

View File

@@ -30,4 +30,121 @@ class MysqlsTest extends TestCase
$this->assertEquals('testdb', $result['description']);
$this->assertEquals(0, $result['dbserver']);
}
/**
* @depends testCustomerMysqlsAdd
*/
public function testAdminMysqlsGet()
{
global $admin_userdata;
$json_result = Mysqls::getLocal($admin_userdata, array(
'dbname' => 'test1sql1'
))->get();
$result = json_decode($json_result, true)['data'];
$this->assertEquals('test1sql1', $result['databasename']);
$this->assertEquals('testdb', $result['description']);
}
/**
* @depends testCustomerMysqlsAdd
*/
public function testResellerMysqlsGet()
{
global $admin_userdata;
// get reseller
$json_result = Admins::getLocal($admin_userdata, array(
'loginname' => 'reseller'
))->get();
$reseller_userdata = json_decode($json_result, true)['data'];
$reseller_userdata['adminsession'] = 1;
$json_result = Mysqls::getLocal($reseller_userdata, array(
'dbname' => 'test1sql1'
))->get();
$result = json_decode($json_result, true)['data'];
$this->assertEquals('test1sql1', $result['databasename']);
$this->assertEquals('testdb', $result['description']);
}
public function testCustomerMysqlsGetUnknown()
{
global $admin_userdata;
// get customer
$json_result = Customers::getLocal($admin_userdata, array(
'loginname' => 'test1'
))->get();
$customer_userdata = json_decode($json_result, true)['data'];
$data = [
'dbname' => 'test1sql5'
];
$this->expectExceptionCode(404);
$this->expectExceptionMessage("MySQL database with dbname 'test1sql5' could not be found");
Mysqls::getLocal($customer_userdata, $data)->get();
}
/**
* @depends testCustomerMysqlsAdd
*/
public function testAdminMysqlsUpdate()
{
global $admin_userdata;
$json_result = Mysqls::getLocal($admin_userdata, array(
'dbname' => 'test1sql1'
))->get();
$old_db = json_decode($json_result, true)['data'];
$data = [
'dbname' => 'test1sql1',
'mysql_password' => generatePassword(),
'description' => 'testdb-upd',
'loginname' => 'test1'
];
$json_result = Mysqls::getLocal($admin_userdata, $data)->update();
$result = json_decode($json_result, true)['data'];
$this->assertEquals('testdb-upd', $result['description']);
}
/**
* @depends testCustomerMysqlsAdd
*/
public function testCustomerMysqlsList()
{
global $admin_userdata;
// get customer
$json_result = Customers::getLocal($admin_userdata, array(
'loginname' => 'test1'
))->get();
$customer_userdata = json_decode($json_result, true)['data'];
$json_result = Mysqls::getLocal($customer_userdata)->listing();
$result = json_decode($json_result, true)['data'];
$this->assertEquals(1, $result['count']);
$this->assertEquals('test1sql1', $result['list'][0]['databasename']);
}
/**
* @depends testCustomerMysqlsList
*/
public function testCustomerMysqlsDelete()
{
global $admin_userdata;
// get customer
$json_result = Customers::getLocal($admin_userdata, array(
'loginname' => 'test1'
))->get();
$customer_userdata = json_decode($json_result, true)['data'];
$data = [
'dbname' => 'test1sql1'
];
$json_result = Mysqls::getLocal($customer_userdata, $data)->delete();
$result = json_decode($json_result, true)['data'];
$this->assertEquals('test1sql1', $result['databasename']);
}
}

View File

@@ -54,6 +54,7 @@ Database::query("TRUNCATE TABLE `" . TABLE_PANEL_DOMAINREDIRECTS . "`;");
Database::query("TRUNCATE TABLE `" . TABLE_PANEL_ADMINS . "`;");
Database::query("TRUNCATE TABLE `" . TABLE_PANEL_IPSANDPORTS . "`;");
Database::query("TRUNCATE TABLE `" . TABLE_API_KEYS . "`;");
Database::query("TRUNCATE TABLE `" . TABLE_PANEL_DATABASES . "`;");
// add superadmin
Database::query("INSERT INTO `" . TABLE_PANEL_ADMINS . "` SET