added unit-tests for DirOptions
Signed-off-by: Michael Kaufmann (d00p) <d00p@froxlor.org>
This commit is contained in:
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user