Files
FOSSBilling/tests-legacy/modules/System/Api/AdminTest.php
T
Belle Aerni ccc97a3ec9 Initial implementation of CI against a live FOSSBilling Install (#2067)
* Rename tests to tests-legacy

* Groundwork for live tests

* Somewhat working tests on a live instance

* Hmmmmmm

* Fix

* Fixed the other bug

* Added a handful of various tests

* Typos, all these are admin endpoints

* Bypass this check for testing envs

* Disable it for now

* Mini cleanup

* Cleanup from debugging, ran PHP-CS-Fixer
2024-01-14 22:51:32 -08:00

167 lines
4.3 KiB
PHP

<?php
namespace Box\Mod\System\Api;
class AdminTest extends \BBTestCase
{
/**
* @var Admin
*/
protected $api;
public function setup(): void
{
$this->api = new Admin();
}
public function testgetDi()
{
$di = new \Pimple\Container();
$this->api->setDi($di);
$getDi = $this->api->getDi();
$this->assertEquals($di, $getDi);
}
public function testgetParams()
{
$data = [
];
$serviceMock = $this->getMockBuilder('\\' . \Box\Mod\System\Service::class)->getMock();
$serviceMock->expects($this->atLeastOnce())
->method('getParams')
->willReturn([]);
$this->api->setService($serviceMock);
$result = $this->api->get_params($data);
$this->assertIsArray($result);
}
public function testupdateParams()
{
$data = [
];
$serviceMock = $this->getMockBuilder('\\' . \Box\Mod\System\Service::class)->getMock();
$serviceMock->expects($this->atLeastOnce())
->method('updateParams')
->willReturn(true);
$this->api->setService($serviceMock);
$result = $this->api->update_params($data);
$this->assertIsBool($result);
$this->assertTrue($result);
}
public function testmessages()
{
$data = [
];
$di = new \Pimple\Container();
$this->api->setDi($di);
$serviceMock = $this->getMockBuilder('\\' . \Box\Mod\System\Service::class)->getMock();
$serviceMock->expects($this->atLeastOnce())
->method('getMessages')
->willReturn([]);
$this->api->setService($serviceMock);
$result = $this->api->messages($data);
$this->assertIsArray($result);
}
public function testtemplateExists()
{
$data = [
'file' => 'testing.txt',
];
$serviceMock = $this->getMockBuilder('\\' . \Box\Mod\System\Service::class)->getMock();
$serviceMock->expects($this->atLeastOnce())
->method('templateExists')
->willReturn(true);
$this->api->setService($serviceMock);
$result = $this->api->template_exists($data);
$this->assertIsBool($result);
$this->assertTrue($result);
}
public function teststringRender()
{
$data = [
'_tpl' => 'default',
];
$serviceMock = $this->getMockBuilder('\\' . \Box\Mod\System\Service::class)->getMock();
$serviceMock->expects($this->atLeastOnce())
->method('renderString')
->willReturn('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 = [];
$serviceMock = $this->getMockBuilder('\\' . \Box\Mod\System\Service::class)->getMock();
$serviceMock->expects($this->atLeastOnce())
->method('getEnv')
->willReturn([]);
$di = new \Pimple\Container();
$this->api->setDi($di);
$this->api->setService($serviceMock);
$result = $this->api->env($data);
$this->assertIsArray($result);
}
public function testisAllowed()
{
$data = [
'mod' => 'extension',
];
$staffServiceMock = $this->getMockBuilder('\\' . \Box\Mod\Staff\Service::class)->getMock();
$staffServiceMock->expects($this->atLeastOnce())
->method('hasPermission')
->willReturn(true);
$validatorMock = $this->getMockBuilder('\\' . \FOSSBilling\Validate::class)->disableOriginalConstructor()->getMock();
$validatorMock->expects($this->atLeastOnce())
->method('checkRequiredParamsForArray')
->willReturn(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);
}
}