mirror of
https://github.com/FOSSBilling/FOSSBilling.git
synced 2026-12-06 15:14:20 +09:00
* Adjust admin alerts and installer warning * Make dashboard cards full-height and align badges * Split dashboard cards into partials and add AJAX * Replace status badges with ribbon elements * Revamp activity panel layout and responsiveness * Adjust dashboard card spacing and styles * Style dashboard links and adjust chart heights * Back-to-top: update classes and styles * Fix client admin UI labels and flags * Improve API response parsing and errors * Mark action columns no-sort, add table-hover * Update table classes for hover and wrapping * Refactor admin templates to card-header layout * Update admin templates layout and semantics * Tidy admin templates; remove tabs, update notice * Standardize admin alert styles and messages * Handle null/empty status in status_name macro * Validate resolved renewal price before invoicing * Keep IP actions inline in activity table * Right-align activity pagination controls * Align pagination and export buttons in admin lists * Improve admin pagination & per-page defaults * Extract record selector into partial * Add tab deep-linking and URL hash persistence * Refactor search controls & capitalize 'One Time' * Refactor client search filters and toggle state * Refactor activity filters UI and tomselect styling * Redesign admin filters; capitalize 'On Hold' * Revamp admin filter panels (Invoice & Support) * Group search clause in Massmailer query * Add filters and expanded search for pages/gateways * Add filter panels, refine search logic, tests * Add advanced search filters for activity modules * Add structured filters, date/ip search & tests * Add Email queue filters and admin tab * Add collapsible filter panel to Staff settings * Refactor badges to use shared macros * Add massmailer statuses & boolean badges * Add search icon and refine search input layout * Update admin templates layout and markup * Use modals for creating clients/groups * Centralize tab header action buttons * Centralize toolbar actions; add Order modal * Bump Composer dependencies (lockfile) * Capitalize 'One Time' payment label * Return raw API body; use button for search * Wrap search button in input-group-text * Make search max width configurable * Fix malformed aria-label Twig expression in layout_default.html.twig Agent-Logs-Url: https://github.com/FOSSBilling/FOSSBilling/sessions/c8db6ba9-bda4-413a-989f-e4777e06bd12 Co-authored-by: admdly <2807620+admdly@users.noreply.github.com> * Fix XSS risk in updateExternalIP: append IP via createTextNode instead of innerHTML concat Agent-Logs-Url: https://github.com/FOSSBilling/FOSSBilling/sessions/0c435e52-1784-4466-a8dc-c41e12443a6f Co-authored-by: admdly <2807620+admdly@users.noreply.github.com> * Refactor New Client modal layout and styles * Limit and style phone country code field * Use `country_names` helper and `country_name` filter * Use Symfony Intl for currencies & locales * Use Symfony Intl for currencies; drop built-in country lists * Refactor Currency module API, entity and service * Remove system checkLimits usages from modules and tests * Remove `currency.title` column and update APIs * Add inputmode and maxlength to cspell dictionary * Fix dropdown toggle accessibility: use button instead of anchor Agent-Logs-Url: https://github.com/FOSSBilling/FOSSBilling/sessions/b7f9474b-1988-4c08-aec0-f8991edfea71 Co-authored-by: admdly <2807620+admdly@users.noreply.github.com> * Improve multi-currency handling and installer * Log currency code when changing cart currency * Use removeCurrency in Admin API and update tests * Use Intl currency symbols and fraction digits * Use currency filters in templates * Rename currency title to name and update schema * Remove deprecated Service::getLanguages * Capitalize system permission labels and fix messages * Use Symfony Countries and remove phone codes list * Validate country codes; use country select * Set fb_locale cookie and fix admin locale display * Validate locales and add default locale selector * Use Locales::getNames; tweak language selector CSS * Tweak header spacing and make nav links icon-only * Localize client login texts * Add phone country-code attrs and styles * Center .modal-dialog in two themes * Add phone_codes API to list calling codes * Make form the modal-content wrapper * Move create forms to Bootstrap modals * Convert new-item tabs to modals in admin UI * Revamp admin UI, embed snippets & modal * Revamp admin settings UI and templates * Revamp Formbuilder & Redirect admin UIs * Add 'Segoe' and 'minmax' to cspell dictionary * Rename warning() to warn() in test logger * Refactor admin templates to card-based layout * Expose initAvatars globally and scoped init * Add 'view' permissions and enforce checks * Refactor Servicehosting admin UI and scripts * Add staff permission checks and module permissions * Refactor admin templates layout and forms * Add staff permission checks and module perms * Add staff permission checks and module perms * Refactor admin Twig templates and UI * Refactor client admin UI to use summary/form cards * Refactor admin invoice/subscription/transaction templates * Refactor Order admin UI; fix country labels * Refactor admin templates and add IP country filter * Add 'view' permissions and checks to admin APIs * Use detail/related partials in admin templates * Refactor admin product templates to use partials * Add endembed to cspell ignoreWords to fix spellcheck CI failure Agent-Logs-Url: https://github.com/FOSSBilling/FOSSBilling/sessions/e8973bef-7364-4b30-8dd8-13701ca15c5d Co-authored-by: admdly <2807620+admdly@users.noreply.github.com> * Refactor admin templates to use common partials * Validate order status, add permission checks * Center form buttons and add horizontal padding * Introduce createAdminApi and BBTestCaseContainer * Refactor admin UI templates and forms * Run intl compression after composer install * Disable provenance in buildx outputs * Revamp admin templates for UI and previews * Refactor admin templates, pricing UI & styles * Refactor admin invoice sidebar and SEO settings UI * Use minor currency units, country list & API fixes * Rename language selector class to locale-selector --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: admdly <2807620+admdly@users.noreply.github.com>
1904 lines
60 KiB
PHP
1904 lines
60 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Box\Mod\Staff;
|
|
|
|
use PHPUnit\Framework\Attributes\DataProvider;
|
|
use PHPUnit\Framework\Attributes\Group;
|
|
|
|
class PdoMock extends \PDO
|
|
{
|
|
public function __construct()
|
|
{
|
|
}
|
|
}
|
|
|
|
class PdoStatementMock extends \PDOStatement
|
|
{
|
|
public function __construct()
|
|
{
|
|
}
|
|
}
|
|
|
|
#[Group('Core')]
|
|
final class ServiceTest extends \BBTestCase
|
|
{
|
|
public function testLogin(): void
|
|
{
|
|
$email = 'email@domain.com';
|
|
$password = 'pass';
|
|
$ip = '127.0.0.1';
|
|
|
|
$admin = new \Model_Admin();
|
|
$admin->loadBean(new \DummyBean());
|
|
$admin->id = 1;
|
|
$admin->email = $email;
|
|
$admin->name = 'Admin';
|
|
$admin->role = 'admin';
|
|
|
|
$emMock = $this->getMockBuilder('\Box_EventManager')
|
|
->getMock();
|
|
$emMock->expects($this->atLeastOnce())
|
|
->method('fire')
|
|
->willReturn(true);
|
|
|
|
$dbMock = $this->getMockBuilder('\Box_Database')
|
|
->getMock();
|
|
$dbMock->expects($this->atLeastOnce())
|
|
->method('findOne')
|
|
->willReturn($admin);
|
|
|
|
$sessionMock = $this->getMockBuilder(\FOSSBilling\Session::class)
|
|
->disableOriginalConstructor()
|
|
->getMock();
|
|
$sessionMock->expects($this->once())
|
|
->method('regenerateId');
|
|
$sessionMock->expects($this->atLeastOnce())
|
|
->method('set');
|
|
|
|
$authMock = $this->getMockBuilder('\Box_Authorization')->disableOriginalConstructor()->getMock();
|
|
$authMock->expects($this->atLeastOnce())
|
|
->method('authorizeUser')
|
|
->with($admin, $password)
|
|
->willReturn($admin);
|
|
|
|
$di = $this->getDi();
|
|
$di['events_manager'] = $emMock;
|
|
$di['db'] = $dbMock;
|
|
$di['session'] = $sessionMock;
|
|
$di['logger'] = new \Box_Log();
|
|
$di['auth'] = $authMock;
|
|
|
|
$service = new Service();
|
|
$service->setDi($di);
|
|
|
|
$result = $service->login($email, $password, $ip);
|
|
|
|
$expected = [
|
|
'id' => 1,
|
|
'email' => $email,
|
|
'name' => 'Admin',
|
|
'role' => 'admin',
|
|
];
|
|
|
|
$this->assertEquals($expected, $result);
|
|
}
|
|
|
|
public function testLoginException(): void
|
|
{
|
|
$email = 'email@domain.com';
|
|
$password = 'pass';
|
|
$ip = '127.0.0.1';
|
|
|
|
$emMock = $this->getMockBuilder('\Box_EventManager')
|
|
->getMock();
|
|
$emMock->expects($this->atLeastOnce())
|
|
->method('fire')
|
|
->willReturn(true);
|
|
|
|
$dbMock = $this->getMockBuilder('\Box_Database')
|
|
->getMock();
|
|
$dbMock->expects($this->atLeastOnce())
|
|
->method('findOne')
|
|
->willReturn(null);
|
|
|
|
$authMock = $this->getMockBuilder('\Box_Authorization')->disableOriginalConstructor()->getMock();
|
|
$authMock->expects($this->atLeastOnce())
|
|
->method('authorizeUser')
|
|
->with(null, $password)
|
|
->willReturn(null);
|
|
|
|
$di = $this->getDi();
|
|
$di['events_manager'] = $emMock;
|
|
$di['db'] = $dbMock;
|
|
$di['auth'] = $authMock;
|
|
|
|
$service = new Service();
|
|
$service->setDi($di);
|
|
|
|
$this->expectException(\FOSSBilling\Exception::class);
|
|
$this->expectExceptionCode(403);
|
|
$this->expectExceptionMessage('Check your login details');
|
|
$service->login($email, $password, $ip);
|
|
}
|
|
|
|
public function testHasPermissionRoleAdmin(): void
|
|
{
|
|
$member = new \Model_Admin();
|
|
$member->loadBean(new \DummyBean());
|
|
$member->role = 'admin';
|
|
|
|
$service = new Service();
|
|
|
|
$result = $service->hasPermission($member, 'example');
|
|
$this->assertTrue($result);
|
|
}
|
|
|
|
public function testHasPermissionRoleStaffWithEmptyPerms(): void
|
|
{
|
|
$member = new \Model_Admin();
|
|
$member->loadBean(new \DummyBean());
|
|
$member->role = 'staff';
|
|
|
|
$serviceMock = $this->getMockBuilder(Service::class)
|
|
->onlyMethods(['getPermissions'])
|
|
->getMock();
|
|
|
|
$serviceMock->expects($this->atLeastOnce())
|
|
->method('getPermissions');
|
|
|
|
$extensionServiceMock = $this->getMockBuilder(\Box\Mod\Extension\Service::class)->onlyMethods(['getSpecificModulePermissions'])->getMock();
|
|
$extensionServiceMock->expects($this->atLeastOnce())
|
|
->method('getSpecificModulePermissions')
|
|
->willReturn([]);
|
|
|
|
$di = $this->getDi();
|
|
$di['mod_service'] = $di->protect(fn (): \PHPUnit\Framework\MockObject\MockObject => $extensionServiceMock);
|
|
|
|
$serviceMock->setDi($di);
|
|
|
|
$result = $serviceMock->hasPermission($member, 'example');
|
|
$this->assertFalse($result);
|
|
}
|
|
|
|
public function testHasPermissionRoleStaffWithNoPerm(): void
|
|
{
|
|
$member = new \Model_Admin();
|
|
$member->loadBean(new \DummyBean());
|
|
$member->role = 'staff';
|
|
|
|
$serviceMock = $this->getMockBuilder(Service::class)
|
|
->onlyMethods(['getPermissions'])
|
|
->getMock();
|
|
|
|
$serviceMock->expects($this->atLeastOnce())
|
|
->method('getPermissions')
|
|
->willReturn(['cart' => [], 'client' => []]);
|
|
|
|
$extensionServiceMock = $this->getMockBuilder(\Box\Mod\Extension\Service::class)->onlyMethods(['getSpecificModulePermissions'])->getMock();
|
|
$extensionServiceMock->expects($this->atLeastOnce())
|
|
->method('getSpecificModulePermissions')
|
|
->willReturn([]);
|
|
|
|
$di = $this->getDi();
|
|
$di['mod_service'] = $di->protect(fn (): \PHPUnit\Framework\MockObject\MockObject => $extensionServiceMock);
|
|
|
|
$serviceMock->setDi($di);
|
|
|
|
$result = $serviceMock->hasPermission($member, 'example');
|
|
$this->assertFalse($result);
|
|
}
|
|
|
|
public function testHasPermissionRoleStaffWithNoMethodPerm(): void
|
|
{
|
|
$member = new \Model_Admin();
|
|
$member->loadBean(new \DummyBean());
|
|
$member->role = 'staff';
|
|
|
|
$serviceMock = $this->getMockBuilder(Service::class)
|
|
->onlyMethods(['getPermissions'])
|
|
->getMock();
|
|
|
|
$serviceMock->expects($this->atLeastOnce())
|
|
->method('getPermissions')
|
|
->willReturn(['example' => [], 'client' => []]);
|
|
|
|
$extensionServiceMock = $this->getMockBuilder(\Box\Mod\Extension\Service::class)->onlyMethods(['getSpecificModulePermissions'])->getMock();
|
|
$extensionServiceMock->expects($this->atLeastOnce())
|
|
->method('getSpecificModulePermissions')
|
|
->willReturn([]);
|
|
|
|
$di = $this->getDi();
|
|
$di['mod_service'] = $di->protect(fn (): \PHPUnit\Framework\MockObject\MockObject => $extensionServiceMock);
|
|
|
|
$serviceMock->setDi($di);
|
|
|
|
$result = $serviceMock->hasPermission($member, 'example', 'get_list');
|
|
$this->assertFalse($result);
|
|
}
|
|
|
|
public function testHasPermissionRoleStaffWithWildcardPermissionsForNewModule(): void
|
|
{
|
|
$member = new \Model_Admin();
|
|
$member->loadBean(new \DummyBean());
|
|
$member->role = 'staff';
|
|
|
|
$serviceMock = $this->getMockBuilder(Service::class)
|
|
->onlyMethods(['getPermissions'])
|
|
->getMock();
|
|
|
|
$serviceMock->expects($this->atLeastOnce())
|
|
->method('getPermissions')
|
|
->willReturn([
|
|
'default' => ['all' => 1],
|
|
'extension' => ['access' => 1, 'manage_extensions' => 1],
|
|
]);
|
|
|
|
$extensionServiceMock = $this->getMockBuilder(\Box\Mod\Extension\Service::class)->onlyMethods(['getSpecificModulePermissions'])->getMock();
|
|
$extensionServiceMock->expects($this->atLeastOnce())
|
|
->method('getSpecificModulePermissions')
|
|
->willReturn(['manage_settings' => ['type' => 'bool']]);
|
|
|
|
$di = $this->getDi();
|
|
$di['mod_service'] = $di->protect(fn (): \PHPUnit\Framework\MockObject\MockObject => $extensionServiceMock);
|
|
|
|
$serviceMock->setDi($di);
|
|
|
|
$this->assertTrue($serviceMock->hasPermission($member, 'massmailer'));
|
|
$this->assertTrue($serviceMock->hasPermission($member, 'massmailer', 'manage_settings'));
|
|
}
|
|
|
|
public function testOnAfterClientReplyTicket(): void
|
|
{
|
|
$eventMock = $this->getMockBuilder('\Box_Event')
|
|
->disableOriginalConstructor()
|
|
->getMock();
|
|
|
|
$supportServiceMock = $this->createMock(\Box\Mod\Support\Service::class);
|
|
$supportServiceMock->expects($this->atLeastOnce())
|
|
->method('getTicketById')
|
|
->willReturn(new \Model_SupportTicket());
|
|
$supportServiceMock->expects($this->atLeastOnce())
|
|
->method('toApiArray')
|
|
->willReturn([]);
|
|
|
|
$emailServiceMock = $this->createMock(\Box\Mod\Email\Service::class);
|
|
$emailServiceMock->expects($this->atLeastOnce())
|
|
->method('sendTemplate');
|
|
|
|
$eventMock->expects($this->atLeastOnce())
|
|
->method('getparameters')
|
|
->willReturn(['id' => random_int(1, 100)]);
|
|
|
|
$service = new Service();
|
|
|
|
$di = $this->getDi();
|
|
$di['mod_service'] = $di->protect(function ($name) use ($supportServiceMock, $emailServiceMock) {
|
|
if ($name == 'support') {
|
|
return $supportServiceMock;
|
|
}
|
|
if ($name == 'email') {
|
|
return $emailServiceMock;
|
|
}
|
|
});
|
|
|
|
$eventMock->expects($this->atLeastOnce())
|
|
->method('getDi')
|
|
->willReturn($di);
|
|
$service->setDi($di);
|
|
$service->onAfterClientReplyTicket($eventMock);
|
|
}
|
|
|
|
public function testOnAfterClientReplyTicketException(): void
|
|
{
|
|
$eventMock = $this->getMockBuilder('\Box_Event')
|
|
->disableOriginalConstructor()
|
|
->getMock();
|
|
|
|
$supportServiceMock = $this->createMock(\Box\Mod\Support\Service::class);
|
|
$supportServiceMock->expects($this->atLeastOnce())
|
|
->method('getTicketById')
|
|
->willReturn(new \Model_SupportTicket());
|
|
$supportServiceMock->expects($this->atLeastOnce())
|
|
->method('toApiArray')
|
|
->willReturn([]);
|
|
|
|
$emailServiceMock = $this->createMock(\Box\Mod\Email\Service::class);
|
|
$emailServiceMock->expects($this->atLeastOnce())
|
|
->method('sendTemplate')
|
|
->willThrowException(new \Exception('PHPunit controlled Exception'));
|
|
|
|
$eventMock->expects($this->atLeastOnce())
|
|
->method('getparameters')
|
|
->willReturn(['id' => random_int(1, 100)]);
|
|
|
|
$service = new Service();
|
|
|
|
$di = $this->getDi();
|
|
$di['mod_service'] = $di->protect(function ($name) use ($supportServiceMock, $emailServiceMock) {
|
|
if ($name == 'support') {
|
|
return $supportServiceMock;
|
|
}
|
|
if ($name == 'email') {
|
|
return $emailServiceMock;
|
|
}
|
|
});
|
|
|
|
$eventMock->expects($this->atLeastOnce())
|
|
->method('getDi')
|
|
->willReturn($di);
|
|
$service->setDi($di);
|
|
$service->onAfterClientReplyTicket($eventMock);
|
|
}
|
|
|
|
public function testOnAfterClientCloseTicket(): void
|
|
{
|
|
$eventMock = $this->getMockBuilder('\Box_Event')
|
|
->disableOriginalConstructor()
|
|
->getMock();
|
|
|
|
$supportServiceMock = $this->createMock(\Box\Mod\Support\Service::class);
|
|
$supportServiceMock->expects($this->atLeastOnce())
|
|
->method('getTicketById')
|
|
->willReturn(new \Model_SupportTicket());
|
|
$supportServiceMock->expects($this->atLeastOnce())
|
|
->method('toApiArray')
|
|
->willReturn([]);
|
|
|
|
$emailServiceMock = $this->createMock(\Box\Mod\Email\Service::class);
|
|
$emailServiceMock->expects($this->atLeastOnce())
|
|
->method('sendTemplate');
|
|
|
|
$eventMock->expects($this->atLeastOnce())
|
|
->method('getparameters')
|
|
->willReturn(['id' => random_int(1, 100)]);
|
|
|
|
$service = new Service();
|
|
|
|
$di = $this->getDi();
|
|
$di['mod_service'] = $di->protect(function ($name) use ($supportServiceMock, $emailServiceMock) {
|
|
if ($name == 'support') {
|
|
return $supportServiceMock;
|
|
}
|
|
if ($name == 'email') {
|
|
return $emailServiceMock;
|
|
}
|
|
});
|
|
|
|
$eventMock->expects($this->atLeastOnce())
|
|
->method('getDi')
|
|
->willReturn($di);
|
|
$service->setDi($di);
|
|
$service->onAfterClientCloseTicket($eventMock);
|
|
}
|
|
|
|
public function testOnAfterClientCloseTicketException(): void
|
|
{
|
|
$eventMock = $this->getMockBuilder('\Box_Event')
|
|
->disableOriginalConstructor()
|
|
->getMock();
|
|
|
|
$supportServiceMock = $this->createMock(\Box\Mod\Support\Service::class);
|
|
$supportServiceMock->expects($this->atLeastOnce())
|
|
->method('getTicketById')
|
|
->willReturn(new \Model_SupportTicket());
|
|
$supportServiceMock->expects($this->atLeastOnce())
|
|
->method('toApiArray')
|
|
->willReturn([]);
|
|
|
|
$emailServiceMock = $this->createMock(\Box\Mod\Email\Service::class);
|
|
$emailServiceMock->expects($this->atLeastOnce())
|
|
->method('sendTemplate')
|
|
->willThrowException(new \Exception('PHPunit controlled Exception'));
|
|
|
|
$eventMock->expects($this->atLeastOnce())
|
|
->method('getparameters')
|
|
->willReturn(['id' => random_int(1, 100)]);
|
|
|
|
$service = new Service();
|
|
|
|
$di = $this->getDi();
|
|
$di['mod_service'] = $di->protect(function ($name) use ($supportServiceMock, $emailServiceMock) {
|
|
if ($name == 'support') {
|
|
return $supportServiceMock;
|
|
}
|
|
if ($name == 'email') {
|
|
return $emailServiceMock;
|
|
}
|
|
});
|
|
|
|
$eventMock->expects($this->atLeastOnce())
|
|
->method('getDi')
|
|
->willReturn($di);
|
|
$service->setDi($di);
|
|
$service->onAfterClientCloseTicket($eventMock);
|
|
}
|
|
|
|
public function testOnAfterGuestPublicTicketOpen(): void
|
|
{
|
|
$eventMock = $this->getMockBuilder('\Box_Event')
|
|
->disableOriginalConstructor()
|
|
->getMock();
|
|
|
|
$supportServiceMock = $this->createMock(\Box\Mod\Support\Service::class);
|
|
$supportServiceMock->expects($this->atLeastOnce())
|
|
->method('getPublicTicketById')
|
|
->willReturn(new \Model_SupportPTicket());
|
|
$supportServiceMock->expects($this->atLeastOnce())
|
|
->method('publicToApiArray')
|
|
->willReturn([]);
|
|
|
|
$emailServiceMock = $this->createMock(\Box\Mod\Email\Service::class);
|
|
$emailServiceMock->expects($this->atLeastOnce())
|
|
->method('sendTemplate');
|
|
|
|
$eventMock->expects($this->atLeastOnce())
|
|
->method('getparameters')
|
|
->willReturn(['id' => random_int(1, 100)]);
|
|
|
|
$service = new Service();
|
|
|
|
$di = $this->getDi();
|
|
$di['mod_service'] = $di->protect(function ($name) use ($supportServiceMock, $emailServiceMock) {
|
|
if ($name == 'support') {
|
|
return $supportServiceMock;
|
|
}
|
|
if ($name == 'email') {
|
|
return $emailServiceMock;
|
|
}
|
|
});
|
|
|
|
$eventMock->expects($this->atLeastOnce())
|
|
->method('getDi')
|
|
->willReturn($di);
|
|
$service->setDi($di);
|
|
$service->onAfterGuestPublicTicketOpen($eventMock);
|
|
}
|
|
|
|
public function testOnAfterGuestPublicTicketOpenException(): void
|
|
{
|
|
$eventMock = $this->getMockBuilder('\Box_Event')
|
|
->disableOriginalConstructor()
|
|
->getMock();
|
|
|
|
$supportServiceMock = $this->createMock(\Box\Mod\Support\Service::class);
|
|
$supportServiceMock->expects($this->atLeastOnce())
|
|
->method('getPublicTicketById')
|
|
->willReturn(new \Model_SupportPTicket());
|
|
$supportServiceMock->expects($this->atLeastOnce())
|
|
->method('publicToApiArray')
|
|
->willReturn([]);
|
|
|
|
$emailServiceMock = $this->createMock(\Box\Mod\Email\Service::class);
|
|
$emailServiceMock->expects($this->atLeastOnce())
|
|
->method('sendTemplate')
|
|
->willThrowException(new \Exception('PHPunit controlled Exception'));
|
|
|
|
$eventMock->expects($this->atLeastOnce())
|
|
->method('getparameters')
|
|
->willReturn(['id' => random_int(1, 100)]);
|
|
|
|
$service = new Service();
|
|
|
|
$di = $this->getDi();
|
|
$di['mod_service'] = $di->protect(function ($name) use ($supportServiceMock, $emailServiceMock) {
|
|
if ($name == 'support') {
|
|
return $supportServiceMock;
|
|
}
|
|
if ($name == 'email') {
|
|
return $emailServiceMock;
|
|
}
|
|
});
|
|
|
|
$eventMock->expects($this->atLeastOnce())
|
|
->method('getDi')
|
|
->willReturn($di);
|
|
$service->setDi($di);
|
|
$service->onAfterGuestPublicTicketOpen($eventMock);
|
|
}
|
|
|
|
public function testOnAfterGuestPublicTicketReply(): void
|
|
{
|
|
$eventMock = $this->getMockBuilder('\Box_Event')
|
|
->disableOriginalConstructor()
|
|
->getMock();
|
|
|
|
$supportServiceMock = $this->createMock(\Box\Mod\Support\Service::class);
|
|
$supportServiceMock->expects($this->atLeastOnce())
|
|
->method('getPublicTicketById')
|
|
->willReturn(new \Model_SupportPTicket());
|
|
$supportServiceMock->expects($this->atLeastOnce())
|
|
->method('publicToApiArray')
|
|
->willReturn([]);
|
|
|
|
$emailServiceMock = $this->createMock(\Box\Mod\Email\Service::class);
|
|
$emailServiceMock->expects($this->atLeastOnce())
|
|
->method('sendTemplate');
|
|
|
|
$eventMock->expects($this->atLeastOnce())
|
|
->method('getparameters')
|
|
->willReturn(['id' => random_int(1, 100)]);
|
|
|
|
$service = new Service();
|
|
|
|
$di = $this->getDi();
|
|
$di['mod_service'] = $di->protect(function ($name) use ($supportServiceMock, $emailServiceMock) {
|
|
if ($name == 'support') {
|
|
return $supportServiceMock;
|
|
}
|
|
if ($name == 'email') {
|
|
return $emailServiceMock;
|
|
}
|
|
});
|
|
|
|
$eventMock->expects($this->atLeastOnce())
|
|
->method('getDi')
|
|
->willReturn($di);
|
|
$service->setDi($di);
|
|
$service->onAfterGuestPublicTicketReply($eventMock);
|
|
}
|
|
|
|
public function testOnAfterGuestPublicTicketReplyException(): void
|
|
{
|
|
$eventMock = $this->getMockBuilder('\Box_Event')
|
|
->disableOriginalConstructor()
|
|
->getMock();
|
|
|
|
$supportServiceMock = $this->createMock(\Box\Mod\Support\Service::class);
|
|
$supportServiceMock->expects($this->atLeastOnce())
|
|
->method('getPublicTicketById')
|
|
->willReturn(new \Model_SupportPTicket());
|
|
$supportServiceMock->expects($this->atLeastOnce())
|
|
->method('publicToApiArray')
|
|
->willReturn([]);
|
|
|
|
$emailServiceMock = $this->createMock(\Box\Mod\Email\Service::class);
|
|
$emailServiceMock->expects($this->atLeastOnce())
|
|
->method('sendTemplate')
|
|
->willThrowException(new \Exception('PHPunit controlled Exception'));
|
|
|
|
$eventMock->expects($this->atLeastOnce())
|
|
->method('getparameters')
|
|
->willReturn(['id' => random_int(1, 100)]);
|
|
|
|
$service = new Service();
|
|
|
|
$di = $this->getDi();
|
|
$di['mod_service'] = $di->protect(function ($name) use ($supportServiceMock, $emailServiceMock) {
|
|
if ($name == 'support') {
|
|
return $supportServiceMock;
|
|
}
|
|
if ($name == 'email') {
|
|
return $emailServiceMock;
|
|
}
|
|
});
|
|
|
|
$eventMock->expects($this->atLeastOnce())
|
|
->method('getDi')
|
|
->willReturn($di);
|
|
$service->setDi($di);
|
|
$service->onAfterGuestPublicTicketReply($eventMock);
|
|
}
|
|
|
|
public function testOnAfterClientSignUp(): void
|
|
{
|
|
$eventMock = $this->getMockBuilder('\Box_Event')
|
|
->disableOriginalConstructor()
|
|
->getMock();
|
|
|
|
$clientMock = $this->createMock(\Box\Mod\Client\Service::class);
|
|
$clientMock->expects($this->atLeastOnce())
|
|
->method('get')
|
|
->willReturn([]);
|
|
|
|
$emailServiceMock = $this->createMock(\Box\Mod\Email\Service::class);
|
|
$emailServiceMock->expects($this->atLeastOnce())
|
|
->method('sendTemplate');
|
|
|
|
$eventMock->expects($this->atLeastOnce())
|
|
->method('getparameters')
|
|
->willReturn(['id' => random_int(1, 100)]);
|
|
|
|
$service = new Service();
|
|
|
|
$di = $this->getDi();
|
|
$di['mod_service'] = $di->protect(function ($name) use ($clientMock, $emailServiceMock) {
|
|
if ($name == 'client') {
|
|
return $clientMock;
|
|
}
|
|
if ($name == 'email') {
|
|
return $emailServiceMock;
|
|
}
|
|
});
|
|
|
|
$eventMock->expects($this->atLeastOnce())
|
|
->method('getDi')
|
|
->willReturn($di);
|
|
$service->setDi($di);
|
|
$service->onAfterClientSignUp($eventMock);
|
|
}
|
|
|
|
public function testOnAfterClientSignUpException(): void
|
|
{
|
|
$eventMock = $this->getMockBuilder('\Box_Event')
|
|
->disableOriginalConstructor()
|
|
->getMock();
|
|
|
|
$clientMock = $this->createMock(\Box\Mod\Client\Service::class);
|
|
$clientMock->expects($this->atLeastOnce())
|
|
->method('get')
|
|
->willReturn([]);
|
|
|
|
$emailServiceMock = $this->createMock(\Box\Mod\Email\Service::class);
|
|
$emailServiceMock->expects($this->atLeastOnce())
|
|
->method('sendTemplate')
|
|
->willThrowException(new \Exception('PHPunit controlled Exception'));
|
|
|
|
$eventMock->expects($this->atLeastOnce())
|
|
->method('getparameters')
|
|
->willReturn(['id' => random_int(1, 100)]);
|
|
|
|
$service = new Service();
|
|
|
|
$di = $this->getDi();
|
|
$di['mod_service'] = $di->protect(function ($name) use ($clientMock, $emailServiceMock) {
|
|
if ($name == 'client') {
|
|
return $clientMock;
|
|
}
|
|
if ($name == 'email') {
|
|
return $emailServiceMock;
|
|
}
|
|
});
|
|
|
|
$eventMock->expects($this->atLeastOnce())
|
|
->method('getDi')
|
|
->willReturn($di);
|
|
$service->setDi($di);
|
|
$service->onAfterClientSignUp($eventMock);
|
|
}
|
|
|
|
public function testOnAfterGuestPublicTicketClose(): void
|
|
{
|
|
$eventMock = $this->getMockBuilder('\Box_Event')
|
|
->disableOriginalConstructor()
|
|
->getMock();
|
|
|
|
$supportServiceMock = $this->createMock(\Box\Mod\Support\Service::class);
|
|
$supportServiceMock->expects($this->atLeastOnce())
|
|
->method('publicToApiArray')
|
|
->willReturn([]);
|
|
|
|
$emailServiceMock = $this->createMock(\Box\Mod\Email\Service::class);
|
|
$emailServiceMock->expects($this->atLeastOnce())
|
|
->method('sendTemplate')
|
|
->willThrowException(new \Exception('PHPunit controlled Exception'));
|
|
|
|
$eventMock->expects($this->atLeastOnce())
|
|
->method('getparameters')
|
|
->willReturn(['id' => random_int(1, 100)]);
|
|
|
|
$dbMock = $this->createMock('\Box_Database');
|
|
$dbMock->expects($this->atLeastOnce())
|
|
->method('load')
|
|
->willReturn(new \Model_SupportPTicket());
|
|
|
|
$service = new Service();
|
|
|
|
$di = $this->getDi();
|
|
$di['mod_service'] = $di->protect(function ($name) use ($supportServiceMock, $emailServiceMock) {
|
|
if ($name == 'support') {
|
|
return $supportServiceMock;
|
|
}
|
|
if ($name == 'email') {
|
|
return $emailServiceMock;
|
|
}
|
|
});
|
|
$di['db'] = $dbMock;
|
|
|
|
$eventMock->expects($this->atLeastOnce())
|
|
->method('getDi')
|
|
->willReturn($di);
|
|
$service->setDi($di);
|
|
$service->onAfterGuestPublicTicketClose($eventMock);
|
|
}
|
|
|
|
public function testOnAfterClientOpenTicketModStaffTicketOpen(): void
|
|
{
|
|
$di = $this->getDi();
|
|
|
|
$ticketModel = new \Model_SupportTicket();
|
|
$ticketModel->loadBean(new \DummyBean());
|
|
|
|
$supportServiceMock = $this->createMock(\Box\Mod\Support\Service::class);
|
|
$supportServiceMock->expects($this->atLeastOnce())
|
|
->method('getTicketById')
|
|
->willReturn($ticketModel);
|
|
|
|
$supportTicketArray = [];
|
|
$supportServiceMock->expects($this->atLeastOnce())
|
|
->method('toApiArray')
|
|
->willReturn($supportTicketArray);
|
|
|
|
$emailServiceMock = $this->createMock(\Box\Mod\Email\Service::class);
|
|
|
|
$emailConfig = [
|
|
'to_staff' => true,
|
|
'code' => 'mod_staff_ticket_open',
|
|
'ticket' => $supportTicketArray,
|
|
];
|
|
$emailServiceMock->expects($this->once())
|
|
->method('sendTemplate')
|
|
->with($emailConfig)
|
|
->willReturn(true);
|
|
|
|
$di['mod_service'] = $di->protect(function ($name) use ($supportServiceMock, $emailServiceMock) {
|
|
if ($name == 'support') {
|
|
return $supportServiceMock;
|
|
}
|
|
if ($name == 'email') {
|
|
return $emailServiceMock;
|
|
}
|
|
});
|
|
|
|
$dbMock = $this->createMock('\Box_Database');
|
|
$dbMock->expects($this->atLeastOnce())
|
|
->method('load')
|
|
->willReturn(null);
|
|
$di['db'] = $dbMock;
|
|
$di['loggedin_admin'] = new \Model_Admin();
|
|
|
|
$eventMock = $this->getMockBuilder('\Box_Event')
|
|
->disableOriginalConstructor()
|
|
->getMock();
|
|
$eventMock->expects($this->atLeastOnce())
|
|
->method('getDi')
|
|
->willReturn($di);
|
|
|
|
$eventMock->expects($this->atLeastOnce())
|
|
->method('getparameters')
|
|
->willReturn(['id' => random_int(1, 100)]);
|
|
|
|
$service = new Service();
|
|
$service->onAfterClientOpenTicket($eventMock);
|
|
}
|
|
|
|
public function testOnAfterClientOpenTicketModSupportHelpdeskTicketOpen(): void
|
|
{
|
|
$di = $this->getDi();
|
|
|
|
$ticketModel = new \Model_SupportTicket();
|
|
$ticketModel->loadBean(new \DummyBean());
|
|
|
|
$supportServiceMock = $this->createMock(\Box\Mod\Support\Service::class);
|
|
$supportServiceMock->expects($this->atLeastOnce())
|
|
->method('getTicketById')
|
|
->willReturn($ticketModel);
|
|
|
|
$supportTicketArray = [];
|
|
$supportServiceMock->expects($this->atLeastOnce())
|
|
->method('toApiArray')
|
|
->willReturn($supportTicketArray);
|
|
|
|
$helpdeskModel = new \Model_SupportHelpdesk();
|
|
$helpdeskModel->loadBean(new \DummyBean());
|
|
$helpdeskModel->email = 'helpdesk@support.com';
|
|
|
|
$emailServiceMock = $this->createMock(\Box\Mod\Email\Service::class);
|
|
$emailConfig = [
|
|
'to' => $helpdeskModel->email,
|
|
'code' => 'mod_support_helpdesk_ticket_open',
|
|
'ticket' => $supportTicketArray,
|
|
];
|
|
$emailServiceMock->expects($this->once())
|
|
->method('sendTemplate')
|
|
->with($emailConfig)
|
|
->willReturn(true);
|
|
|
|
$di['mod_service'] = $di->protect(function ($name) use ($supportServiceMock, $emailServiceMock) {
|
|
if ($name == 'support') {
|
|
return $supportServiceMock;
|
|
}
|
|
if ($name == 'email') {
|
|
return $emailServiceMock;
|
|
}
|
|
});
|
|
|
|
$dbMock = $this->createMock('\Box_Database');
|
|
$dbMock->expects($this->atLeastOnce())
|
|
->method('load')
|
|
->willReturn($helpdeskModel);
|
|
$di['db'] = $dbMock;
|
|
$di['loggedin_admin'] = new \Model_Admin();
|
|
|
|
$eventMock = $this->getMockBuilder('\Box_Event')
|
|
->disableOriginalConstructor()
|
|
->getMock();
|
|
$eventMock->expects($this->atLeastOnce())
|
|
->method('getDi')
|
|
->willReturn($di);
|
|
|
|
$eventMock->expects($this->atLeastOnce())
|
|
->method('getparameters')
|
|
->willReturn(['id' => random_int(1, 100)]);
|
|
|
|
$service = new Service();
|
|
$service->onAfterClientOpenTicket($eventMock);
|
|
}
|
|
|
|
public function testGetList(): void
|
|
{
|
|
$pagerMock = $this->getMockBuilder(\FOSSBilling\Pagination::class)
|
|
->onlyMethods(['getPaginatedResultSet'])
|
|
->disableOriginalConstructor()
|
|
->getMock();
|
|
$pagerMock->expects($this->atLeastOnce())
|
|
->method('getPaginatedResultSet')
|
|
->willReturn([]);
|
|
|
|
$di = $this->getDi();
|
|
$di['pager'] = $pagerMock;
|
|
|
|
$service = new Service();
|
|
$service->setDi($di);
|
|
|
|
$result = $service->getList([]);
|
|
$this->assertIsArray($result);
|
|
}
|
|
|
|
public static function searchFilters(): array
|
|
{
|
|
return [
|
|
[
|
|
[],
|
|
'SELECT * FROM admin',
|
|
[],
|
|
],
|
|
[
|
|
['search' => 'keyword'],
|
|
'(name LIKE :name OR email LIKE :email )',
|
|
[':name' => '%keyword%', ':email' => '%keyword%'],
|
|
],
|
|
[
|
|
['status' => 'active'],
|
|
'status = :status',
|
|
[':status' => 'active'],
|
|
],
|
|
[
|
|
['id' => '4'],
|
|
'id = :id',
|
|
[':id' => 4],
|
|
],
|
|
[
|
|
['admin_group_id' => '3'],
|
|
'admin_group_id = :admin_group_id',
|
|
[':admin_group_id' => 3],
|
|
],
|
|
[
|
|
['no_cron' => 'true'],
|
|
'role != :role',
|
|
[':role' => \Model_Admin::ROLE_CRON],
|
|
],
|
|
];
|
|
}
|
|
|
|
#[DataProvider('searchFilters')]
|
|
public function testGetSearchQuery(array $data, string $expectedStr, array $expectedParams): void
|
|
{
|
|
$di = $this->getDi();
|
|
|
|
$service = new Service();
|
|
$service->setDi($di);
|
|
$result = $service->getSearchQuery($data);
|
|
$this->assertIsString($result[0]);
|
|
$this->assertIsArray($result[1]);
|
|
|
|
$this->assertTrue(str_contains($result[0], $expectedStr), $result[0]);
|
|
$this->assertEquals([], array_diff_key($result[1], $expectedParams));
|
|
}
|
|
|
|
public function testGetCronAdminAlreadyExists(): void
|
|
{
|
|
$adminModel = new \Model_Admin();
|
|
$adminModel->loadBean(new \DummyBean());
|
|
|
|
$dbMock = $this->createMock('\Box_Database');
|
|
$dbMock->expects($this->atLeastOnce())
|
|
->method('findOne')
|
|
->willReturn($adminModel);
|
|
|
|
$di = $this->getDi();
|
|
$di['db'] = $dbMock;
|
|
|
|
$service = new Service();
|
|
$service->setDi($di);
|
|
|
|
$result = $service->getCronAdmin();
|
|
$this->assertNotEmpty($result);
|
|
$this->assertInstanceOf('\Model_Admin', $result);
|
|
}
|
|
|
|
public function testGetCronAdminCreateCronAdminAndReturn(): void
|
|
{
|
|
$adminModel = new \Model_Admin();
|
|
$adminModel->loadBean(new \DummyBean());
|
|
|
|
$dbMock = $this->createMock('\Box_Database');
|
|
$dbMock->expects($this->atLeastOnce())
|
|
->method('findOne')
|
|
->willReturn(null);
|
|
|
|
$dbMock->expects($this->atLeastOnce())
|
|
->method('dispense')
|
|
->willReturn($adminModel);
|
|
|
|
$dbMock->expects($this->atLeastOnce())
|
|
->method('store');
|
|
|
|
$passwordMock = $this->createMock(\FOSSBilling\PasswordManager::class);
|
|
$passwordMock->expects($this->atLeastOnce())
|
|
->method('hashIt');
|
|
|
|
$di = $this->getDi();
|
|
$di['db'] = $dbMock;
|
|
$di['tools'] = new \FOSSBilling\Tools();
|
|
$di['password'] = $passwordMock;
|
|
|
|
$service = new Service();
|
|
$service->setDi($di);
|
|
|
|
$result = $service->getCronAdmin();
|
|
$this->assertNotEmpty($result);
|
|
$this->assertInstanceOf('\Model_Admin', $result);
|
|
}
|
|
|
|
public function testToModelAdminApiArray(): void
|
|
{
|
|
$adminModel = new \Model_Admin();
|
|
$adminModel->loadBean(new \DummyBean());
|
|
|
|
$adminGroupModel = new \Model_Admin();
|
|
$adminGroupModel->loadBean(new \DummyBean());
|
|
|
|
$dbMock = $this->createMock('\Box_Database');
|
|
$dbMock->expects($this->atLeastOnce())
|
|
->method('load')
|
|
->willReturn($adminGroupModel);
|
|
|
|
$expected =
|
|
[
|
|
'id' => '',
|
|
'role' => '',
|
|
'admin_group_id' => '',
|
|
'email' => '',
|
|
'name' => '',
|
|
'status' => '',
|
|
'signature' => '',
|
|
'created_at' => '',
|
|
'updated_at' => '',
|
|
'protected' => '',
|
|
'group' => ['id' => '', 'name' => ''],
|
|
];
|
|
|
|
$di = $this->getDi();
|
|
$di['db'] = $dbMock;
|
|
|
|
$service = new Service();
|
|
$service->setDi($di);
|
|
$result = $service->toModel_AdminApiArray($adminModel);
|
|
|
|
$this->assertNotEmpty($result);
|
|
$this->assertIsArray($result);
|
|
$this->assertTrue(count(array_diff(array_keys($expected), array_keys($result))) == 0, 'Missing array key values.');
|
|
}
|
|
|
|
public function testUpdate(): void
|
|
{
|
|
$data = [
|
|
'email' => 'test@example.com',
|
|
'admin_group_id' => '1',
|
|
'name' => 'testJohn',
|
|
'status' => 'active',
|
|
'signature' => '1345',
|
|
];
|
|
|
|
$adminModel = new \Model_Admin();
|
|
$adminModel->loadBean(new \DummyBean());
|
|
|
|
$eventsMock = $this->createMock('\Box_EventManager');
|
|
$eventsMock->expects($this->atLeastOnce())
|
|
->method('fire');
|
|
|
|
$logMock = $this->createStub('\Box_Log');
|
|
|
|
$dbMock = $this->createMock('\Box_Database');
|
|
$dbMock->expects($this->atLeastOnce())
|
|
->method('store');
|
|
|
|
$serviceMock = $this->getMockBuilder(Service::class)
|
|
->onlyMethods(['hasPermission'])->getMock();
|
|
|
|
$serviceMock->expects($this->atLeastOnce())
|
|
->method('hasPermission')->willReturn(true);
|
|
|
|
$di = $this->getDi();
|
|
$di['events_manager'] = $eventsMock;
|
|
$di['logger'] = $logMock;
|
|
$di['db'] = $dbMock;
|
|
|
|
$serviceMock->setDi($di);
|
|
|
|
$result = $serviceMock->update($adminModel, $data);
|
|
$this->assertTrue($result);
|
|
}
|
|
|
|
public function testDelete(): void
|
|
{
|
|
$adminModel = new \Model_Admin();
|
|
$adminModel->loadBean(new \DummyBean());
|
|
|
|
$eventsMock = $this->createMock('\Box_EventManager');
|
|
$eventsMock->expects($this->atLeastOnce())
|
|
->method('fire');
|
|
|
|
$logMock = $this->createStub('\Box_Log');
|
|
|
|
$dbMock = $this->createMock('\Box_Database');
|
|
$dbMock->expects($this->atLeastOnce())
|
|
->method('trash');
|
|
|
|
$serviceMock = $this->getMockBuilder(Service::class)
|
|
->onlyMethods(['hasPermission'])->getMock();
|
|
|
|
$serviceMock->expects($this->atLeastOnce())
|
|
->method('hasPermission')->willReturn(true);
|
|
|
|
$di = $this->getDi();
|
|
$di['events_manager'] = $eventsMock;
|
|
$di['logger'] = $logMock;
|
|
$di['db'] = $dbMock;
|
|
|
|
$serviceMock->setDi($di);
|
|
|
|
$result = $serviceMock->delete($adminModel);
|
|
$this->assertTrue($result);
|
|
}
|
|
|
|
public function testDeleteProtectedAccount(): void
|
|
{
|
|
$adminModel = new \Model_Admin();
|
|
$adminModel->loadBean(new \DummyBean());
|
|
$adminModel->protected = 1;
|
|
|
|
$service = new Service();
|
|
|
|
$this->expectException(\FOSSBilling\Exception::class);
|
|
$this->expectExceptionMessage('This administrator account is protected and cannot be removed');
|
|
$service->delete($adminModel);
|
|
}
|
|
|
|
public function testChangePassword(): void
|
|
{
|
|
$plainTextPassword = 'password';
|
|
$adminModel = new \Model_Admin();
|
|
$adminModel->loadBean(new \DummyBean());
|
|
|
|
$eventsMock = $this->createMock('\Box_EventManager');
|
|
$eventsMock->expects($this->atLeastOnce())
|
|
->method('fire');
|
|
|
|
$logMock = $this->createStub('\Box_Log');
|
|
|
|
$dbMock = $this->createMock('\Box_Database');
|
|
$dbMock->expects($this->atLeastOnce())
|
|
->method('store');
|
|
|
|
$passwordMock = $this->createMock(\FOSSBilling\PasswordManager::class);
|
|
$passwordMock->expects($this->atLeastOnce())
|
|
->method('hashIt')
|
|
->with($plainTextPassword);
|
|
|
|
$profileService = $this->createStub(\Box\Mod\Profile\Service::class);
|
|
|
|
$serviceMock = $this->getMockBuilder(Service::class)
|
|
->onlyMethods(['hasPermission'])->getMock();
|
|
|
|
$serviceMock->expects($this->atLeastOnce())
|
|
->method('hasPermission')->willReturn(true);
|
|
|
|
$di = $this->getDi();
|
|
$di['events_manager'] = $eventsMock;
|
|
$di['logger'] = $logMock;
|
|
$di['db'] = $dbMock;
|
|
$di['password'] = $passwordMock;
|
|
$di['mod_service'] = $di->protect(fn (): \PHPUnit\Framework\MockObject\Stub => $profileService);
|
|
|
|
$serviceMock->setDi($di);
|
|
|
|
$result = $serviceMock->changePassword($adminModel, $plainTextPassword);
|
|
$this->assertTrue($result);
|
|
}
|
|
|
|
public function testCreate(): void
|
|
{
|
|
$data = [
|
|
'email' => 'test@example.com',
|
|
'admin_group_id' => '1',
|
|
'name' => 'testJohn',
|
|
'status' => 'active',
|
|
'password' => '1345',
|
|
];
|
|
|
|
$newId = 1;
|
|
|
|
$adminModel = new \Model_Admin();
|
|
$adminModel->loadBean(new \DummyBean());
|
|
|
|
$eventsMock = $this->createMock('\Box_EventManager');
|
|
$eventsMock->expects($this->atLeastOnce())
|
|
->method('fire');
|
|
|
|
$dbMock = $this->createMock('\Box_Database');
|
|
$dbMock->expects($this->atLeastOnce())
|
|
->method('dispense')
|
|
->willReturn($adminModel);
|
|
$dbMock->expects($this->atLeastOnce())
|
|
->method('store')
|
|
->willReturn($newId);
|
|
|
|
$logMock = $this->createStub('\Box_Log');
|
|
|
|
$passwordMock = $this->createMock(\FOSSBilling\PasswordManager::class);
|
|
$passwordMock->expects($this->atLeastOnce())
|
|
->method('hashIt')
|
|
->with($data['password']);
|
|
|
|
$serviceMock = $this->getMockBuilder(Service::class)
|
|
->onlyMethods(['hasPermission'])->getMock();
|
|
|
|
$serviceMock->expects($this->atLeastOnce())
|
|
->method('hasPermission')->willReturn(true);
|
|
|
|
$di = $this->getDi();
|
|
$di['events_manager'] = $eventsMock;
|
|
$di['logger'] = $logMock;
|
|
$di['db'] = $dbMock;
|
|
|
|
$di['password'] = $passwordMock;
|
|
|
|
$serviceMock->setDi($di);
|
|
|
|
$result = $serviceMock->create($data);
|
|
$this->assertIsInt($result);
|
|
$this->assertEquals($newId, $result);
|
|
}
|
|
|
|
public function testCreateException(): void
|
|
{
|
|
$data = [
|
|
'email' => 'test@example.com',
|
|
'admin_group_id' => '1',
|
|
'name' => 'testJohn',
|
|
'status' => 'active',
|
|
'password' => '1345',
|
|
];
|
|
|
|
$newId = 1;
|
|
|
|
$adminModel = new \Model_Admin();
|
|
$adminModel->loadBean(new \DummyBean());
|
|
|
|
$eventsMock = $this->createMock('\Box_EventManager');
|
|
$eventsMock->expects($this->atLeastOnce())
|
|
->method('fire');
|
|
|
|
$dbMock = $this->createMock('\Box_Database');
|
|
$dbMock->expects($this->atLeastOnce())
|
|
->method('dispense')
|
|
->willReturn($adminModel);
|
|
$dbMock->expects($this->atLeastOnce())
|
|
->method('store')
|
|
->willThrowException(new \RedBeanPHP\RedException());
|
|
|
|
$logMock = $this->createStub('\Box_Log');
|
|
|
|
$passwordMock = $this->createMock(\FOSSBilling\PasswordManager::class);
|
|
$passwordMock->expects($this->atLeastOnce())
|
|
->method('hashIt')
|
|
->with($data['password']);
|
|
|
|
$serviceMock = $this->getMockBuilder(Service::class)
|
|
->onlyMethods(['hasPermission'])->getMock();
|
|
|
|
$serviceMock->expects($this->atLeastOnce())
|
|
->method('hasPermission')->willReturn(true);
|
|
|
|
$di = $this->getDi();
|
|
$di['events_manager'] = $eventsMock;
|
|
$di['logger'] = $logMock;
|
|
$di['db'] = $dbMock;
|
|
|
|
$di['password'] = $passwordMock;
|
|
|
|
$serviceMock->setDi($di);
|
|
|
|
$this->expectException(\FOSSBilling\Exception::class);
|
|
$this->expectExceptionCode(788954);
|
|
$this->expectExceptionMessage("Staff member with email {$data['email']} is already registered.");
|
|
$serviceMock->create($data);
|
|
}
|
|
|
|
public function testGetAdminGroupPair(): void
|
|
{
|
|
$rows = [
|
|
[
|
|
'id' => '1',
|
|
'name' => 'First Jogh',
|
|
],
|
|
[
|
|
'id' => '2',
|
|
'name' => 'Another Smith',
|
|
],
|
|
];
|
|
|
|
$expected = [
|
|
1 => 'First Jogh',
|
|
2 => 'Another Smith',
|
|
];
|
|
|
|
$dbMock = $this->createMock('\Box_Database');
|
|
$dbMock->expects($this->atLeastOnce())
|
|
->method('getAll')
|
|
->willReturn($rows);
|
|
|
|
$di = $this->getDi();
|
|
$di['db'] = $dbMock;
|
|
|
|
$service = new Service();
|
|
$service->setDi($di);
|
|
|
|
$result = $service->getAdminGroupPair();
|
|
|
|
$this->assertEquals($expected, $result);
|
|
$this->assertIsArray($result);
|
|
}
|
|
|
|
public function testGetAdminGroupSearchQuery(): void
|
|
{
|
|
$service = new Service();
|
|
|
|
$result = $service->getAdminGroupSearchQuery([]);
|
|
|
|
$this->assertIsString($result[0]);
|
|
$this->assertIsArray($result[1]);
|
|
}
|
|
|
|
public function testCreateGroup(): void
|
|
{
|
|
$adminGroupModel = new \Model_AdminGroup();
|
|
$adminGroupModel->loadBean(new \DummyBean());
|
|
$newGroupId = 1;
|
|
|
|
$dbMock = $this->createMock('\Box_Database');
|
|
$dbMock->expects($this->atLeastOnce())
|
|
->method('dispense')
|
|
->willReturn($adminGroupModel);
|
|
$dbMock->expects($this->atLeastOnce())
|
|
->method('store')
|
|
->willReturn($newGroupId);
|
|
|
|
$serviceMock = $this->getMockBuilder(Service::class)
|
|
->onlyMethods(['hasPermission'])->getMock();
|
|
|
|
$serviceMock->expects($this->atLeastOnce())
|
|
->method('hasPermission')->willReturn(true);
|
|
|
|
$di = $this->getDi();
|
|
$di['db'] = $dbMock;
|
|
$di['logger'] = new \Box_Log();
|
|
|
|
$serviceMock->setDi($di);
|
|
|
|
$result = $serviceMock->createGroup('new_group_name');
|
|
$this->assertIsInt($result);
|
|
$this->assertEquals($newGroupId, $result);
|
|
}
|
|
|
|
public function testToAdminGroupApiArray(): void
|
|
{
|
|
$adminGroupModel = new \Model_AdminGroup();
|
|
$adminGroupModel->loadBean(new \DummyBean());
|
|
|
|
$expected =
|
|
[
|
|
'id' => '',
|
|
'name' => '',
|
|
'created_at' => '',
|
|
'updated_at' => '',
|
|
];
|
|
|
|
$service = new Service();
|
|
|
|
$result = $service->toAdminGroupApiArray($adminGroupModel);
|
|
|
|
$this->assertIsArray($result);
|
|
$this->assertTrue(count(array_diff(array_keys($expected), array_keys($result))) == 0, 'Missing array key values.');
|
|
}
|
|
|
|
public function testDeleteGroup(): void
|
|
{
|
|
$adminGroupModel = new \Model_AdminGroup();
|
|
$adminGroupModel->loadBean(new \DummyBean());
|
|
|
|
$dbMock = $this->createMock('\Box_Database');
|
|
$dbMock->expects($this->atLeastOnce())
|
|
->method('trash');
|
|
$dbMock->expects($this->atLeastOnce())
|
|
->method('getCell')
|
|
->willReturn(0);
|
|
|
|
$serviceMock = $this->getMockBuilder(Service::class)
|
|
->onlyMethods(['hasPermission'])->getMock();
|
|
|
|
$serviceMock->expects($this->atLeastOnce())
|
|
->method('hasPermission')->willReturn(true);
|
|
|
|
$di = $this->getDi();
|
|
$di['db'] = $dbMock;
|
|
$di['logger'] = new \Box_Log();
|
|
|
|
$serviceMock->setDi($di);
|
|
|
|
$result = $serviceMock->deleteGroup($adminGroupModel);
|
|
$this->assertIsBool($result);
|
|
$this->assertTrue($result);
|
|
}
|
|
|
|
public function testDeleteGroupDeleteAdminGroup(): void
|
|
{
|
|
$adminGroupModel = new \Model_AdminGroup();
|
|
$adminGroupModel->loadBean(new \DummyBean());
|
|
$adminGroupModel->id = 1;
|
|
|
|
$serviceMock = $this->getMockBuilder(Service::class)
|
|
->onlyMethods(['hasPermission'])->getMock();
|
|
|
|
$serviceMock->expects($this->atLeastOnce())
|
|
->method('hasPermission')->willReturn(true);
|
|
|
|
$this->expectException(\FOSSBilling\Exception::class);
|
|
$this->expectExceptionMessage('Administrators group cannot be removed');
|
|
$serviceMock->deleteGroup($adminGroupModel);
|
|
}
|
|
|
|
public function testDeleteGroupGroupHasMembers(): void
|
|
{
|
|
$adminGroupModel = new \Model_AdminGroup();
|
|
$adminGroupModel->loadBean(new \DummyBean());
|
|
|
|
$dbMock = $this->createMock('\Box_Database');
|
|
$dbMock->expects($this->atLeastOnce())
|
|
->method('getCell')
|
|
->willReturn(2);
|
|
|
|
$serviceMock = $this->getMockBuilder(Service::class)
|
|
->onlyMethods(['hasPermission'])->getMock();
|
|
|
|
$serviceMock->expects($this->atLeastOnce())
|
|
->method('hasPermission')->willReturn(true);
|
|
|
|
$di = $this->getDi();
|
|
$di['db'] = $dbMock;
|
|
|
|
$serviceMock->setDi($di);
|
|
|
|
$this->expectException(\FOSSBilling\Exception::class);
|
|
$this->expectExceptionMessage('Cannot remove group which has staff members');
|
|
$serviceMock->deleteGroup($adminGroupModel);
|
|
}
|
|
|
|
public function testUpdateGroup(): void
|
|
{
|
|
$adminGroupModel = new \Model_AdminGroup();
|
|
$adminGroupModel->loadBean(new \DummyBean());
|
|
|
|
$dbMock = $this->createMock('\Box_Database');
|
|
$dbMock->expects($this->atLeastOnce())
|
|
->method('store');
|
|
|
|
$serviceMock = $this->getMockBuilder(Service::class)
|
|
->onlyMethods(['hasPermission'])->getMock();
|
|
|
|
$serviceMock->expects($this->atLeastOnce())
|
|
->method('hasPermission')->willReturn(true);
|
|
|
|
$di = $this->getDi();
|
|
$di['db'] = $dbMock;
|
|
$di['logger'] = new \Box_Log();
|
|
|
|
$serviceMock->setDi($di);
|
|
|
|
$data = ['name' => 'OhExampleName'];
|
|
$result = $serviceMock->updateGroup($adminGroupModel, $data);
|
|
$this->assertIsBool($result);
|
|
$this->assertTrue($result);
|
|
}
|
|
|
|
public static function ActivityAdminHistorySearchFilters(): array
|
|
{
|
|
return [
|
|
[
|
|
[],
|
|
'SELECT m.*, a.email, a.name',
|
|
[],
|
|
],
|
|
[
|
|
['search' => 'keyword'],
|
|
'a.name LIKE :name OR a.id LIKE :id OR a.email LIKE :email',
|
|
['name' => '%keyword%', 'id' => '%keyword%', 'email' => '%keyword%'],
|
|
],
|
|
[
|
|
['admin_id' => '2'],
|
|
'm.admin_id = :admin_id',
|
|
['admin_id' => '2'],
|
|
],
|
|
[
|
|
['id' => '6'],
|
|
'm.id = :event_id',
|
|
['event_id' => 6],
|
|
],
|
|
[
|
|
['ip' => '203.0.113'],
|
|
'm.ip LIKE :ip',
|
|
['ip' => '%203.0.113%'],
|
|
],
|
|
];
|
|
}
|
|
|
|
#[DataProvider('ActivityAdminHistorySearchFilters')]
|
|
public function testGetActivityAdminHistorySearchQuery(array $data, string $expectedStr, array $expectedParams): void
|
|
{
|
|
$di = $this->getDi();
|
|
|
|
$service = new Service();
|
|
$service->setDi($di);
|
|
$result = $service->getActivityAdminHistorySearchQuery($data);
|
|
$this->assertIsString($result[0]);
|
|
$this->assertIsArray($result[1]);
|
|
|
|
$this->assertTrue(str_contains($result[0], $expectedStr), $result[0]);
|
|
$this->assertEquals([], array_diff_key($result[1], $expectedParams));
|
|
}
|
|
|
|
public function testGetActivityAdminHistorySearchQueryWithDateRangeFilters(): void
|
|
{
|
|
$di = $this->getDi();
|
|
|
|
$service = new Service();
|
|
$service->setDi($di);
|
|
[$sql, $params] = $service->getActivityAdminHistorySearchQuery([
|
|
'date_from' => '2026-06-01',
|
|
'date_to' => '2026-06-02',
|
|
]);
|
|
|
|
$this->assertStringContainsString('m.created_at >= :date_from', $sql);
|
|
$this->assertStringContainsString('m.created_at <= :date_to', $sql);
|
|
$this->assertSame('2026-06-01 00:00:00', $params['date_from']);
|
|
$this->assertSame('2026-06-02 23:59:59', $params['date_to']);
|
|
}
|
|
|
|
public function testToActivityAdminHistoryApiArray(): void
|
|
{
|
|
$adminHistoryModel = new \Model_ActivityAdminHistory();
|
|
$adminHistoryModel->loadBean(new \DummyBean());
|
|
$adminHistoryModel->admin_id = 2;
|
|
|
|
$expected = [
|
|
'id' => '',
|
|
'ip' => '',
|
|
'created_at' => '',
|
|
'staff' => [
|
|
'id' => $adminHistoryModel->admin_id,
|
|
'name' => '',
|
|
'email' => '',
|
|
],
|
|
];
|
|
|
|
$adminModel = new \Model_Admin();
|
|
$adminModel->loadBean(new \DummyBean());
|
|
$adminModel->id = 2;
|
|
|
|
$dbMock = $this->createMock('\Box_Database');
|
|
$dbMock->expects($this->atLeastOnce())
|
|
->method('load')
|
|
->willReturn($adminModel);
|
|
|
|
$di = $this->getDi();
|
|
$di['db'] = $dbMock;
|
|
|
|
$service = new Service();
|
|
$service->setDi($di);
|
|
$result = $service->toActivityAdminHistoryApiArray($adminHistoryModel);
|
|
|
|
$this->assertNotEmpty($result);
|
|
$this->assertIsArray($result);
|
|
$this->assertTrue(count(array_diff(array_keys($expected), array_keys($result))) == 0, 'Missing array key values.');
|
|
}
|
|
|
|
public function testSetPermissions(): void
|
|
{
|
|
$serviceMock = $this->getMockBuilder(Service::class)
|
|
->onlyMethods(['hasPermission'])->getMock();
|
|
|
|
$serviceMock->expects($this->atLeastOnce())
|
|
->method('hasPermission')->willReturn(true);
|
|
|
|
$queryBuilderMock = new class {
|
|
public function update($table)
|
|
{
|
|
return $this;
|
|
}
|
|
|
|
public function set($field, $value)
|
|
{
|
|
return $this;
|
|
}
|
|
|
|
public function where($cond)
|
|
{
|
|
return $this;
|
|
}
|
|
|
|
public function setParameter($key, $val)
|
|
{
|
|
return $this;
|
|
}
|
|
|
|
public function executeStatement(): int
|
|
{
|
|
return 1;
|
|
}
|
|
};
|
|
|
|
$dbalMock = new class($queryBuilderMock) {
|
|
public function __construct(private $qb)
|
|
{
|
|
}
|
|
|
|
public function createQueryBuilder()
|
|
{
|
|
return $this->qb;
|
|
}
|
|
};
|
|
|
|
$callerModel = new \Model_Admin();
|
|
$callerModel->loadBean(new \DummyBean());
|
|
$callerModel->id = 1;
|
|
$callerModel->role = \Model_Admin::ROLE_ADMIN;
|
|
|
|
$targetModel = new \Model_Admin();
|
|
$targetModel->loadBean(new \DummyBean());
|
|
$targetModel->id = 2;
|
|
$targetModel->role = \Model_Admin::ROLE_STAFF;
|
|
|
|
$di = new \Pimple\Container();
|
|
$di['dbal'] = $dbalMock;
|
|
$di['loggedin_admin'] = $callerModel;
|
|
$serviceMock->setDi($di);
|
|
|
|
$result = $serviceMock->setPermissions($targetModel, []);
|
|
$this->assertTrue($result);
|
|
}
|
|
|
|
public function testSetPermissionsSelfEditThrows(): void
|
|
{
|
|
$service = new Service();
|
|
|
|
$callerModel = new \Model_Admin();
|
|
$callerModel->loadBean(new \DummyBean());
|
|
$callerModel->id = 1;
|
|
$callerModel->role = \Model_Admin::ROLE_STAFF;
|
|
|
|
$di = new \Pimple\Container();
|
|
$di['loggedin_admin'] = $callerModel;
|
|
$service->setDi($di);
|
|
|
|
$this->expectException(\FOSSBilling\InformationException::class);
|
|
$this->expectExceptionMessage('You cannot modify your own permissions');
|
|
$service->setPermissions($callerModel, []);
|
|
}
|
|
|
|
public function testSetPermissionsCeilingEnforced(): void
|
|
{
|
|
$serviceMock = $this->getMockBuilder(Service::class)
|
|
->onlyMethods(['hasPermission', 'getPermissions'])->getMock();
|
|
|
|
$serviceMock->expects($this->atLeastOnce())
|
|
->method('hasPermission')->willReturn(true);
|
|
|
|
$callerPerms = [
|
|
'client' => ['access' => 1, 'view' => 1],
|
|
];
|
|
$serviceMock->expects($this->atLeastOnce())
|
|
->method('getPermissions')->willReturn($callerPerms);
|
|
|
|
$callerModel = new \Model_Admin();
|
|
$callerModel->loadBean(new \DummyBean());
|
|
$callerModel->id = 1;
|
|
$callerModel->role = \Model_Admin::ROLE_STAFF;
|
|
|
|
$targetModel = new \Model_Admin();
|
|
$targetModel->loadBean(new \DummyBean());
|
|
$targetModel->id = 2;
|
|
$targetModel->role = \Model_Admin::ROLE_STAFF;
|
|
|
|
$di = new \Pimple\Container();
|
|
$di['loggedin_admin'] = $callerModel;
|
|
$serviceMock->setDi($di);
|
|
|
|
$submitted = [
|
|
'client' => ['access' => 1, 'view' => 1, 'manage_balance' => 1],
|
|
];
|
|
|
|
$this->expectException(\FOSSBilling\InformationException::class);
|
|
$this->expectExceptionMessage('You cannot grant a permission that you do not have');
|
|
$serviceMock->setPermissions($targetModel, $submitted);
|
|
}
|
|
|
|
public function testSetPermissionsWildcardCeilingEnforced(): void
|
|
{
|
|
$serviceMock = $this->getMockBuilder(Service::class)
|
|
->onlyMethods(['hasPermission', 'getPermissions'])->getMock();
|
|
|
|
$serviceMock->expects($this->atLeastOnce())
|
|
->method('hasPermission')->willReturn(true);
|
|
|
|
$serviceMock->expects($this->atLeastOnce())
|
|
->method('getPermissions')->willReturn([]);
|
|
|
|
$callerModel = new \Model_Admin();
|
|
$callerModel->loadBean(new \DummyBean());
|
|
$callerModel->id = 1;
|
|
$callerModel->role = \Model_Admin::ROLE_STAFF;
|
|
|
|
$targetModel = new \Model_Admin();
|
|
$targetModel->loadBean(new \DummyBean());
|
|
$targetModel->id = 2;
|
|
$targetModel->role = \Model_Admin::ROLE_STAFF;
|
|
|
|
$di = new \Pimple\Container();
|
|
$di['loggedin_admin'] = $callerModel;
|
|
$serviceMock->setDi($di);
|
|
|
|
$submitted = [
|
|
'default' => ['all' => 1],
|
|
];
|
|
|
|
$this->expectException(\FOSSBilling\InformationException::class);
|
|
$this->expectExceptionMessage('You cannot grant wildcard access that you do not have');
|
|
$serviceMock->setPermissions($targetModel, $submitted);
|
|
}
|
|
|
|
public function testGetPermissionsPermAreEmpty(): void
|
|
{
|
|
$statementWithFetchOne = new class {
|
|
public function fetchOne(): string
|
|
{
|
|
return '{}';
|
|
}
|
|
};
|
|
|
|
$service = new Service();
|
|
|
|
$queryBuilderMock = new class($statementWithFetchOne) {
|
|
public function __construct(private $stmt)
|
|
{
|
|
}
|
|
|
|
public function update($table)
|
|
{
|
|
return $this;
|
|
}
|
|
|
|
public function set($field, $value)
|
|
{
|
|
return $this;
|
|
}
|
|
|
|
public function where($cond)
|
|
{
|
|
return $this;
|
|
}
|
|
|
|
public function setParameter($key, $val)
|
|
{
|
|
return $this;
|
|
}
|
|
|
|
public function executeStatement(): int
|
|
{
|
|
return 1;
|
|
}
|
|
|
|
public function select($field)
|
|
{
|
|
return $this;
|
|
}
|
|
|
|
public function from($table)
|
|
{
|
|
return $this;
|
|
}
|
|
|
|
public function executeQuery()
|
|
{
|
|
return $this->stmt;
|
|
}
|
|
};
|
|
|
|
$dbalMock = new class($queryBuilderMock) {
|
|
public function __construct(private $qb)
|
|
{
|
|
}
|
|
|
|
public function createQueryBuilder()
|
|
{
|
|
return $this->qb;
|
|
}
|
|
};
|
|
|
|
$di = new \Pimple\Container();
|
|
$di['dbal'] = $dbalMock;
|
|
$service->setDi($di);
|
|
|
|
$member_id = 1;
|
|
$result = $service->getPermissions($member_id);
|
|
$this->assertIsArray($result);
|
|
$this->assertSame([], $result);
|
|
}
|
|
|
|
public function testGetPermissions(): void
|
|
{
|
|
$queryResult = '{"id" : "1"}';
|
|
|
|
$statementWithFetchOne = new class($queryResult) {
|
|
public function __construct(private $result)
|
|
{
|
|
}
|
|
|
|
public function fetchOne()
|
|
{
|
|
return $this->result;
|
|
}
|
|
};
|
|
|
|
$service = new Service();
|
|
|
|
$queryBuilderMock = new class($statementWithFetchOne) {
|
|
public function __construct(private $stmt)
|
|
{
|
|
}
|
|
|
|
public function update($table)
|
|
{
|
|
return $this;
|
|
}
|
|
|
|
public function set($field, $value)
|
|
{
|
|
return $this;
|
|
}
|
|
|
|
public function where($cond)
|
|
{
|
|
return $this;
|
|
}
|
|
|
|
public function setParameter($key, $val)
|
|
{
|
|
return $this;
|
|
}
|
|
|
|
public function executeStatement(): int
|
|
{
|
|
return 1;
|
|
}
|
|
|
|
public function select($field)
|
|
{
|
|
return $this;
|
|
}
|
|
|
|
public function from($table)
|
|
{
|
|
return $this;
|
|
}
|
|
|
|
public function executeQuery()
|
|
{
|
|
return $this->stmt;
|
|
}
|
|
};
|
|
|
|
$dbalMock = new class($queryBuilderMock) {
|
|
public function __construct(private $qb)
|
|
{
|
|
}
|
|
|
|
public function createQueryBuilder()
|
|
{
|
|
return $this->qb;
|
|
}
|
|
};
|
|
|
|
$di = new \Pimple\Container();
|
|
$di['dbal'] = $dbalMock;
|
|
$service->setDi($di);
|
|
|
|
$member_id = 1;
|
|
$expected = json_decode($queryResult ?? '', true);
|
|
$result = $service->getPermissions($member_id);
|
|
$this->assertIsArray($result);
|
|
$this->assertEquals($expected, $result);
|
|
}
|
|
|
|
public function testAuthorizeAdminDidntFoundEmail(): void
|
|
{
|
|
$email = 'example@fossbilling.vm';
|
|
$password = '123456';
|
|
|
|
$dbMock = $this->createMock('\Box_Database');
|
|
$dbMock->expects($this->atLeastOnce())
|
|
->method('findOne')
|
|
->with('Admin', 'email = ? AND status = ? AND role != ?')
|
|
->willReturn(null);
|
|
|
|
$authMock = $this->getMockBuilder('\Box_Authorization')->disableOriginalConstructor()->getMock();
|
|
$authMock->expects($this->atLeastOnce())
|
|
->method('authorizeUser')
|
|
->with(null, $password)
|
|
->willReturn(null);
|
|
|
|
$di = $this->getDi();
|
|
$di['db'] = $dbMock;
|
|
$di['auth'] = $authMock;
|
|
|
|
$service = new Service();
|
|
$service->setDi($di);
|
|
|
|
$result = $service->authorizeAdmin($email, $password);
|
|
$this->assertNull($result);
|
|
}
|
|
|
|
public function testAuthorizeAdmin(): void
|
|
{
|
|
$email = 'example@fossbilling.vm';
|
|
$password = '123456';
|
|
|
|
$model = new \Model_Admin();
|
|
$model->loadBean(new \DummyBean());
|
|
|
|
$dbMock = $this->createMock('\Box_Database');
|
|
$dbMock->expects($this->atLeastOnce())
|
|
->method('findOne')
|
|
->with('Admin', 'email = ? AND status = ? AND role != ?')
|
|
->willReturn($model);
|
|
|
|
$authMock = $this->getMockBuilder('\Box_Authorization')->disableOriginalConstructor()->getMock();
|
|
$authMock->expects($this->atLeastOnce())
|
|
->method('authorizeUser')
|
|
->with($model, $password)
|
|
->willReturn($model);
|
|
|
|
$di = $this->getDi();
|
|
$di['db'] = $dbMock;
|
|
$di['auth'] = $authMock;
|
|
|
|
$service = new Service();
|
|
$service->setDi($di);
|
|
|
|
$result = $service->authorizeAdmin($email, $password);
|
|
$this->assertInstanceOf('\Model_Admin', $result);
|
|
}
|
|
}
|