mirror of
https://github.com/FOSSBilling/FOSSBilling.git
synced 2026-12-04 22:24:42 +09:00
* 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
170 lines
5.7 KiB
PHP
170 lines
5.7 KiB
PHP
<?php
|
|
|
|
namespace Box\Tests\Mod\Activity\Api;
|
|
|
|
class AdminTest extends \BBTestCase
|
|
{
|
|
public function testLogGetList()
|
|
{
|
|
$simpleResultArr = [
|
|
'list' => [
|
|
[
|
|
'id' => 1,
|
|
'staff_id' => 1,
|
|
'staff_name' => 'Joe',
|
|
'staff_email' => 'example@example.com',
|
|
],
|
|
],
|
|
];
|
|
$paginatorMock = $this->getMockBuilder('\Box_Pagination')->disableOriginalConstructor()->getMock();
|
|
$paginatorMock->expects($this->atLeastOnce())
|
|
->method('getSimpleResultSet')
|
|
->willReturn($simpleResultArr);
|
|
|
|
$service = $this->getMockBuilder('\\' . \Box\Mod\Activity\Service::class)->getMock();
|
|
$service->expects($this->atLeastOnce())
|
|
->method('getSearchQuery')
|
|
->willReturn('String');
|
|
|
|
$model = new \Model_ActivitySystem();
|
|
$model->loadBean(new \DummyBean());
|
|
|
|
$di = new \Pimple\Container();
|
|
$di['pager'] = $paginatorMock;
|
|
$di['mod_service'] = $di->protect(fn () => $service);
|
|
|
|
$api = new \Api_Handler(new \Model_Admin());
|
|
$api->setDi($di);
|
|
$di['api_admin'] = $api;
|
|
|
|
$activity = new \Box\Mod\Activity\Api\Admin();
|
|
$activity->setDi($di);
|
|
$activity->setService($service);
|
|
$activity->log_get_list([]);
|
|
}
|
|
|
|
public function testLogGetListItemUserClient()
|
|
{
|
|
$simpleResultArr = [
|
|
'list' => [
|
|
[
|
|
'id' => 1,
|
|
'client_id' => 1,
|
|
'client_name' => 'Joe',
|
|
'client_email' => 'example@example.com',
|
|
],
|
|
],
|
|
];
|
|
$paginatorMock = $this->getMockBuilder('\Box_Pagination')->disableOriginalConstructor()->getMock();
|
|
$paginatorMock->expects($this->atLeastOnce())
|
|
->method('getSimpleResultSet')
|
|
->willReturn($simpleResultArr);
|
|
|
|
$service = $this->getMockBuilder('\\' . \Box\Mod\Activity\Service::class)->getMock();
|
|
$service->expects($this->atLeastOnce())
|
|
->method('getSearchQuery')
|
|
->willReturn('String');
|
|
|
|
$model = new \Model_ActivitySystem();
|
|
$model->loadBean(new \DummyBean());
|
|
|
|
$di = new \Pimple\Container();
|
|
$di['pager'] = $paginatorMock;
|
|
$di['mod_service'] = $di->protect(fn () => $service);
|
|
|
|
$api = new \Api_Handler(new \Model_Admin());
|
|
$api->setDi($di);
|
|
$di['api_admin'] = $api;
|
|
|
|
$activity = new \Box\Mod\Activity\Api\Admin();
|
|
$activity->setDi($di);
|
|
$activity->setService($service);
|
|
$activity->log_get_list([]);
|
|
}
|
|
|
|
public function testlogEmptyMParam()
|
|
{
|
|
$di = new \Pimple\Container();
|
|
|
|
$activity = new \Box\Mod\Activity\Api\Admin();
|
|
$activity->setDi($di);
|
|
$result = $activity->log([]);
|
|
$this->assertFalse($result, 'Empty array key m');
|
|
}
|
|
|
|
public function testlogEmail()
|
|
{
|
|
$service = $this->getMockBuilder('\\' . \Box\Mod\Activity\Service::class)->onlyMethods(['logEmail'])->getMock();
|
|
$service->expects($this->atLeastOnce())
|
|
->method('logEmail')
|
|
->willReturn(true);
|
|
|
|
$di = new \Pimple\Container();
|
|
|
|
$adminApi = new \Box\Mod\Activity\Api\Admin();
|
|
$adminApi->setService($service);
|
|
$adminApi->setDi($di);
|
|
$result = $adminApi->log_email(['subject' => 'Proper subject']);
|
|
|
|
$this->assertTrue($result, 'Log_email did not returned true');
|
|
}
|
|
|
|
public function testlogEmailWithoutSubject()
|
|
{
|
|
$activity = new \Box\Mod\Activity\Api\Admin();
|
|
$result = $activity->log_email([]);
|
|
$this->assertFalse($result);
|
|
}
|
|
|
|
public function testlogDelete()
|
|
{
|
|
$di = new \Pimple\Container();
|
|
|
|
$databaseMock = $this->getMockBuilder('Box_Database')->getMock();
|
|
$databaseMock->expects($this->atLeastOnce())->
|
|
method('getExistingModelById')->
|
|
willReturn(new \Model_ActivitySystem());
|
|
|
|
$databaseMock->expects($this->atLeastOnce())->
|
|
method('trash');
|
|
|
|
$serviceMock = $this->getMockBuilder('\Box\Mod\Staff\Service')->onlyMethods(['hasPermission'])->getMock();
|
|
$serviceMock->expects($this->atLeastOnce())
|
|
->method('hasPermission')
|
|
->willReturn(true);
|
|
|
|
$di['db'] = $databaseMock;
|
|
$validatorMock = $this->getMockBuilder('\\' . \FOSSBilling\Validate::class)->disableOriginalConstructor()->getMock();
|
|
$validatorMock->expects($this->atLeastOnce())
|
|
->method('checkRequiredParamsForArray')
|
|
->willReturn(null);
|
|
$di['validator'] = $validatorMock;
|
|
|
|
$di['mod_service'] = $di->protect(fn () => $serviceMock);
|
|
|
|
$activity = new \Box\Mod\Activity\Api\Admin();
|
|
$activity->setDi($di);
|
|
|
|
$result = $activity->log_delete(['id' => 1]);
|
|
$this->assertTrue($result);
|
|
}
|
|
|
|
public function testBatchDelete()
|
|
{
|
|
$activityMock = $this->getMockBuilder('\\' . \Box\Mod\Activity\Api\Admin::class)->onlyMethods(['log_delete'])->getMock();
|
|
$activityMock->expects($this->atLeastOnce())->method('log_delete')->willReturn(true);
|
|
|
|
$validatorMock = $this->getMockBuilder('\\' . \FOSSBilling\Validate::class)->disableOriginalConstructor()->getMock();
|
|
$validatorMock->expects($this->atLeastOnce())
|
|
->method('checkRequiredParamsForArray')
|
|
->willReturn(null);
|
|
|
|
$di = new \Pimple\Container();
|
|
$di['validator'] = $validatorMock;
|
|
$activityMock->setDi($di);
|
|
|
|
$result = $activityMock->batch_delete(['ids' => [1, 2, 3]]);
|
|
$this->assertTrue($result);
|
|
}
|
|
}
|