Files
FOSSBilling/tests/modules/System/Api/AdminTest.php
T
Belle Aerni 5bd3ff7751 Begin reworking permission management (#1545)
* Begin reworking permission management

* Tests

* This.. tested functionality that didn't exist in the app

* Fixes

* Added permission checks for the system module

* Implemented extension settings permission

The "extension" settings page will now check for permission before allowing a staff member to even visit the settings page for a client.

FOSSBilling will also check for permission before saving a new config so the API can't be used to bypass this limitation.

I also removed a test as it was checking a function which only ever had one possible return value, no point in updating it to work with this PR

* This should fix the test

* I got a little mixed up with that, but this should work

* Fixed the tests

* Implemented give all & revoke all buttons

* Implemented more, enhancements, & bugfix

* Rename function

* Fix tests

* Optimize, address comment

* Now let's make the tests happy again

* Deduplicate code, cleanup a bit

* Bugfix

* Added selectbox support to the front-end

* Quick bugfix

* Fix issue PHPStan detected

* Bug fix

* Improved page layout & styling

* Implemented more checks

* Fix the tests

* Update error.html.twig

* Cleanup

* Fix the tests

* Updated the design to be more space efficient

* Don't list module access when always given

* Updated the exception type

* setMethod -> onlyMethods

* I donno how that got goofed up

* Fix the test, email module should always be accessible

* Removed the broken test

It's.. not really checking anything anyways. Just that the `extension` module is in a hardcoded array.
2023-11-21 16:18:53 -08:00

168 lines
4.6 KiB
PHP

<?php
namespace Box\Mod\System\Api;
class AdminTest extends \BBTestCase {
/**
* @var \Box\Mod\System\Api\Admin
*/
protected $api = null;
public function setup(): void
{
$this->api= new \Box\Mod\System\Api\Admin();
}
public function testgetDi()
{
$di = new \Pimple\Container();
$this->api->setDi($di);
$getDi = $this->api->getDi();
$this->assertEquals($di, $getDi);
}
public function testget_params()
{
$data = array(
);
$serviceMock = $this->getMockBuilder('\\' . \Box\Mod\System\Service::class)->getMock();
$serviceMock->expects($this->atLeastOnce())
->method('getParams')
->will($this->returnValue(array()));
$this->api->setService($serviceMock);
$result = $this->api->get_params($data);
$this->assertIsArray($result);
}
public function testupdate_params()
{
$data = array(
);
$serviceMock = $this->getMockBuilder('\\' . \Box\Mod\System\Service::class)->getMock();
$serviceMock->expects($this->atLeastOnce())
->method('updateParams')
->will($this->returnValue(true));
$this->api->setService($serviceMock);
$result = $this->api->update_params($data);
$this->assertIsBool($result);
$this->assertTrue($result);
}
public function testmessages()
{
$data = array(
);
$di = new \Pimple\Container();
$this->api->setDi($di);
$serviceMock = $this->getMockBuilder('\\' . \Box\Mod\System\Service::class)->getMock();
$serviceMock->expects($this->atLeastOnce())
->method('getMessages')
->will($this->returnValue(array()));
$this->api->setService($serviceMock);
$result = $this->api->messages($data);
$this->assertIsArray($result);
}
public function testtemplate_exists()
{
$data = array(
'file' => 'testing.txt',
);
$serviceMock = $this->getMockBuilder('\\' . \Box\Mod\System\Service::class)->getMock();
$serviceMock->expects($this->atLeastOnce())
->method('templateExists')
->will($this->returnValue(true));
$this->api->setService($serviceMock);
$result = $this->api->template_exists($data);
$this->assertIsBool($result);
$this->assertTrue($result);
}
public function teststring_render()
{
$data = array(
'_tpl' => 'default'
);
$serviceMock = $this->getMockBuilder('\\' . \Box\Mod\System\Service::class)->getMock();
$serviceMock->expects($this->atLeastOnce())
->method('renderString')
->will($this->returnValue('returnStringType'));
$di = new \Pimple\Container();
$this->api->setDi($di);
$this->api->setService($serviceMock);
$result = $this->api->string_render($data);
$this->assertIsString($result);
}
public function testenv()
{
$data = array();
$serviceMock = $this->getMockBuilder('\\' . \Box\Mod\System\Service::class)->getMock();
$serviceMock->expects($this->atLeastOnce())
->method('getEnv')
->will($this->returnValue(array()));
$di = new \Pimple\Container();
$this->api->setDi($di);
$this->api->setService($serviceMock);
$result = $this->api->env($data);
$this->assertIsArray($result);
}
public function testis_allowed()
{
$data = array(
'mod' => 'extension',
);
$staffServiceMock = $this->getMockBuilder('\\' . \Box\Mod\Staff\Service::class)->getMock();
$staffServiceMock->expects($this->atLeastOnce())
->method('hasPermission')
->will($this->returnValue(true));
$validatorMock = $this->getMockBuilder('\\' . \FOSSBilling\Validate::class)->disableOriginalConstructor()->getMock();
$validatorMock->expects($this->atLeastOnce())
->method('checkRequiredParamsForArray')
->will($this->returnValue(null));
$di = new \Pimple\Container();
$di['mod_service'] = $di->protect(function ($serviceName) use ($staffServiceMock) {
if ($serviceName == 'Staff') {
return $staffServiceMock;
}
return false;
});
$di['validator'] = $validatorMock;
$this->api->setDi($di);
$result = $this->api->is_allowed($data);
$this->assertIsBool($result);
$this->assertTrue($result);
}
}