mirror of
https://github.com/FOSSBilling/FOSSBilling.git
synced 2026-12-03 05:41:52 +09:00
* Introduce the new Paginator class * Rename it back to Pagination * Move #2756 here * Use HttpFoundation\Request * Restore Box_Paginator * Tests * Replace the deprecated methods wherever used * No need * Tests * Tests again * tests * Tests hopefully for the last time * Use a subquery instead * Found a faulty query `m.*` already includes `client_id`. was getting a duplicated column error. * New pagination logic in Huraga & a couple of improvements * Type safety * Accessibility and other improvements * Fixed tests * Make aria tags translatable * Update partial_pagination.html.twig * Dot operator and little docblock improvement ---------
109 lines
3.2 KiB
PHP
109 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace Box\Mod\Client\Api;
|
|
|
|
class ClientTest extends \BBTestCase
|
|
{
|
|
public function testgetDi(): void
|
|
{
|
|
$di = new \Pimple\Container();
|
|
$client = new Client();
|
|
$client->setDi($di);
|
|
$getDi = $client->getDi();
|
|
$this->assertEquals($di, $getDi);
|
|
}
|
|
|
|
public function testbalanceGetList(): void
|
|
{
|
|
$data = [];
|
|
|
|
$model = new \Model_Client();
|
|
$model->loadBean(new \DummyBean());
|
|
|
|
$serviceMock = $this->getMockBuilder('\\' . \Box\Mod\Client\ServiceBalance::class)->getMock();
|
|
$serviceMock->expects($this->atLeastOnce())
|
|
->method('getSearchQuery')
|
|
->willReturn(['sql', []]);
|
|
|
|
$simpleResultArr = [
|
|
'list' => [
|
|
['id' => 1],
|
|
],
|
|
];
|
|
|
|
$pagerMock = $this->getMockBuilder('\\' . \FOSSBilling\Pagination::class)
|
|
->onlyMethods(['getPaginatedResultSet'])
|
|
->disableOriginalConstructor()
|
|
->getMock();
|
|
$pagerMock->expects($this->atLeastOnce())
|
|
->method('getPaginatedResultSet')
|
|
->willReturn($simpleResultArr);
|
|
|
|
$model = new \Model_ClientBalance();
|
|
$model->loadBean(new \DummyBean());
|
|
$dbMock = $this->getMockBuilder('\Box_Database')->getMock();
|
|
$dbMock->expects($this->atLeastOnce())
|
|
->method('getExistingModelById')
|
|
->willReturn($model);
|
|
|
|
$di = new \Pimple\Container();
|
|
$di['mod_service'] = $di->protect(fn ($name) => $serviceMock);
|
|
$di['pager'] = $pagerMock;
|
|
$di['db'] = $dbMock;
|
|
|
|
$client = new Client();
|
|
$client->setDi($di);
|
|
$client->setService($serviceMock);
|
|
$client->setIdentity($model);
|
|
|
|
$result = $client->balance_get_list($data);
|
|
|
|
$this->assertIsArray($result);
|
|
}
|
|
|
|
public function testbalanceGetTotal(): void
|
|
{
|
|
$balanceAmount = 0.00;
|
|
$model = new \Model_Client();
|
|
$model->loadBean(new \DummyBean());
|
|
|
|
$serviceMock = $this->getMockBuilder('\\' . \Box\Mod\Client\ServiceBalance::class)->getMock();
|
|
$serviceMock->expects($this->atLeastOnce())
|
|
->method('getClientBalance')
|
|
->willReturn($balanceAmount);
|
|
|
|
$di = new \Pimple\Container();
|
|
$di['mod_service'] = $di->protect(fn ($name, $sub) => $serviceMock);
|
|
|
|
$api = new Client();
|
|
$api->setDi($di);
|
|
$api->setIdentity($model);
|
|
|
|
$result = $api->balance_get_total();
|
|
|
|
$this->assertIsFloat($result);
|
|
$this->assertEquals($balanceAmount, $result);
|
|
}
|
|
|
|
public function testisTaxable(): void
|
|
{
|
|
$clientIsTaxable = true;
|
|
|
|
$serviceMock = $this->getMockBuilder('\\' . \Box\Mod\Client\Service::class)->getMock();
|
|
$serviceMock->expects($this->atLeastOnce())
|
|
->method('isClientTaxable')
|
|
->willReturn($clientIsTaxable);
|
|
|
|
$client = new \Model_Client();
|
|
$client->loadBean(new \DummyBean());
|
|
|
|
$api = new Client();
|
|
$api->setService($serviceMock);
|
|
$api->setIdentity($client);
|
|
|
|
$result = $api->is_taxable();
|
|
$this->assertIsBool($result);
|
|
$this->assertEquals($clientIsTaxable, $result);
|
|
}
|
|
}
|