Files
FOSSBilling/tests/modules/Extension/Api/GuestTest.php
T
Belle Aerni 50043e6211 Run Rector against our tests (#1761)
* Update rector config to include tests

* Run Rector against the tests

* Delete test-results

* Update .gitignore

* Correctly set the PHP min to 8.1, split the configs

* Corrected PHPDoc

* Deleted tests we can't really get to pass

PHPunit is hard-coded to fail when a class has a return type of `never`, which is the correct return type of our redirect function (and rightfully so).

No way to disable the exception as far as we can tell
2023-11-11 18:41:09 +00:00

119 lines
3.0 KiB
PHP

<?php
namespace Box\Mod\Extension\Api;
class GuestTest extends \BBTestCase {
/**
* @var \Box\Mod\Extension\Service
*/
protected $service = null;
/**
* @var \Box\Mod\Extension\Api\Guest
*/
protected $api = null;
public function setup(): void
{
$this->service = new \Box\Mod\Extension\Service();
$this->api = new \Box\Mod\Extension\Api\Guest();
}
public function testgetDi()
{
$di = new \Pimple\Container();
$this->api->setDi($di);
$getDi = $this->api->getDi();
$this->assertEquals($di, $getDi);
}
public static function is_onProvider()
{
return array(
array(
array('mod' => 'testModule'),
array(),
),
array(
array(
'id' => 'extensionId',
'type' => 'extensionType',
),
array()
),
);
}
#[\PHPUnit\Framework\Attributes\DataProvider('is_onProvider')]
public function testis_on($data, $expected)
{
$serviceMock = $this->getMockBuilder('\\' . \Box\Mod\Extension\Service::class)->getMock();
$serviceMock->expects($this->atLeastOnce())
->method('isExtensionActive')
->will($this->returnValue(array()));
$this->api->setService($serviceMock);
$result = $this->api->is_on($data);
$this->assertEquals($expected, $result);
}
public function testis_onInvalidDataArray()
{
$data = array();
$result = $this->api->is_on($data);
$this->assertTrue($result);
}
public function testtheme()
{
$themeServiceMock = $this->getMockBuilder('\\' . \Box\Mod\Theme\Service::class)->getMock();
$themeServiceMock->expects($this->atLeastOnce())
->method('getThemeConfig')
->will($this->returnValue(array()));
$di = new \Pimple\Container();
$di['mod_service'] = $di->protect(fn($name) => $themeServiceMock);
$this->api->setDi($di);
$result = $this->api->theme();
$this->assertIsArray($result);
}
public function testsettings()
{
$data['ext'] = 'testExtension';
$serviceMock = $this->getMockBuilder('\\' . \Box\Mod\Extension\Service::class)->getMock();
$serviceMock->expects($this->atLeastOnce())
->method('getConfig')
->will($this->returnValue(array()));
$this->api->setService($serviceMock);
$result = $this->api->settings($data);
$this->assertIsArray($result);
}
public function testsettingsExtExtension()
{
$data = array();
$this->expectException(\FOSSBilling\Exception::class);
$this->expectExceptionMessage('Parameter ext is missing');
$this->api->settings($data);
}
public function testlanguages()
{
$di = new \Pimple\Container();
$this->api->setDi($di);
$result = $this->api->languages();
$this->assertIsArray($result);
}
}