added unit-tests for DirOptions
Signed-off-by: Michael Kaufmann (d00p) <d00p@froxlor.org>
This commit is contained in:
@@ -74,7 +74,7 @@ class DirOptions extends ApiCommand implements ResourceEntity
|
|||||||
SELECT `id`, `path` FROM `" . TABLE_PANEL_HTACCESS . "`
|
SELECT `id`, `path` FROM `" . TABLE_PANEL_HTACCESS . "`
|
||||||
WHERE `path`= :path AND `customerid`= :customerid
|
WHERE `path`= :path AND `customerid`= :customerid
|
||||||
");
|
");
|
||||||
$path_dupe_check = Database::pexecute($path_dupe_check_stmt, array(
|
$path_dupe_check = Database::pexecute_first($path_dupe_check_stmt, array(
|
||||||
"path" => $path,
|
"path" => $path,
|
||||||
"customerid" => $customer['customerid']
|
"customerid" => $customer['customerid']
|
||||||
), true, true);
|
), true, true);
|
||||||
@@ -222,7 +222,7 @@ class DirOptions extends ApiCommand implements ResourceEntity
|
|||||||
$error500path = correctErrorDocument($error500path, true);
|
$error500path = correctErrorDocument($error500path, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($option_indexes != $result['options_indexes']) || ($error404path != $result['error404path']) || ($error403path != $result['error403path']) || ($error500path != $result['error500path']) || ($options_cgi != $result['options_cgi'])) {
|
if (($options_indexes != $result['options_indexes']) || ($error404path != $result['error404path']) || ($error403path != $result['error403path']) || ($error500path != $result['error500path']) || ($options_cgi != $result['options_cgi'])) {
|
||||||
inserttask('1');
|
inserttask('1');
|
||||||
$stmt = Database::prepare("
|
$stmt = Database::prepare("
|
||||||
UPDATE `" . TABLE_PANEL_HTACCESS . "`
|
UPDATE `" . TABLE_PANEL_HTACCESS . "`
|
||||||
@@ -236,7 +236,7 @@ class DirOptions extends ApiCommand implements ResourceEntity
|
|||||||
");
|
");
|
||||||
$params = array(
|
$params = array(
|
||||||
"customerid" => $customer['customerid'],
|
"customerid" => $customer['customerid'],
|
||||||
"options_indexes" => $option_indexes,
|
"options_indexes" => $options_indexes,
|
||||||
"error403path" => $error403path,
|
"error403path" => $error403path,
|
||||||
"error404path" => $error404path,
|
"error404path" => $error404path,
|
||||||
"error500path" => $error500path,
|
"error500path" => $error500path,
|
||||||
|
|||||||
184
tests/Extras/DirOptionsTest.php
Normal file
184
tests/Extras/DirOptionsTest.php
Normal file
@@ -0,0 +1,184 @@
|
|||||||
|
<?php
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers ApiCommand
|
||||||
|
* @covers ApiParameter
|
||||||
|
* @covers DirOptions
|
||||||
|
*/
|
||||||
|
class DirOptionsTest extends TestCase
|
||||||
|
{
|
||||||
|
|
||||||
|
public function testCustomerDirOptionsAdd()
|
||||||
|
{
|
||||||
|
global $admin_userdata;
|
||||||
|
|
||||||
|
// get customer
|
||||||
|
$json_result = Customers::getLocal($admin_userdata, array(
|
||||||
|
'loginname' => 'test1'
|
||||||
|
))->get();
|
||||||
|
$customer_userdata = json_decode($json_result, true)['data'];
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'path' => '/test',
|
||||||
|
'options_indexes' => 1,
|
||||||
|
'options_cgi' => 1,
|
||||||
|
'error404path' => '/404.html',
|
||||||
|
'error403path' => '/403.html',
|
||||||
|
'error500path' => '/500.html'
|
||||||
|
];
|
||||||
|
$json_result = DirOptions::getLocal($customer_userdata, $data)->add();
|
||||||
|
$result = json_decode($json_result, true)['data'];
|
||||||
|
$this->assertEquals($customer_userdata['documentroot'] . 'test/', $result['path']);
|
||||||
|
$this->assertEquals('1', $result['options_cgi']);
|
||||||
|
$this->assertEquals('/403.html', $result['error403path']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCustomerDirOptionsAddDuplicatePath()
|
||||||
|
{
|
||||||
|
global $admin_userdata;
|
||||||
|
|
||||||
|
// get customer
|
||||||
|
$json_result = Customers::getLocal($admin_userdata, array(
|
||||||
|
'loginname' => 'test1'
|
||||||
|
))->get();
|
||||||
|
$customer_userdata = json_decode($json_result, true)['data'];
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'path' => '/test',
|
||||||
|
'options_indexes' => 0,
|
||||||
|
'options_cgi' => 0,
|
||||||
|
'error404path' => '/404a.html',
|
||||||
|
'error403path' => '/403a.html',
|
||||||
|
'error500path' => '/500a.html'
|
||||||
|
];
|
||||||
|
$this->expectExceptionMessage("Option for path /test/ already exists");
|
||||||
|
DirOptions::getLocal($customer_userdata, $data)->add();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAdminDirOptionsGet()
|
||||||
|
{
|
||||||
|
global $admin_userdata;
|
||||||
|
|
||||||
|
// get customer
|
||||||
|
$json_result = Customers::getLocal($admin_userdata, array(
|
||||||
|
'loginname' => 'test1'
|
||||||
|
))->get();
|
||||||
|
$customer_userdata = json_decode($json_result, true)['data'];
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'id' => 1,
|
||||||
|
'loginname' => 'test1'
|
||||||
|
];
|
||||||
|
$json_result = DirOptions::getLocal($admin_userdata, $data)->get();
|
||||||
|
$result = json_decode($json_result, true)['data'];
|
||||||
|
$this->assertEquals($customer_userdata['documentroot'] . 'test/', $result['path']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testResellerDirOptionsGet()
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
// get customer
|
||||||
|
$json_result = Customers::getLocal($admin_userdata, array(
|
||||||
|
'loginname' => 'test1'
|
||||||
|
))->get();
|
||||||
|
$customer_userdata = json_decode($json_result, true)['data'];
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'id' => 1,
|
||||||
|
'loginname' => 'test1'
|
||||||
|
];
|
||||||
|
$json_result = DirOptions::getLocal($reseller_userdata, $data)->get();
|
||||||
|
$result = json_decode($json_result, true)['data'];
|
||||||
|
$this->assertEquals($customer_userdata['documentroot'] . 'test/', $result['path']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCustomerDirOptionsGetNotFound()
|
||||||
|
{
|
||||||
|
global $admin_userdata;
|
||||||
|
|
||||||
|
// get customer
|
||||||
|
$json_result = Customers::getLocal($admin_userdata, array(
|
||||||
|
'loginname' => 'test1'
|
||||||
|
))->get();
|
||||||
|
$customer_userdata = json_decode($json_result, true)['data'];
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'id' => 1337
|
||||||
|
];
|
||||||
|
$this->expectExceptionMessage("Directory option with id #1337 could not be found");
|
||||||
|
DirOptions::getLocal($admin_userdata, $data)->get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCustomerDirOptionsUpdate()
|
||||||
|
{
|
||||||
|
global $admin_userdata;
|
||||||
|
|
||||||
|
// get customer
|
||||||
|
$json_result = Customers::getLocal($admin_userdata, array(
|
||||||
|
'loginname' => 'test1'
|
||||||
|
))->get();
|
||||||
|
$customer_userdata = json_decode($json_result, true)['data'];
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'id' => 1,
|
||||||
|
'options_indexes' => 0,
|
||||||
|
'options_cgi' => 0,
|
||||||
|
'error403path' => '/403-test.html'
|
||||||
|
];
|
||||||
|
$json_result = DirOptions::getLocal($customer_userdata, $data)->update();
|
||||||
|
$result = json_decode($json_result, true)['data'];
|
||||||
|
$this->assertEquals($customer_userdata['documentroot'] . 'test/', $result['path']);
|
||||||
|
$this->assertEquals('0', $result['options_cgi']);
|
||||||
|
$this->assertEquals('/403-test.html', $result['error403path']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAdminDirOptionsList()
|
||||||
|
{
|
||||||
|
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 = DirOptions::getLocal($admin_userdata)->listing();
|
||||||
|
$result = json_decode($json_result, true)['data'];
|
||||||
|
$this->assertEquals(1, $result['count']);
|
||||||
|
$this->assertEquals($customer_userdata['documentroot'] . 'test/', $result['list'][0]['path']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testAdminDirOptionsList
|
||||||
|
*/
|
||||||
|
public function testCustomerDirOptionsDelete()
|
||||||
|
{
|
||||||
|
global $admin_userdata;
|
||||||
|
|
||||||
|
// get customer
|
||||||
|
$json_result = Customers::getLocal($admin_userdata, array(
|
||||||
|
'loginname' => 'test1'
|
||||||
|
))->get();
|
||||||
|
$customer_userdata = json_decode($json_result, true)['data'];
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'id' => 1
|
||||||
|
];
|
||||||
|
$json_result = DirOptions::getLocal($customer_userdata, $data)->delete();
|
||||||
|
$result = json_decode($json_result, true)['data'];
|
||||||
|
$this->assertEquals($customer_userdata['documentroot'] . 'test/', $result['path']);
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'id' => 1
|
||||||
|
];
|
||||||
|
$this->expectExceptionMessage("Directory option with id #1 could not be found");
|
||||||
|
DirOptions::getLocal($admin_userdata, $data)->get();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,7 +6,7 @@ use PHPUnit\Framework\TestCase;
|
|||||||
* @covers ApiParameter
|
* @covers ApiParameter
|
||||||
* @covers DirProtections
|
* @covers DirProtections
|
||||||
*/
|
*/
|
||||||
class ExtrasTest extends TestCase
|
class DirProtectionsTest extends TestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
public function testCustomerDirProtectionsAdd()
|
public function testCustomerDirProtectionsAdd()
|
||||||
Reference in New Issue
Block a user