added Traffic.listing ApiCommand; added first Unit-Tests for Traffic-Api; SQL IN-clause cannot be prepared, replaced all occurances accordingly; added --no-fork parameter to traffic-cron

Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann
2018-11-11 21:51:39 +01:00
parent 41acbc745c
commit 18aa8eb5d2
15 changed files with 206 additions and 48 deletions

View File

@@ -82,7 +82,7 @@ class FtpsTest extends TestCase
$json_result = Ftps::getLocal($admin_userdata)->listing();
$result = json_decode($json_result, true)['data'];
$this->assertEquals(1, $result['count']);
$this->assertEquals(2, $result['count']);
}
public function testAdminFtpsListSpecificCustomer()

View File

@@ -0,0 +1,104 @@
<?php
use PHPUnit\Framework\TestCase;
/**
*
* @covers ApiCommand
* @covers ApiParameter
* @covers Traffic
* @covers Customers
* @covers Admins
*/
class TrafficTest extends TestCase
{
public static function setUpBeforeClass()
{
$ins_stmt = Database::prepare("
INSERT INTO `" . TABLE_PANEL_TRAFFIC . "` SET
`customerid` = :cid,
`year` = :y, `month` = :m, `day` = :d,
`stamp` = :ts,
`http` = :http, `ftp_up` = :fup, `ftp_down` = :fdown, `mail` = :mail
");
$ins_adm_stmt = Database::prepare("
INSERT INTO `" . TABLE_PANEL_TRAFFIC_ADMINS . "` SET
`adminid` = :aid,
`year` = :y, `month` = :m, `day` = :d,
`stamp` = :ts,
`http` = :http, `ftp_up` = :fup, `ftp_down` = :fdown, `mail` = :mail
");
$http = 5 * 1024 * 1024 * 1024; // 5 GB
$fup = 50 * 1024 * 1024; // 50 MB
$fdown = 2 * 1024 * 1024 * 1024; // 2 GB
$mail = 250 * 1024 * 1024; // 250 MB
foreach (array(1,2,3) as $cid)
{
Database::pexecute($ins_stmt, array(
'cid' => $cid,
'y' => date('Y'),
'm' => date('m'),
'd' => date('d'),
'ts' => time(),
'http' => $http,
'fup' => $fup,
'fdown' => $fdown,
'mail' => $mail
));
}
Database::pexecute($ins_adm_stmt, array(
'aid' => 1,
'y' => date('Y'),
'm' => date('m'),
'd' => date('d'),
'ts' => time(),
'http' => $http * 2,
'fup' => $fup * 2,
'fdown' => $fdown * 2,
'mail' => $mail * 2
));
}
public function testAdminTrafficList()
{
global $admin_userdata;
$json_result = Traffic::getLocal($admin_userdata)->listing();
$result = json_decode($json_result, true)['data'];
$this->assertEquals(1, $result['count']);
$http = 2 * (5 * 1024 * 1024 * 1024); // 2x 5 GB
$this->assertEquals($http, $result['list'][0]['http']);
}
public function testAdminTrafficListCustomers()
{
global $admin_userdata;
$json_result = Traffic::getLocal($admin_userdata, array(
'customer_traffic' => 1
))->listing();
$result = json_decode($json_result, true)['data'];
$this->assertEquals(2, $result['count']);
$this->assertEquals(1, $result['list'][0]['customerid']);
$this->assertEquals(3, $result['list'][1]['customerid']);
}
public function testCustomerTrafficList()
{
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 = Traffic::getLocal($customer_userdata)->listing();
$result = json_decode($json_result, true)['data'];
$this->assertEquals(1, $result['count']);
$mail = 250 * 1024 * 1024; // 250 MB
$this->assertEquals($mail, $result['list'][0]['mail']);
}
}

View File

@@ -130,3 +130,4 @@ $admin_userdata = Database::pexecute_first($sel_stmt);
$admin_userdata['adminsession'] = 1;
Settings::Set('panel.standardlanguage', 'English', true);
Settings::Set('system.lastguid', '10000', true);