Remove Legacy (#2914)

* Remove legacy broken integration tests

* Remove deprecated `Box_Exception` and related code

Deleted `Box_Exception` class and its deprecated usage. Update tests to use `FOSSBilling\Exception` directly. Also removed deprecated methods from `FOSSBilling\Pagination`.
This commit is contained in:
Adam Daley authored and GitHub committed 2025-09-30 22:32:06 +01:00
1 parent 533a15999c
commit 902e514ca3
82 files changed
+1 -8330

No files matched your search

-29
View File
@@ -1,29 +0,0 @@
<?php
/**
* Copyright 2022-2025 FOSSBilling
* Copyright 2011-2021 BoxBilling, Inc.
* SPDX-License-Identifier: Apache-2.0.
*
* @copyright FOSSBilling (https://www.fossbilling.org)
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache-2.0
*/
class Box_Exception extends FOSSBilling\Exception
{
/**
* Creates a new translated exception.
*
* @deprecated 0.6.0, you should use FOSSBilling\Exception instead which is a drop in replacement.
*
* @param string $message error message
* @param array|null $variables translation variables
* @param int $code the exception code
* @param bool $protected if the variables in this should be considered protect, if so, hide them from the stack trace
*/
public function __construct(string $message, ?array $variables = null, int $code = 0, bool $protected = false)
{
// Pass the message to the parent
trigger_error('Box_Exception is deprecated and soon to be removed.', E_USER_DEPRECATED);
parent::__construct($message, $variables, $code, $protected);
}
}
-31
View File
@@ -97,35 +97,4 @@ class Pagination implements InjectionAwareInterface
'list' => $result,
];
}
/* Deprecated functions */
/**
* @deprecated 0.7.0, you should use getPaginatedResultSet() instead which is a drop in replacement.
*/
public function getAdvancedResultSet(string $query, array $params = [], ?int $perPage = null, ?int $page = null, string $pageParam = 'page', string $perPageParam = 'per_page'): array
{
trigger_error('getAdvancedResultSet() is deprecated and will be removed in a future version of FOSSBilling. Please use getPaginatedResultSet() instead.', E_USER_DEPRECATED);
return $this->getPaginatedResultSet($query, $params, $perPage, $page, $pageParam, $perPageParam);
}
/**
* @deprecated 0.7.0, you should use getPaginatedResultSet() instead which is a drop in replacement.
*/
public function getSimpleResultSet(string $query, array $params = [], ?int $perPage = null, ?int $page = null, string $pageParam = 'page', string $perPageParam = 'per_page'): array
{
trigger_error('getSimpleResultSet() is deprecated and will be removed in a future version of FOSSBilling. Please use getPaginatedResultSet() instead.', E_USER_DEPRECATED);
return $this->getPaginatedResultSet($query, $params, $perPage, $page, $pageParam, $perPageParam);
}
/**
* @deprecated 0.7.0, you should use getDefaultPerPage() instead which is a drop in replacement.
*/
public function getPer_page(): int
{
trigger_error('getPer_page() is deprecated and will be removed in a future version of FOSSBilling. Please use getDefaultPerPage() instead.', E_USER_DEPRECATED);
return $this->getDefaultPerPage();
}
}
@@ -1,55 +0,0 @@
<?php
class HandlerTest extends BBDbApiTestCase
{
public static function api_roles()
{
return [
['api_guest'],
['api_admin'],
['api_client'],
];
}
#[PHPUnit\Framework\Attributes\DataProvider('api_roles')]
public function testInstances($apiName): void
{
$api = $this->di[$apiName];
$this->assertInstanceOf('Api_Handler', $api);
}
public function testCall(): void
{
$api = $this->di['api_guest'];
$version = $api->system_version();
$this->assertEquals('0.0.1', $version);
}
public function testException(): void
{
$api = $this->di['api_guest'];
$method = 'methodWithoutUnderscore';
$this->expectException(FOSSBilling\Exception::class);
$this->expectExceptionCode(710);
$api->$method();
}
public function testInvalidModuleNameException(): void
{
$api = $this->di['api_guest'];
$moduleName = '__';
$this->expectException(FOSSBilling\Exception::class);
$this->expectExceptionCode(714);
$version = $api->$moduleName();
}
public function testModuleNotActiveException(): void
{
$api = $this->di['api_guest'];
$moduleName = 'notActiveModule_version';
$this->expectException(FOSSBilling\Exception::class);
$this->expectExceptionCode(715);
$version = $api->$moduleName();
}
}
@@ -1,59 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class DatabaseTest extends BBDbApiTestCase
{
public function testModel(): void
{
$model = $this->di['db']->dispense('Admin');
$this->assertInstanceOf(RedBeanPHP\SimpleModel::class, $model);
$id = $this->di['db']->store($model);
$this->assertNotNull($id);
$model = $this->di['db']->findOne('Admin', 'id = ?', [$id]);
$this->assertInstanceOf(RedBeanPHP\SimpleModel::class, $model);
$model = $this->di['db']->load('Admin', $id);
$this->assertInstanceOf(RedBeanPHP\SimpleModel::class, $model);
$model = $this->di['db']->getExistingModelById('Admin', $id);
$this->assertInstanceOf(RedBeanPHP\SimpleModel::class, $model);
$array = $this->di['db']->toArray($model);
$this->assertIsArray($array);
$models = $this->di['db']->find('Admin');
foreach ($models as $m) {
$this->assertInstanceOf(RedBeanPHP\SimpleModel::class, $m);
}
$this->assertNull($this->di['db']->trash($model));
}
public function testBean(): void
{
$bean = $this->di['db']->dispense('admin');
$this->assertInstanceOf(RedBeanPHP\OODBBean::class, $bean);
$id = $this->di['db']->store($bean);
$this->assertNotNull($id);
$model = $this->di['db']->findOne('admin', 'id = ?', [$id]);
$this->assertInstanceOf(RedBeanPHP\OODBBean::class, $model);
$model = $this->di['db']->load('admin', $id);
$this->assertInstanceOf(RedBeanPHP\OODBBean::class, $model);
$model = $this->di['db']->getExistingModelById('admin', $id);
$this->assertInstanceOf(RedBeanPHP\OODBBean::class, $model);
$array = $this->di['db']->toArray($model);
$this->assertIsArray($array);
$models = $this->di['db']->find('admin');
foreach ($models as $m) {
$this->assertInstanceOf(RedBeanPHP\OODBBean::class, $m);
}
$this->assertNull($this->di['db']->trash($model));
}
}
@@ -1,46 +0,0 @@
<?php
class DiTest extends PHPUnit\Framework\TestCase
{
public function setup(): void
{
global $di;
$this->di = clone $di;
}
public function testInjector(): void
{
$di = $this->di;
$this->assertInstanceOf('Box_Mod', $di['mod']('admin'));
$this->assertInstanceOf('Box_Log', $di['logger']);
$this->assertInstanceOf('Box_Crypt', $di['crypt']);
$this->assertTrue(isset($di['pdo']));
$this->assertTrue(isset($di['db']));
$this->assertInstanceOf('\\' . FOSSBilling\Pagination::class, $di['pager']);
$this->assertInstanceOf('Box_Url', $di['url']);
$this->assertInstanceOf('Box_EventManager', $di['events_manager']);
$this->assertInstanceOf('\\' . FOSSBilling\Session::class, $di['session']);
$this->assertInstanceOf('Box_Authorization', $di['auth']);
$this->assertInstanceOf(Twig\Environment::class, $di['twig']);
$this->assertInstanceOf('\\' . FOSSBilling\Tools::class, $di['tools']);
$this->assertInstanceOf('\\' . FOSSBilling\Validate::class, $di['validator']);
$this->assertTrue(isset($di['mod']));
$this->assertTrue(isset($di['mod_config']));
$this->assertInstanceOf(Box\Mod\Cron\Service::class, $di['mod_service']('cron'));
$this->assertInstanceOf('\\' . FOSSBilling\ExtensionManager::class, $di['extension_manager']);
$this->assertInstanceOf('\Box_Update', $di['updater']);
$this->assertInstanceOf('\Server_Package', $di['server_package']);
$this->assertInstanceOf('\Server_Client', $di['server_client']);
$this->assertInstanceOf('\Server_Account', $di['server_account']);
$this->assertTrue(isset($di['server_manager']));
$this->assertInstanceOf('\\' . FOSSBilling\Requirements::class, $di['requirements']);
$this->assertInstanceOf('\\' . Box\Mod\Theme\Model\Theme::class, $di['theme']);
$this->assertInstanceOf('\Model_Cart', $di['cart']);
$this->assertInstanceOf('\\' . GeoIp2\Database\Reader::class, $di['geoip']);
$this->assertInstanceOf('\FOSSBilling\PasswordManager', $di['password']);
$this->assertInstanceOf('\Box_Translate', $di['translate']());
}
}
@@ -1,64 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class LogTest extends BBDbApiTestCase
{
public static function logWithoutParamsProvider()
{
return [
['Test message'],
['Test message with param %s, but param not passed'],
];
}
#[PHPUnit\Framework\Attributes\DataProvider('logWithoutParamsProvider')]
public function testLogWithoutParams($msg): void
{
$msg = 'Test message';
$this->di['logger']->info($msg);
$array = $this->api_admin->activity_log_get_list();
$log = $array['list'][0]; // by default sorting by ID descending order so newest will always be first array item
$message = $log['message'];
$this->assertEquals($msg, $message);
}
public function testLogProvider()
{
$rand = random_int(1, 100);
$msg1 = 'No params in message, param passed';
$msg2 = 'Test message with param %s';
$this->assertTrue($rand <= 100 && $rand > 0);
return [
[$msg1, $rand, $msg1],
[$msg2, $rand, 'Test message with param ' . $rand],
];
}
#[PHPUnit\Framework\Attributes\DataProvider('testLogProvider')]
public function testLogWithSingleParam($msg, $param, $expected): void
{
$this->di['logger']->info($msg, $param);
$array = $this->api_admin->activity_log_get_list();
$log = $array['list'][0]; // by default sorting by ID descending order so newest will always be first array item
$message = $log['message'];
$this->assertEquals($expected, $message);
}
public function testLogMultipleVariables(): void
{
$msg = '%sMultiple params in message, one param passed%s';
$rand = random_int(1, 100);
$this->di['logger']->info($msg, $rand, $rand);
$array = $this->api_admin->activity_log_get_list();
$log = $array['list'][0]; // by default sorting by ID descending order so newest will always be first array item
$message = $log['message'];
$this->assertEquals(sprintf($msg, $rand, $rand), $message);
}
}
@@ -1,20 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class ModTest extends BBDbApiTestCase
{
public function testConfig(): void
{
$conf = [
'ext' => 'mod_client',
'required' => [
'last-name',
],
];
$this->api_admin->extension_config_save($conf);
$config = $this->di['mod_config']('client');
$this->assertEquals($conf, $config);
}
}
@@ -1,22 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class Payment_Adapter_CustomTest extends BBDbApiTestCase
{
protected $_initialSeedFile = 'gateway_Custom.xml';
public function testCustom(): void
{
$config = [
'single' => 'test',
'recurrent' => 'test',
];
$adapter = new Payment_Adapter_Custom($config);
$adapter->setDi($this->di);
$adapter->getConfig();
$adapter->getHtml($this->api_admin, 1, true);
$tx = $this->di['db']->load('Transaction', 1);
$adapter->process($tx);
}
}
@@ -1,62 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class Payment_Adapter_PayPalEmailTest extends BBDbApiTestCase
{
protected $_initialSeedFile = 'gateway_PayPal.xml';
public function testGateway(): void
{
$config = [];
$config['test_mode'] = true;
$config['email'] = 'example@gmail.com';
$config['return_url'] = 'http://www.google.com?q=return';
$config['cancel_url'] = 'http://www.google.com?q=cancel';
$config['notify_url'] = 'http://www.google.com?q=notify';
$adapter = new Payment_Adapter_PayPalEmail($config);
$adapter->setDi($this->di);
$adapter->getConfig();
$adapter->getHtml($this->api_admin, 1, false);
$adapter->getHtml($this->api_admin, 2, true);
$subscr_payment = json_decode('{"get":{"gateway_id":"1","invoice_id":"1"},"post":{"transaction_subject":"Subscription for FOSSBilling Pro License","payment_date":"11:24:34 Mar 08, 2012 PST","txn_type":"subscr_payment","subscr_id":"S-9X268688JL8514304","last_name":"Doe","residence_country":"GB","item_name":"Subscription for FOSSBilling Pro License","payment_gross":"5.95","mc_currency":"USD","business":"clients@fossbilling.org","payment_type":"instant","protection_eligibility":"Ineligible","verify_sign":"A2QxLKJxNBOK3utJMiCwOkOiLG3tAo4.KtJCsCemU7s98tgtW37-hOOx","payer_status":"verified","payer_email":"john.doe@gmail.com","txn_id":"6SR32195AP993094V","receiver_email":"clients@fossbilling.org","first_name":"John","payer_id":"9W3LMGTFS5RTY","receiver_id":"79PMKLAHPL5YH","item_number":"BOX05697","payment_status":"Completed","payment_fee":"0.47","mc_fee":"0.47","mc_gross":"5.95","charset":"windows-1252","notify_version":"3.4","ipn_track_id":"54b4dbrfvg396"},"http_raw_post_data":"transaction_subject=Subscription+for+FOSSBilling+Pro+License&payment_date=11%3A24%3A34+Mar+08%2C+2012+PST&txn_type=subscr_payment&subscr_id=S-9X268688JL8514304&last_name=Doe&residence_country=GB&item_name=Subscription+for+FOSSBilling+Pro+License&payment_gross=5.95&mc_currency=USD&business=clients%40fossbilling.org&payment_type=instant&protection_eligibility=Ineligible&verify_sign=A2QxLKJxNBOK3utOLuCwOkOiLG3tAo4.KtJCsCemU7db97vtW37-hOOx&payer_status=verified&payer_email=mitcheyDoe%40gmail.com&txn_id=6SR99524AP993094V&receiver_email=clients%40fossbilling.org&first_name=John&payer_id=9W3MDRHPS5RTY&receiver_id=79PMKLAHYN3HN&item_number=BOX05697&payment_status=Completed&payment_fee=0.47&mc_fee=0.47&mc_gross=5.95&charset=windows-1252&notify_version=3.4&ipn_track_id=54b4dbfade396"}', true);
$adapter->processTransaction($this->api_admin, 1, $subscr_payment, 1);
$web_accept = json_decode('{"get":{"gateway_id":"1","invoice_id":"1"},"post":{"transaction_subject":"Payment for invoice BOX05623","payment_date":"08:26:14 Mar 01, 2012 PST","txn_type":"web_accept","last_name":"Doe","residence_country":"US","item_name":"Payment for invoice BOX05623","payment_gross":"5.95","mc_currency":"USD","business":"sales@fossbilling.org","payment_type":"instant","protection_eligibility":"Ineligible","verify_sign":"A.DRDmKsJOHhCaHehJk34EQqLY1rAuZ0ksJDt.45zrn5eO7JxP0.4QP.","payer_status":"verified","tax":"0.00","payer_email":"john.doe@gmail.com","txn_id":"8X786252873429051","quantity":"1","receiver_email":"clients@fossbilling.org","first_name":"John","payer_id":"29NE5SEU5VR2E","receiver_id":"79PMKLAHPL5YH","item_number":"BOX05623","handling_amount":"0.00","payment_status":"Completed","payment_fee":"0.44","mc_fee":"0.44","shipping":"0.00","mc_gross":"5.95","custom":"","charset":"windows-1252","notify_version":"3.4","ipn_track_id":"6fd845df6f247"},"http_raw_post_data":"transaction_subject=Payment+for+invoice+BOX05623&payment_date=08%3A26%3A14+Mar+01%2C+2012+PST&txn_type=web_accept&last_name=Doe&residence_country=LT&item_name=Payment+for+invoice+BOX05623&payment_gross=5.95&mc_currency=USD&business=sales%40fossbilling.org&payment_type=instant&protection_eligibility=Ineligible&verify_sign=A.DRDmKsJOHhCaHehJr9EQqLY1rAuZ0ksJDt.45zrn5eO7JxP0.4QP.&payer_status=verified&tax=0.00&payer_email=fordnox%40gmail.com&txn_id=8X786252873429051&quantity=1&receiver_email=clients%40fossbilling.org&first_name=John&payer_id=29NE5SEU5VR2E&receiver_id=79PMKLAHYN3HN&item_number=BOX05623&handling_amount=0.00&payment_status=Completed&payment_fee=0.44&mc_fee=0.44&shipping=0.00&mc_gross=5.95&custom=&charset=windows-1252&notify_version=3.4&ipn_track_id=6fd802df6f247"}', true);
$adapter->processTransaction($this->api_admin, 1, $web_accept, 1);
$refund_ipn = json_decode('{"get":{"gateway_id":"1","invoice_id":"1"},"post":{"transaction_subject":"Subscription for FOSSBilling Pro License","payment_date":"17:42:05 Mar 13, 2012 PDT", "txn_type":"subscr_payment","subscr_id":"S-9X268688JL8514304","last_name":"Doe","residence_country":"GB","item_name":"Subscription for FOSSBilling Pro License","payment_gross":"-5.95","mc_currency":"USD","business":"clients@fossbilling.org","payment_type":"instant","protection_eligibility":"Ineligible","verify_sign":"ArFZ5DF1pEd4euI2jpvbEwe5Q4BiAB46zG6F4TMlFNMtpDC7L5z6VPsB","payer_email":"mitcheyDoe@gmail.com","txn_id":"33R88456DU653693H","receiver_email":"clients@fossbilling.org","first_name":"John","parent_txn_id":"6SR99524AP993094V","payer_id":"9W3LMGTFS5RTY","receiver_id":"79PMKLAHPL5YH","reason_code":"refund","item_number":"BOX05697","payment_status":"Refunded","payment_fee":"-0.17","mc_fee":"-0.17","mc_gross":"-5.95","charset":"windows-1252","notify_version":"3.4","ipn_track_id":"71f325984a82e"},"http_raw_post_data":"transaction_subject=Subscription+for+FOSSBilling+Pro+License&payment_date=17%3A42%3A05+Mar+13%2C+2012+PDT&subscr_id=S-9X268688JL8514304&last_name=Doe&residence_country=GB&item_name=Subscription+for+FOSSBilling+Pro+License&payment_gross=-5.95&mc_currency=USD&business=clients%40fossbilling.org&payment_type=instant&protection_eligibility=Ineligible&verify_sign=ArFZ5DF1pEd6dfI2jpvbEwe5Q4BiAB46zG6F4TMlFNMtpDC7L5z6VPsB&payer_email=mitcheyDoe%40gmail.com&txn_id=33R88456DU653693H&receiver_email=clients%40fossbilling.org&first_name=John&parent_txn_id=6SR99524AP993094V&payer_id=9W3MDRHPS5RTY&receiver_id=79PMKLAHYN3HN&reason_code=refund&item_number=BOX05697&payment_status=Refunded&payment_fee=-0.17&mc_fee=-0.17&mc_gross=-5.95&charset=windows-1252&notify_version=3.4&ipn_track_id=71f784354a82e"}', true);
$adapter->processTransaction($this->api_admin, 1, $refund_ipn, 1);
}
public function testGatewayProductionUrl(): void
{
$config = [];
$config['email'] = 'example@gmail.com';
$config['test_mode'] = false;
$config['return_url'] = 'http://www.google.com?q=return';
$config['cancel_url'] = 'http://www.google.com?q=cancel';
$config['notify_url'] = 'http://www.google.com?q=notify';
$adapter = new Payment_Adapter_PayPalEmail($config);
$adapter->setDi($this->di);
$form = $adapter->getHtml($this->api_admin, 1, false);
$this->assertMatchesRegularExpression('/action="https:\/\/www\.paypal\.com\/cgi-bin\/webscr"/', $form);
}
public function testGatewayTestmodeUrl(): void
{
$config = [];
$config['email'] = 'example@gmail.com';
$config['test_mode'] = true;
$config['return_url'] = 'http://www.google.com?q=return';
$config['cancel_url'] = 'http://www.google.com?q=cancel';
$config['notify_url'] = 'http://www.google.com?q=notify';
$adapter = new Payment_Adapter_PayPalEmail($config);
$adapter->setDi($this->di);
$form = $adapter->getHtml($this->api_admin, 1, false);
$this->assertMatchesRegularExpression('/action="https:\/\/www\.sandbox\.paypal\.com\/cgi-bin\/webscr"/', $form);
}
}
@@ -1,74 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class Api_AdminTest extends BBDbApiTestCase
{
protected $_initialSeedFile = 'settings.xml';
public function testActivity(): void
{
$bool = $this->api_admin->activity_log_delete(['id' => 1]);
$this->assertTrue($bool);
$bool = $this->api_admin->activity_log();
$this->assertFalse($bool);
$bool = $this->api_admin->activity_log(['m' => 'this is test message to log']);
$this->assertTrue($bool);
$bool = $this->api_admin->activity_log_email(['subject' => 'This is an email subject']);
$this->assertTrue($bool);
}
public function testLogDeleteIdNotSetException(): void
{
$this->expectException(FOSSBilling\Exception::class);
$this->api_admin->activity_log_delete([]);
}
public function testLogNotFoundException(): void
{
$this->expectException(FOSSBilling\Exception::class);
$this->api_admin->activity_log_delete(['id' => 100]);
}
public function testActivityLogGetList(): void
{
$array = $this->api_admin->activity_log_get_list();
$this->assertIsArray($array);
$this->assertArrayHasKey('list', $array);
$this->assertArrayHasKey('pages', $array);
$this->assertArrayHasKey('page', $array);
$this->assertArrayHasKey('per_page', $array);
$this->assertArrayHasKey('total', $array);
$this->assertArrayHasKey('list', $array);
$list = $array['list'];
$this->assertIsArray($list);
if (count($list)) {
$item = $list[0];
$this->assertArrayHasKey('id', $item);
$this->assertArrayHasKey('priority', $item);
$this->assertArrayHasKey('admin_id', $item);
$this->assertArrayHasKey('client_id', $item);
$this->assertArrayHasKey('message', $item);
$this->assertArrayHasKey('ip', $item);
$this->assertArrayHasKey('created_at', $item);
$this->assertArrayHasKey('updated_at', $item);
}
}
public function testBatchDelete(): void
{
$array = $this->api_admin->activity_log_get_list([]);
foreach ($array['list'] as $value) {
$ids[] = $value['id'];
}
$result = $this->api_admin->activity_batch_delete(['ids' => $ids]);
$array = $this->api_admin->activity_log_get_list([]);
$this->assertEquals(0, count($array['list']));
$this->assertTrue($result);
}
}
@@ -1,28 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class ServiceTest extends BBDbApiTestCase
{
protected $_mod = 'api';
protected $_initialSeedFile = 'mod_api.xml';
public function testClasses(): void
{
$service = $this->di['mod_service']('api');
$api = $service->getApiGuest();
$this->assertInstanceOf('Api_Handler', $api);
$api = $service->getApiAdmin();
$this->assertInstanceOf('Api_Handler', $api);
$api = $service->getApiClient(1);
$this->assertInstanceOf('Api_Handler', $api);
$result = $service->getRequestCount('2001-05-06', '123.124.125.126');
$this->assertIsInt($result);
$result = $service->logRequest();
$this->assertIsInt($result);
}
}
@@ -1,23 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class ServiceTest extends ApiTestCase
{
private $configLicense;
public function tearDown(): void
{
if ($this->configLicense) {
$this->di['config']['license'] = $this->configLicense;
}
}
public function testUninstallNotPro(): void
{
$this->configLicense = $this->di['config']['license'];
$this->expectException(Exception::class);
$service = $this->di['mod_service']('branding');
$this->di['config']['license'] = 'invalidLicense';
$service->uninstall();
}
}
@@ -1,47 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class Box_Mod_Cart_Api_AdminTest extends BBDbApiTestCase
{
protected $_initialSeedFile = 'mod_cart.xml';
public function testCarts(): void
{
$array = $this->api_admin->cart_get_list();
$this->assertIsArray($array);
$this->assertArrayHasKey('list', $array);
$list = $array['list'];
$this->assertIsArray($list);
if (count($list)) {
$item = $list[0];
$this->assertArrayHasKey('promocode', $item);
$this->assertArrayHasKey('discount', $item);
$this->assertArrayHasKey('total', $item);
$this->assertArrayHasKey('items', $item);
$this->assertArrayHasKey('currency', $item);
$currency = $item['currency'];
$this->assertIsArray($currency);
$this->assertArrayHasKey('code', $currency);
$this->assertArrayHasKey('title', $currency);
$this->assertArrayHasKey('conversion_rate', $currency);
$this->assertArrayHasKey('format', $currency);
$this->assertArrayHasKey('price_format', $currency);
$this->assertArrayHasKey('default', $currency);
}
}
public function testGet(): void
{
$data = [
'id' => 1,
];
$cartArr = $this->api_admin->cart_get($data);
$this->assertIsArray($cartArr);
}
public function testExpire(): void
{
$bool = $this->api_admin->cart_batch_expire();
$this->assertTrue($bool);
}
}
@@ -1,183 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class Box_Mod_Cart_Api_ClientTest extends BBDbApiTestCase
{
protected $_initialSeedFile = 'mod_cart.xml';
public function testCheckout(): void
{
$this->api_guest->cart_set_currency(['currency' => 'USD']);
// test custom products
$data = [
'id' => 1,
'period' => '1M',
'quantity' => 2,
];
$bool = $this->api_guest->cart_add_item($data);
$this->assertTrue($bool);
$cart_before_promo = $this->api_guest->cart_get();
$bool = $this->api_guest->cart_apply_promo(['promocode' => 'PHPUNIT']);
$this->assertTrue($bool);
$cart_after_promo = $this->api_guest->cart_get();
$this->assertTrue($cart_before_promo['total'] != $cart_after_promo['total'], 'Could not apply promo to cart');
$array = $this->api_client->cart_checkout();
$this->assertInternalType('array', $array);
$this->assertTrue(isset($array['invoice_hash']));
$this->assertTrue(isset($array['order_id']));
}
public function testCheckoutEmptyCart(): void
{
$this->api_guest->cart_set_currency(['currency' => 'USD']);
// test custom products
$data = [
'id' => 1,
'period' => '1M',
'quantity' => 2,
];
$this->expectException(FOSSBilling\Exception::class);
$this->expectExceptionMessage('Cannot checkout empty cart.');
$this->api_client->cart_checkout();
}
/**
* If client order total amount is 0 then activate it after placement.
*/
public function testPromoOrderActivation(): void
{
$this->api_guest->cart_set_currency(['currency' => 'USD']);
// add custom product
$data = [
'id' => 1,
'period' => '1M',
'quantity' => 1,
];
$bool = $this->api_guest->cart_add_item($data);
$this->assertTrue($bool);
$bool = $this->api_guest->cart_apply_promo(['promocode' => 'TOTAL_DISCOUNT']);
$this->assertTrue($bool);
$d = $this->api_client->cart_checkout();
$order = $this->api_client->order_get(['id' => $d['order_id']]);
$this->assertEquals(0, $order['total'] - $order['discount']);
$this->assertEquals('active', $order['status'], 'Order should be activated if total amount is 0 after discount and product setup is after_payment');
}
/**
* Test if promo code can be applied only once per client.
*/
public function testPromoOncePerClient(): void
{
$this->api_guest->cart_set_currency(['currency' => 'USD']);
// test custom products
$data = [
'id' => 1,
'period' => '1M',
'quantity' => 2,
];
$bool = $this->api_guest->cart_add_item($data);
$this->assertTrue($bool);
$bool = $this->api_guest->cart_apply_promo(['promocode' => 'ONCE_PER_CLIENT']);
$this->assertTrue($bool);
try {
$this->api_client->cart_checkout();
$this->fail('Promo code was aplied multiple times. Promo can only be applied once.');
} catch (Exception $e) {
$this->assertEquals(9874, $e->getCode());
}
}
/**
* checkout cart with product with addon and client has insufficient funds to cover.
*/
public function testAddonActivatedWhileOrderInvoiceUnpaid(): void
{
$this->api_guest->cart_reset();
$data = [
'id' => 11,
'period' => '6M',
'domain' => [
'action' => 'register',
'owndomain_sld' => '',
'owndomain_tld' => '.com',
'register_sld' => 'newdomainregister',
'register_tld' => '.com',
'register_years' => '1',
],
'multiple' => 1,
];
$this->api_guest->cart_add_item($data);
$this->api_client->cart_checkout();
$masterOrder = $this->di['db']->findOne('ClientOrder', 'group_master = 1 ORDER BY id desc');
$addonOrder = $this->di['db']->findOne('ClientOrder', 'group_id = ? and group_master = 0', [$masterOrder->group_id]);
$invoiceModel = $this->di['db']->load('Invoice', $masterOrder->unpaid_invoice_id);
$this->assertInstanceOf('Model_ClientOrder', $masterOrder);
$this->assertInstanceOf('Model_ClientOrder', $addonOrder);
$this->assertInstanceOf('Model_Invoice', $invoiceModel);
$this->assertNotNull($masterOrder->unpaid_invoice_id);
$this->assertEquals(Model_ClientOrder::STATUS_PENDING_SETUP, $masterOrder->status);
$this->assertEquals(Model_ClientOrder::STATUS_PENDING_SETUP, $addonOrder->status);
$this->assertEquals(Model_Invoice::STATUS_UNPAID, $invoiceModel->status);
}
/**
* checkout cart with product with addon and client has sufficient funds to cover.
*/
public function testOrderWithAddonCoverFromAccountBalance(): void
{
$this->api_guest->cart_reset();
$data = [
'id' => 11,
'period' => '6M',
'domain' => [
'action' => 'register',
'owndomain_sld' => '',
'owndomain_tld' => '.com',
'register_sld' => 'newdomainregister2',
'register_tld' => '.com',
'register_years' => '1',
],
'multiple' => 1,
];
$this->api_admin->client_balance_add_funds(['id' => 1, 'amount' => 100, 'description' => 'Added from PHPUnit']);
$this->api_guest->cart_add_item($data);
$this->api_client->cart_checkout();
$masterOrder = $this->di['db']->findOne('ClientOrder', 'group_master = 1 ORDER BY id desc');
$addonOrder = $this->di['db']->findOne('ClientOrder', 'group_id = ? and group_master = 0', [$masterOrder->group_id]);
$invoiceItemModel = $this->di['db']->findOne('InvoiceItem', "type = 'order' and rel_id = ?", [$masterOrder->id]);
$invoiceModel = $this->di['db']->load('Invoice', $invoiceItemModel->invoice_id);
$this->assertInstanceOf('Model_ClientOrder', $masterOrder);
$this->assertInstanceOf('Model_ClientOrder', $addonOrder);
$this->assertInstanceOf('Model_Invoice', $invoiceModel);
$this->assertNull($masterOrder->unpaid_invoice_id);
$this->assertEquals(Model_ClientOrder::STATUS_ACTIVE, $masterOrder->status);
$this->assertEquals(Model_ClientOrder::STATUS_ACTIVE, $addonOrder->status);
$this->assertEquals(Model_Invoice::STATUS_PAID, $invoiceModel->status);
}
}
@@ -1,556 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class Box_Mod_Cart_Api_GuestTest extends BBDbApiTestCase
{
protected $_initialSeedFile = 'mod_cart.xml';
public function testGet(): void
{
$cart = $this->api_guest->cart_get();
$this->assertIsArray($cart);
}
public function testCurrency(): void
{
$data = ['currency' => 'USD'];
$bool = $this->api_guest->cart_set_currency($data);
$this->assertTrue($bool);
$c = $this->api_guest->cart_get_currency();
$this->assertIsArray($c);
}
public function testReset(): void
{
$bool = $this->api_guest->cart_reset();
$this->assertTrue($bool);
}
public function testAddCustomProduct(): void
{
$this->api_guest->cart_reset();
$data = [
'id' => 1,
];
$bool = $this->api_guest->cart_add_item($data);
$this->assertTrue($bool);
}
public function testAddAddons(): void
{
$this->api_guest->cart_reset();
$pid = 1;
$data = [
'id' => $pid,
'addons' => [
5 => [
'selected' => 1,
'period' => '1Y',
'quantity' => 2,
],
],
];
$bool = $this->api_guest->cart_add_item($data);
$this->assertTrue($bool);
$cart = $this->api_guest->cart_get();
// main product must be first in cart
$this->assertEquals($pid, $cart['items'][0]['product_id']);
$this->assertEquals(2, count($cart['items']));
$this->assertEquals(2, $cart['items'][1]['quantity']);
}
public function testAddAddonsAddonPeriodNotEnabled(): void
{
$this->api_guest->cart_reset();
$pid = 1;
$data = [
'id' => $pid,
'addons' => [
5 => [
'selected' => 1,
'period' => '1W',
'quantity' => 2,
],
],
];
$this->expectException(FOSSBilling\Exception::class);
$this->expectExceptionMessage('Selected billing period is invalid for the selected add-on');
$bool = $this->api_guest->cart_add_item($data);
}
public function testAddAddonsMissingPeriodParameter(): void
{
$this->api_guest->cart_reset();
$pid = 1;
$data = [
'id' => $pid,
'addons' => [
5 => [
'selected' => 1,
'quantity' => 2,
],
],
];
$this->expectException(FOSSBilling\Exception::class);
$this->expectExceptionMessage('Addon period parameter not passed');
$bool = $this->api_guest->cart_add_item($data);
}
public function testAddAddonsAddonNotFoundById(): void
{
$this->api_guest->cart_reset();
$pid = 1;
$data = [
'id' => $pid,
'addons' => [
31 => [
'selected' => 1,
'quantity' => 2,
],
],
];
$return = $this->api_guest->cart_add_item($data);
$this->assertTrue($return);
}
/**
* @expectedException \FOSSBilling\Exception
*/
public function testAddDisabledPeriod(): void
{
$this->api_guest->cart_reset();
$data = [
'id' => 17,
'period' => '1W',
];
$this->api_guest->cart_add_item($data);
}
public function testAddDomainRegisterProduct(): void
{
$this->api_guest->cart_reset();
$data = [
'id' => 10,
'action' => 'register',
'register_tld' => '.com',
'register_sld' => 'mytestdomain',
'register_years' => 5,
];
$bool = $this->api_guest->cart_add_item($data);
$this->assertTrue($bool);
}
public function testAddDomainTransferProduct(): void
{
$this->api_guest->cart_reset();
$data = [
'id' => 10,
'action' => 'transfer',
'transfer_tld' => '.com',
'transfer_sld' => 'domaintotransfer',
'transfer_code' => 5,
];
$bool = $this->api_guest->cart_add_item($data);
$this->assertTrue($bool);
$cart = $this->api_guest->cart_get();
$item = $cart['items'][0];
$this->assertEquals('transfer', $item['action']);
$this->assertEquals('year', $item['unit']);
}
public function testAddLicenseProduct(): void
{
$this->api_guest->cart_reset();
$data = [
'id' => 6,
'period' => '3M',
];
$bool = $this->api_guest->cart_add_item($data);
$this->assertTrue($bool);
}
public function testAddDownloadableProduct(): void
{
$this->api_guest->cart_reset();
$data = [
'id' => 7,
];
$bool = $this->api_guest->cart_add_item($data);
$this->assertTrue($bool);
}
/* @TODO: Handle tests for external modules better
public function testAddSolusvmProduct()
{
$this->api_guest->cart_reset();
$data = array(
'id' => 15,
'period' => '3M',
'server_id' => 1,
'plan_id' => 1,
'hostname' => 'mydomain.com',
'template' => 'centos-6-x86',
'root_password' => 'optional', //if not passed then auto generated
);
$bool = $this->api_guest->cart_add_item($data);
$this->assertTrue($bool);
}
*/
public function testAddResellerHostingProduct(): void
{
$this->api_guest->cart_reset();
$data = [
'id' => 9,
'period' => '1Y',
'domain' => [
'action' => 'register',
'register_years' => 2,
'register_tld' => '.com',
'register_sld' => 'resellerdomain',
],
];
$bool = $this->api_guest->cart_add_item($data);
$this->assertTrue($bool);
}
public function testAddHostingProductWithDomainRegistration(): void
{
$this->api_guest->cart_reset();
$data = [
'id' => 8,
'period' => '3M',
'domain' => [
'action' => 'register',
'register_years' => 2,
'register_tld' => '.com',
'register_sld' => 'example',
],
];
$bool = $this->api_guest->cart_add_item($data);
$this->assertTrue($bool);
$cart = $this->api_guest->cart_get();
$this->assertTrue(count($cart['items']) == 2);
}
public function testAddHostingProductWithFreeDomainRegistration(): void
{
$this->api_guest->cart_reset();
$data = [
'id' => 11,
'period' => '3M',
'domain' => [
'action' => 'register',
'register_years' => 2,
'register_tld' => '.com',
'register_sld' => 'example',
],
];
$bool = $this->api_guest->cart_add_item($data);
$this->assertTrue($bool);
$cart = $this->api_guest->cart_get();
$this->assertTrue($cart['items'][1]['free_domain']);
$this->assertEquals(10, $cart['items'][1]['discount'], 'Could not set free domain for hosting product');
}
public function testAddHostingProductWithFreeDomainTransfer(): void
{
$this->api_guest->cart_reset();
$data = [
'id' => 11,
'period' => '3M',
'domain' => [
'action' => 'transfer',
'transfer_code' => '123',
'transfer_tld' => '.com',
'transfer_sld' => 'example',
],
];
$bool = $this->api_guest->cart_add_item($data);
$this->assertTrue($bool);
$cart = $this->api_guest->cart_get();
$this->assertTrue($cart['items'][1]['free_domain']);
$this->assertEquals(15, $cart['items'][1]['discount'], 'Could not set free transfer for hosting product');
}
public function testAddHostingProductWithDomainTransfer(): void
{
$this->api_guest->cart_reset();
$data = [
'id' => 8,
'period' => '3M',
'domain' => [
'action' => 'transfer',
'transfer_code' => 2,
'transfer_tld' => '.com',
'transfer_sld' => 'example',
],
];
$bool = $this->api_guest->cart_add_item($data);
$this->assertTrue($bool);
$cart = $this->api_guest->cart_get();
$this->assertTrue(count($cart['items']) == 2);
}
public function testAddHostingProductWithOwnDomainWhenExists(): void
{
$this->api_guest->cart_reset();
$data = [
'id' => 8,
'period' => '3M',
'domain' => [
'action' => 'owndomain',
'owndomain_tld' => '.com',
'owndomain_sld' => 'exist',
],
];
$bool = $this->api_guest->cart_add_item($data);
$this->assertTrue($bool);
}
public function testAddHostingProductWithOwnDomain(): void
{
$this->api_guest->cart_reset();
$data = [
'id' => 8,
'period' => '3M',
'domain' => [
'action' => 'owndomain',
'owndomain_tld' => '.com',
'owndomain_sld' => 'example',
],
];
$bool = $this->api_guest->cart_add_item($data);
$this->assertTrue($bool);
$cart = $this->api_guest->cart_get();
$this->assertTrue(count($cart['items']) == 1);
}
public function testFreeSetupPromo(): void
{
$this->api_admin->currency_set_default(['code' => 'USD']);
$this->api_guest->cart_reset();
$this->api_guest->cart_set_currency(['currency' => 'USD']);
// test custom products
$data = [
'id' => 13,
'quantity' => 1,
];
$bool = $this->api_guest->cart_add_item($data);
$this->assertTrue($bool);
$cart_before_promo = $this->api_guest->cart_get();
$this->assertNull($cart_before_promo['promocode']);
$data = ['promocode' => 'FREE_SETUP'];
$bool = $this->api_guest->cart_apply_promo($data);
$this->assertTrue($bool);
$cart_after_promo = $this->api_guest->cart_get();
$this->assertNotNull($cart_after_promo['promocode']);
$this->assertEquals(0, $cart_after_promo['items'][0]['discount_price']);
$this->assertEquals(20, $cart_after_promo['items'][0]['discount_setup']);
$this->assertEquals(20, $cart_after_promo['items'][0]['discount']);
$result = $this->api_client->cart_checkout();
$order = $this->api_client->order_get(['id' => $result['order_id']]);
$this->assertEquals(2, $order['promo_id']);
$invoice = $this->api_client->invoice_get(['hash' => $result['invoice_hash']]);
$this->assertEquals(50, $invoice['total']); // normal price
$this->assertEquals(50, $invoice['lines'][0]['price']); // normal price
$this->assertEquals(0, $invoice['lines'][1]['price']); // setup price
}
public function testApplyPromo(): void
{
$this->api_guest->cart_reset();
// test custom products
$data = [
'id' => 1,
'type' => 'custom',
'period' => '1M',
'quantity' => 1,
];
$bool = $this->api_guest->cart_add_item($data);
$this->assertTrue($bool);
$cart_before_promo = $this->api_guest->cart_get();
$data = ['promocode' => 'PHPUNIT'];
$bool = $this->api_guest->cart_apply_promo($data);
$this->assertTrue($bool);
$cart_after_promo = $this->api_guest->cart_get();
$this->assertTrue($cart_before_promo['total'] != $cart_after_promo['total'], 'Could not apply promo to cart');
$bool = $this->api_guest->cart_remove_promo($data);
$this->assertTrue($bool);
}
public function testRemoveItem(): void
{
$cart = $this->api_guest->cart_get();
foreach ($cart['items'] as $item) {
$bool = $this->api_guest->cart_remove_item(['id' => $item['id']]);
$this->assertTrue($bool);
}
}
public function testRemoveItemWithAddons(): void
{
$this->api_guest->cart_reset();
$data = [
'id' => 1,
'multiple' => true,
];
$bool = $this->api_guest->cart_add_item($data);
$cart = $this->api_guest->cart_get();
$this->assertEquals(1, count($cart['items']));
$data = [
'id' => 2,
'multiple' => true,
'addons' => [
3 => [
'selected' => 1,
'period' => '1Y',
'quantity' => 2,
],
4 => [
'selected' => 1,
'period' => '1Y',
],
],
];
$bool = $this->api_guest->cart_add_item($data);
$this->assertTrue($bool);
$cart = $this->api_guest->cart_get();
$this->assertEquals(4, count($cart['items']));
$this->api_guest->cart_remove_item(['id' => $cart['items'][1]['id']]); // removing second item from cart. Should remove its addons as well
$cart = $this->api_guest->cart_get();
$this->assertEquals(1, count($cart['items']));
}
public function testMultiple(): void
{
$res = $this->api_admin->invoice_get_list();
$this->assertEquals(0, $res['total'], 'Invoice exists in fixture?');
$this->api_guest->cart_reset();
$data = [
'id' => 1,
'type' => 'custom',
'period' => '1M',
'quantity' => 2,
'multiple' => true,
];
$bool = $this->api_guest->cart_add_item($data);
$this->assertTrue($bool);
$bool = $this->api_guest->cart_add_item($data);
$this->assertTrue($bool);
$cart = $this->api_guest->cart_get();
$this->assertEquals(2, count($cart['items']));
$res = $this->api_client->cart_checkout();
// one invoice for two products after checkout
$res = $this->api_admin->invoice_get_list();
$this->assertEquals(1, $res['total'], 'Generated more than one invoice');
}
public static function testApplyPromoForClientProvider()
{
$ids = [1, 2];
return [
[50, 5, $ids, true], // should throw exception because client group does not match ones set in Promo
[50, 2, $ids, false], // Client group ID is same as set for Promo, su discount must be applied
[50, 5, [], false], // Promo does not have any client group set, so it is valid for any client and should apply discount
[50, null, [], false], // Client group ID is not set and there are no group IDs in Promo, should apply discount
[50, null, $ids, true], // Client group ID is not set however there are group IDs in Promo, should throw an exception
];
}
#[PHPUnit\Framework\Attributes\DataProvider('testApplyPromoForClientProvider')]
public function testApplyPromoForClient($discount, $clientGroupId, $ids, $shouldThrowException): void
{
if ($shouldThrowException) {
$this->expectException(FOSSBilling\Exception::class);
}
$this->api_guest->cart_reset();
$data = [
'code' => '50OFF',
'type' => 'percentage',
'value' => $discount,
'active' => 1,
'client_groups' => $ids,
];
$id = $this->api_admin->product_promo_create($data);
$this->assertTrue(is_numeric($id));
$client = $this->di['loggedin_client'];
$client->client_group_id = $clientGroupId;
$data = [
'id' => 1,
'type' => 'custom',
'period' => '1M',
'quantity' => 1,
];
$bool = $this->api_guest->cart_add_item($data);
$this->assertTrue($bool);
$cart_before_promo = $this->api_guest->cart_get();
$data = ['promocode' => '50OFF'];
$bool = $this->api_guest->cart_apply_promo($data);
$this->assertTrue($bool);
$cart_after_promo = $this->api_guest->cart_get();
$this->assertTrue($cart_after_promo['total'] == $cart_before_promo['total'] - ($cart_before_promo['total'] * $discount / 100), 'Could not apply promo to cart');
}
}
@@ -1,249 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class Api_Admin_ClientTest extends BBDbApiTestCase
{
protected $_initialSeedFile = 'initial.xml';
public function testClient(): void
{
$data = [
'id' => 1,
];
$array = $this->api_admin->client_get($data);
$this->assertIsArray($array);
$array = $this->api_admin->client_login($data);
$this->assertIsArray($array);
$data['email'] = 'new@gmail.com';
$data['first_name'] = 'phpunit';
$data['last_name'] = 'same';
$data['status'] = 'active';
$bool = $this->api_admin->client_update($data);
$this->assertTrue($bool);
$data['password'] = 'new';
$data['password_confirm'] = 'new';
$bool = $this->api_admin->client_change_password($data);
$this->assertTrue($bool);
$array = $this->api_admin->client_get_statuses($data);
$this->assertIsArray($array);
$bool = $this->api_admin->client_balance_add_funds(['id' => 1, 'amount' => 100, 'description' => 'Added from PHPUnit']);
$this->assertTrue($bool);
$array = $this->api_admin->client_balance_get_list($data);
$this->assertIsArray($array);
$this->assertEquals(count($array['list']), 1);
$bool = $this->api_admin->client_balance_delete(['id' => 1]);
$this->assertTrue($bool);
$array = $this->api_admin->client_balance_get_list($data);
$this->assertIsArray($array);
$this->assertEquals(count($array['list']), 0);
$data = [
'id' => 1,
];
$bool = $this->api_admin->client_login_history_delete($data);
$this->assertTrue($bool);
$bool = $this->api_admin->client_batch_expire_password_reminders();
$this->assertTrue($bool);
}
public function testGetPairs(): void
{
$data = [
'search' => 'de',
];
$array = $this->api_admin->client_get_pairs($data);
$this->assertIsArray($array);
}
public function testGroups(): void
{
$data = [
'title' => 'testers',
];
$id = $this->api_admin->client_group_create($data);
$this->assertTrue(is_numeric($id));
$data['id'] = $id;
$bool = $this->api_admin->client_group_update($data);
$this->assertTrue($bool);
$array = $this->api_admin->client_group_get($data);
$this->assertIsArray($array);
$array = $this->api_admin->client_group_get_pairs($data);
$this->assertIsArray($array);
$bool = $this->api_admin->client_group_delete($data);
$this->assertTrue($bool);
}
public function testGet(): void
{
$data = [
'id' => 1,
];
$array = $this->api_admin->client_get($data);
$this->assertIsArray($array);
$this->assertNull($array['auth_type']);
}
public function testCreate(): void
{
$data = [
'email' => 'tester@gmail.com',
'first_name' => 'Client',
'password' => 'password',
];
$id = $this->api_admin->client_create($data);
$this->assertTrue($id > 1);
$bool = $this->api_admin->client_delete(['id' => $id]);
$this->assertTrue($bool);
}
public function testLoginHistoryGetList(): void
{
$array = $this->api_admin->client_login_history_get_list([]);
$this->assertIsArray($array);
$this->assertArrayHasKey('list', $array);
$list = $array['list'];
$this->assertIsArray($list);
if (count($list)) {
$item = $list[0];
$this->assertIsArray($item);
$this->assertArrayHasKey('id', $item);
$this->assertArrayHasKey('ip', $item);
$this->assertArrayHasKey('created_at', $item);
$this->assertArrayHasKey('client', $item);
$staff = $item['client'];
$this->assertIsArray($staff);
$this->assertArrayHasKey('id', $staff);
$this->assertArrayHasKey('first_name', $staff);
$this->assertArrayHasKey('last_name', $staff);
$this->assertArrayHasKey('email', $staff);
}
}
public function testClientGetList(): void
{
$array = $this->api_admin->client_get_list([]);
$this->assertIsArray($array);
$this->assertArrayHasKey('list', $array);
$list = $array['list'];
$this->assertIsArray($list);
if (count($list)) {
$item = $list[0];
$this->assertIsArray($item);
$this->assertArrayHasKey('id', $item);
$this->assertArrayHasKey('aid', $item);
$this->assertArrayHasKey('email', $item);
$this->assertArrayHasKey('type', $item);
$this->assertArrayHasKey('group_id', $item);
$this->assertArrayHasKey('company', $item);
$this->assertArrayHasKey('company_vat', $item);
$this->assertArrayHasKey('company_number', $item);
$this->assertArrayHasKey('first_name', $item);
$this->assertArrayHasKey('last_name', $item);
$this->assertArrayHasKey('gender', $item);
$this->assertArrayHasKey('birthday', $item);
$this->assertArrayHasKey('phone_cc', $item);
$this->assertArrayHasKey('phone', $item);
$this->assertArrayHasKey('address_1', $item);
$this->assertArrayHasKey('address_2', $item);
$this->assertArrayHasKey('city', $item);
$this->assertArrayHasKey('state', $item);
$this->assertArrayHasKey('postcode', $item);
$this->assertArrayHasKey('country', $item);
$this->assertArrayHasKey('currency', $item);
$this->assertArrayHasKey('notes', $item);
$this->assertArrayHasKey('created_at', $item);
$this->assertArrayHasKey('balance', $item);
$this->assertArrayHasKey('auth_type', $item);
$this->assertArrayHasKey('api_token', $item);
$this->assertArrayHasKey('ip', $item);
$this->assertArrayHasKey('status', $item);
$this->assertArrayHasKey('tax_exempt', $item);
$this->assertArrayHasKey('group', $item);
$this->assertArrayHasKey('updated_at', $item);
}
}
public function testClientBalanceGetList(): void
{
$bool = $this->api_admin->client_balance_add_funds(['id' => 1, 'amount' => 100, 'description' => 'Added from PHPUnit']);
$this->assertTrue($bool);
$array = $this->api_admin->client_balance_get_list([]);
$this->assertIsArray($array);
$this->assertArrayHasKey('list', $array);
$list = $array['list'];
$this->assertIsArray($list);
if (count($list)) {
$item = $list[0];
$this->assertIsArray($item);
$this->assertArrayHasKey('id', $item);
$this->assertArrayHasKey('description', $item);
$this->assertArrayHasKey('amount', $item);
$this->assertArrayHasKey('currency', $item);
$this->assertArrayHasKey('created_at', $item);
}
}
public function testClientBatchDelete(): void
{
$id = $this->api_admin->client_create(
[
'email' => 'tester@gmail.com',
'first_name' => 'Client',
'password' => 'password',
]);
$id2 = $this->api_admin->client_create(
[
'email' => 'tester2@gmail.com',
'first_name' => 'Client',
'password' => 'password',
]);
$id3 = $this->api_admin->client_create(
[
'email' => 'tester3@gmail.com',
'first_name' => 'Client',
'password' => 'password',
]);
$array = $this->api_admin->client_get_list([]);
$count = count($array['list']);
$result = $this->api_admin->client_batch_delete(['ids' => [$id, $id2, $id3]]);
$array = $this->api_admin->client_get_list([]);
$this->assertEquals($count - 3, count($array['list']));
$this->assertTrue($result);
}
public function testClientBatchDeleteLog(): void
{
$this->api_admin->client_login(['id' => 1]);
$array = $this->api_admin->client_login_history_get_list([]);
$result = $this->api_admin->client_batch_delete_log(['ids' => [$array['list'][0]]]);
$array = $this->api_admin->client_login_history_get_list([]);
$this->assertEquals(0, count($array['list']));
$this->assertTrue($result);
}
}
@@ -1,65 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class Api_ClientTest extends BBDbApiTestCase
{
protected $_initialSeedFile = 'initial.xml';
public function testClient(): void
{
$array = $this->api_client->client_get();
$this->assertIsArray($array);
$data = [
'email' => 'newEmail@fossbilling.org',
'first_name' => 'John',
'last_name' => 'Doe',
'gender' => 'male',
'birthday' => '1987.10.11',
'company' => 'FOSSBilling',
'address_1' => 'Wall Street 45',
'phone_cc' => 'FOSSBilling',
'country' => 'USA',
'currency' => 'USD',
'postcode' => 123456,
'api_token' => 'phpunit_token',
];
$bool = $this->api_client->client_update($data);
$this->assertTrue($bool);
$key = $this->api_client->client_api_key_get([]);
$this->assertIsString($key);
$newKey = $this->api_client->client_api_key_reset([]);
$this->assertIsString($newKey);
$this->assertNotEquals($key, $newKey);
$data = [
'password' => 'newPa55word',
'password_confirm' => 'newPa55word',
];
$bool = $this->api_client->client_change_password($data);
$this->assertTrue($bool);
$array = $this->api_client->client_balance_get_list($data);
$this->assertIsArray($array);
}
public function testClientBalanceGetList(): void
{
$array = $this->api_client->client_balance_get_list([]);
$this->assertIsArray($array);
$this->assertArrayHasKey('list', $array);
$list = $array['list'];
$this->assertIsArray($list);
if (count($list)) {
$item = $list[0];
$this->assertIsArray($item);
$this->assertArrayHasKey('id', $item);
$this->assertArrayHasKey('description', $item);
$this->assertArrayHasKey('amount', $item);
$this->assertArrayHasKey('currency', $item);
$this->assertArrayHasKey('created_at', $item);
}
}
}
@@ -1,189 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class Api_Guest_ClientTest extends BBDbApiTestCase
{
protected $_initialSeedFile = 'initial.xml';
public function testCreate(): void
{
$this->api_admin->extension_config_save([
'ext' => 'mod_client',
'required' => [],
]);
$e = random_int(5, 56666) . '@gmail.com';
$pass = 'testA1sssss';
$data = [
'aid' => '2',
'email' => $e,
'first_name' => 'John',
'last_name' => 'Doe',
'address_1' => 'Palo Alto',
'country' => 'USA',
'company_vat' => 'LS-2qwddwqdsd12',
'city' => 'California',
'tel_cc' => '211',
'phone' => '11212156485451',
'password' => $pass,
'password_confirm' => $pass,
];
$id = $this->api_guest->client_create($data);
$this->assertIsInt($id);
$client = $this->di['db']->load('Client', $id);
$this->assertNotEquals($data['password'], $client->pass);
$this->assertTrue($this->di['password']->verify($data['password'], $client->pass));
}
/**
* @expectedException \FOSSBilling\Exception
*/
public function testRequiredFields(): void
{
$this->api_admin->extension_config_save([
'ext' => 'mod_client',
'required' => [
'last_name',
],
]);
$pass = 'testA222sssww';
$data = [
'email' => 'test@example.com',
'first_name' => 'John',
'password' => $pass,
'password_confirm' => $pass,
];
$id = $this->api_guest->client_create($data);
}
public function testPasswordReset(): void
{
$data = [
'email' => 'client@fossbilling.org',
];
$bool = $this->api_guest->client_reset_password($data);
$this->assertTrue($bool);
$data = [
'hash' => 'hash',
];
$bool = $this->api_guest->client_confirm_reset($data);
$this->assertTrue($bool);
}
public function testVat(): void
{
$data = [
'country' => 'GB',
'vat' => 'GB999 9999 73',
];
$bool = $this->api_guest->client_is_vat($data);
// $this->assertTrue($bool);
}
public function testClientLogin(): void
{
$data = [
'email' => 'client@fossbilling.org',
'password' => 'demo',
];
$array = $this->api_guest->client_login($data);
$this->assertIsArray($array);
$this->assertTrue(is_numeric($this->session->get('client_id')), 'Client id is not integer');
$bool = $this->api_client->client_logout($data);
$this->assertNull($this->session->get('client_id'));
$this->assertTrue($bool);
$this->assertNull($this->session->get('admin'));
}
public function testRequired(): void
{
$array = $this->api_guest->client_required();
$this->assertIsArray($array);
}
public function testCreateWithCustom(): void
{
$this->api_admin->extension_config_save([
'ext' => 'mod_client',
'required' => [
'last_name',
],
'custom_fields' => [
'custom_5' => [
'active' => true,
'required' => true,
'title' => 'Your username',
],
],
]);
$e = random_int(5, 56666) . '@gmail.com';
$pass = 'testA1sssss';
$data = [
'aid' => '2',
'email' => $e,
'first_name' => 'John',
'last_name' => 'Doe',
'address_1' => 'Palo Alto',
'country' => 'USA',
'company_vat' => 'LS-2qwddwqdsd12',
'city' => 'California',
'tel_cc' => '211',
'phone' => '11212156485451',
'password' => $pass,
'password_confirm' => $pass,
'custom_5' => 'JohnUsername',
];
$id = $this->api_guest->client_create($data);
$this->assertIsInt($id);
$client = $this->di['db']->load('Client', $id);
$this->assertEquals($data['custom_5'], $client->custom_5);
}
/**
* @expectedException \FOSSBilling\Exception
*/
public function testCreateWithCustomRequiredException(): void
{
$this->api_admin->extension_config_save([
'ext' => 'mod_client',
'required' => [
'last_name',
],
'custom_fields' => [
'custom_5' => [
'active' => true,
'required' => true,
'title' => 'Your username',
],
],
]);
$e = random_int(5, 56666) . '@gmail.com';
$pass = 'testA1sssss';
$data = [
'aid' => '2',
'email' => $e,
'first_name' => 'John',
'last_name' => 'Doe',
'address_1' => 'Palo Alto',
'country' => 'USA',
'company_vat' => 'LS-2qwddwqdsd12',
'city' => 'California',
'tel_cc' => '211',
'phone' => '11212156485451',
'password' => $pass,
'password_confirm' => $pass,
];
$id = $this->api_guest->client_create($data);
}
}
@@ -1,122 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class Box_Mod_Client_ServiceTest extends ApiTestCase
{
public function testEvents(): void
{
$service = new Box\Mod\Client\Service();
$service->setDi($this->di);
$params = [
'id' => 1,
'password' => 'qwerty123',
];
$event = new Box_Event(null, 'name', $params, $this->api_admin, $this->api_guest);
$event->setDi($this->di);
$bool = $service->onAfterClientSignUp($event);
$this->assertTrue($bool);
}
public function testGenerateEmailConfirmationLink(): void
{
$service = new Box\Mod\Client\Service();
$service->setDi($this->di);
$link = $service->generateEmailConfirmationLink(1);
$this->assertIsString($link);
$this->assertEquals(strpos($link, 'http://'), 0);
}
public function testRemove(): void
{
// We have a client
$data = [
'email' => 'tester@gmail.com',
'first_name' => 'Client',
'password' => 'password',
];
$id = $this->api_admin->client_create($data);
$this->assertTrue($id > 1);
// Client has license orders
$data['client_id'] = $id;
$data['product_id'] = 6;
$data['period'] = '1M';
$data['invoice_option'] = 'issue-invoice';
$data['activate'] = 1;
$data['config'] = [];
$orderId = $this->api_admin->order_create($data);
$this->assertIsInt($orderId);
// Client has invoice with items for order
$invoiceModel = $this->di['db']->findOne('Invoice', 'client_id = ?', [$id]);
$this->assertInstanceOf('Model_Invoice', $invoiceModel);
$invoiceItemModel = $this->di['db']->findOne('InvoiceItem', 'invoice_id = ?', [$invoiceModel->id]);
$this->assertInstanceOf('Model_InvoiceItem', $invoiceItemModel);
// Client has amount in balance
$bool = $this->api_admin->client_balance_add_funds(['id' => 1, 'amount' => 100, 'description' => 'Added from PHPUnit']);
$this->assertTrue($bool);
// Client has activity history
$log = $this->di['db']->dispense('ActivityClientHistory');
$log->client_id = $id;
$log->ip = '10.0.0.1';
$log->created_at = date('Y-m-d H:i:s');
$log->updated_at = date('Y-m-d H:i:s');
$this->di['db']->store($log);
// Client has email activity
$entry = $this->di['db']->dispense('ActivityClientEmail');
$entry->client_id = $id;
$entry->created_at = date('Y-m-d H:i:s');
$entry->updated_at = date('Y-m-d H:i:s');
$this->di['db']->store($entry);
// Client has system activity
$systemEntry = $this->di['db']->dispense('ActivitySystem');
$systemEntry->client_id = $id;
$systemEntry->message = 'PHP UNIT TEST';
$systemEntry->created_at = date('Y-m-d H:i:s');
$systemEntry->updated_at = date('Y-m-d H:i:s');
$this->di['db']->store($systemEntry);
// Client has passwordReset record
$r = $this->di['db']->dispense('ClientPasswordReset');
$r->client_id = $id;
$r->ip = '10.0.0.1';
$r->hash = sha1(random_int(50, random_int(10, 99)));
$r->created_at = date('Y-m-d H:i:s');
$r->updated_at = date('Y-m-d H:i:s');
$this->di['db']->store($r);
$clientModel = $this->di['db']->load('Client', $id);
$this->assertInstanceOf('Model_Client', $clientModel);
$service = new Box\Mod\Client\Service();
$service->setDi($this->di);
$service->remove($clientModel);
// Removed items from Db
$model = $this->di['db']->load('ClientOrder', $orderId);
$this->assertNull($model);
$model = $this->di['db']->load('Invoice', $invoiceModel->id);
$this->assertNull($model);
$model = $this->di['db']->load('InvoiceItem', $invoiceItemModel->id);
$this->assertNull($model);
$model = $this->di['db']->load('ActivityClientHistory', $log->id);
$this->assertNull($model);
$model = $this->di['db']->load('ActivityClientEmail', $entry->id);
$this->assertNull($model);
$model = $this->di['db']->load('ActivitySystem', $systemEntry->id);
$this->assertNull($model);
$model = $this->di['db']->load('ClientPasswordReset', $r->id);
$this->assertNull($model);
$model = $this->di['db']->find('ClientBalance', 'client_id = ?', [$clientModel->id]);
$this->assertEmpty($model);
$model = $this->di['db']->findOne('Client', $clientModel->id);
$this->assertNull($model);
}
}
@@ -1,16 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class Api_AdminTest extends BBDbApiTestCase
{
protected $_initialSeedFile = 'orders.xml';
public function testRun(): void
{
$array = $this->api_system->cron_info();
$this->assertIsArray($array);
$bool = $this->api_system->cron_run();
$this->assertTrue($bool);
}
}
@@ -1,60 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class Api_Admin_CurrencyTest extends BBDbApiTestCase
{
protected $_initialSeedFile = 'currencies.xml';
public function testCurrencies(): void
{
$array = $this->api_admin->currency_get_pairs();
$this->assertIsArray($array);
$array = $this->api_admin->currency_get(['code' => 'USD']);
$this->assertIsArray($array);
$this->assertEquals('USD', $array['code']);
$array = $this->api_admin->currency_get_default();
$this->assertIsArray($array);
$data = [
'code' => 'GBP',
'title' => 'British Pound',
'format' => '{{price}}£',
];
$code = $this->api_admin->currency_create($data);
$this->assertIsString($code);
$bool = $this->api_admin->currency_update($data);
$this->assertTrue($bool);
$bool = $this->api_admin->currency_delete($data);
$this->assertTrue($bool);
$data['code'] = 'EUR';
$bool = $this->api_admin->currency_set_default($data);
$this->assertTrue($bool);
$bool = $this->api_admin->currency_update_rates();
$this->assertTrue($bool);
}
public function testCurerncyGetList(): void
{
$array = $this->api_admin->currency_get_list();
$this->assertIsArray($array);
$this->assertArrayHasKey('list', $array);
$list = $array['list'];
$this->assertIsArray($list);
if (count($list)) {
$item = $list[0];
$this->assertArrayHasKey('code', $item);
$this->assertArrayHasKey('title', $item);
$this->assertArrayHasKey('conversion_rate', $item);
$this->assertArrayHasKey('format', $item);
$this->assertArrayHasKey('price_format', $item);
$this->assertArrayHasKey('default', $item);
}
}
}
@@ -1,36 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class Api_GuestTest extends BBDbApiTestCase
{
protected $_initialSeedFile = 'currencies.xml';
public function testFormat(): void
{
$string = $this->api_guest->currency_format(['price' => '2']);
$this->assertEquals('$2.00', $string);
$string = $this->api_guest->currency_format(['price' => '2', 'convert' => 0]);
$this->assertEquals('$2.00', $string);
$string = $this->api_guest->currency_format(['price' => '1', 'code' => 'EUR', 'convert' => 0]);
$this->assertEquals('1.00 EUR', $string);
$string = $this->api_guest->currency_format(['price' => '1', 'code' => 'EUR', 'convert' => 1]);
$this->assertEquals('0.75 EUR', $string);
}
public function testCurrency(): void
{
$array = $this->api_guest->currency_get_pairs();
$this->assertIsArray($array);
$array = $this->api_guest->currency_get(['code' => 'usd']);
$this->assertIsArray($array);
$this->assertEquals('USD', $array['code']);
$array = $this->api_guest->currency_get(['code' => 'eur']);
$this->assertIsArray($array);
$this->assertEquals('EUR', $array['code']);
}
}
@@ -1,260 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class Api_AdminTest extends BBDbApiTestCase
{
protected $_initialSeedFile = 'emails.xml';
public function testGenerate(): void
{
$bool = $this->api_admin->email_batch_template_generate();
$this->assertTrue($bool);
}
public function testReset(): void
{
$data = [
'code' => 'mod_email_test',
];
$bool = $this->api_admin->email_template_reset($data);
$this->assertTrue($bool);
}
public function testTemplates(): void
{
$array = $this->api_admin->email_template_get_list();
$this->assertIsArray($array);
$data = [
'id' => 1,
];
$array = $this->api_admin->email_template_get($data);
$this->assertIsArray($array);
$data = [
'action_code' => 'test',
'subject' => 'test',
'enabled' => 1,
'content' => 'test',
];
$id = $this->api_admin->email_template_create($data);
$this->assertTrue($id > 0);
$data['id'] = $id;
$bool = $this->api_admin->email_template_update($data);
$this->assertTrue($bool);
$bool = $this->api_admin->email_template_delete($data);
$this->assertTrue($bool);
}
public function testUpdate(): void
{
$subject = 'New subject';
$data['id'] = 1;
$data['subject'] = $subject;
$bool = $this->api_admin->email_template_update($data);
$this->assertTrue($bool);
$array = $this->api_admin->email_template_get($data);
$this->assertEquals($subject, $array['subject']);
}
public function testEmails(): void
{
$array = $this->api_admin->email_email_get_list();
$this->assertIsArray($array);
$data = [
'id' => 1,
];
$array = $this->api_admin->email_email_get($data);
$this->assertIsArray($array);
}
public function testSend(): void
{
$data = [
'to' => 'demo@boxbiling.com',
'to_name' => 'Client name',
'from' => 'admin@fossbilling.org',
'from_name' => 'Admin',
'subject' => 'This is subject',
'content' => 'This is message',
];
$bool = $this->api_admin->email_send($data);
$this->assertTrue($bool);
}
public function testResend(): void
{
$data = [
'id' => 1,
];
$bool = $this->api_admin->email_email_resend($data);
$this->assertTrue($bool);
$array = $this->api_admin->email_email_get_list();
$this->assertEquals(2, $array['total']);
}
public function testDelete(): void
{
$data = [
'id' => 1,
];
$bool = $this->api_admin->email_email_delete($data);
$this->assertTrue($bool);
$array = $this->api_admin->email_email_get_list();
$this->assertEquals(0, $array['total']);
}
public function testBatch(): void
{
$bool = $this->api_admin->email_batch_template_disable();
$this->assertTrue($bool);
$bool = $this->api_admin->email_batch_template_enable();
$this->assertTrue($bool);
}
public function testCheck(): void
{
$bool = $this->api_admin->email_send_test();
$this->assertTrue($bool);
}
public function testRender(): void
{
$data = [
'id' => 1,
'_tpl' => '{{ now|date("Y") }}',
];
$string = $this->api_admin->email_template_render($data);
$this->assertEquals(date('Y'), $string);
}
public function testTemplateGeneralSend(): void
{
$params = [];
$params['to'] = 'client@fossbilling.org';
$params['to_name'] = 'Client PHPUnit';
$params['code'] = 'mod_client_signup';
$params['default_template'] = 'Hello, message from {{ admin.client_get({"id":client_id}).first_name }}, {{subject}}';
$params['default_subject'] = 'My subject for client';
$params['client_id'] = 1;
$bool = $this->api_admin->email_template_send($params);
$this->assertTrue($bool);
}
public function testTemplatePopulateVariables(): void
{
$params = [];
$params['to'] = 'client@fossbilling.org';
$params['to_name'] = 'Client PHPUnit';
$params['code'] = 'mod_client_signup';
$params['default_template'] = 'Hello, message from {{ admin.client_get({"id":client_id}).first_name }}, {{subject}}';
$params['default_subject'] = 'My subject for client';
$params['to_client'] = 1;
$bool = $this->api_admin->email_template_send($params);
$this->assertTrue($bool);
$emailModel = $this->di['db']->findOne('ModEmailQueue', ' order by id desc');
$clientModel = $this->di['db']->load('Client', $params['to_client']);
$this->assertTrue(str_contains($emailModel->subject, $clientModel->first_name), 'Template variables were not populated');
}
public function testSendToClient(): void
{
$params = [];
$params['to_client'] = 1;
$params['code'] = 'mod_client_signup';
$bool = $this->api_admin->email_template_send($params);
$this->assertTrue($bool);
}
public function testSendToStaff(): void
{
$params = [];
$params['to_staff'] = true;
$params['code'] = 'mod_staff_client_signup';
$params['client'] = $this->api_admin->client_get(['id' => 1]);
$bool = $this->api_admin->email_template_send($params);
$this->assertTrue($bool);
}
public function testBatchSendmail(): void
{
$result = $this->api_admin->email_batch_sendmail();
$this->assertNull($result);
}
public function testEmailEmailGetList(): void
{
$array = $this->api_admin->email_email_get_list();
$this->assertIsArray($array);
$this->assertArrayHasKey('list', $array);
$list = $array['list'];
$this->assertIsArray($list);
if (count($list)) {
$item = $list[0];
$this->assertArrayHasKey('id', $item);
$this->assertArrayHasKey('client_id', $item);
$this->assertArrayHasKey('sender', $item);
$this->assertArrayHasKey('recipients', $item);
$this->assertArrayHasKey('subject', $item);
$this->assertArrayHasKey('content_html', $item);
$this->assertArrayHasKey('content_text', $item);
$this->assertArrayHasKey('created_at', $item);
$this->assertArrayHasKey('updated_at', $item);
}
}
public function testEmailTemplateGetList(): void
{
$array = $this->api_admin->email_template_get_list();
$this->assertIsArray($array);
$this->assertArrayHasKey('list', $array);
$list = $array['list'];
$this->assertIsArray($list);
if (count($list)) {
$item = $list[0];
$this->assertArrayHasKey('id', $item);
$this->assertArrayHasKey('action_code', $item);
$this->assertArrayHasKey('category', $item);
$this->assertArrayHasKey('enabled', $item);
$this->assertArrayHasKey('subject', $item);
$this->assertArrayHasKey('description', $item);
}
}
public function testBatchDelete(): void
{
$array = $this->api_admin->email_email_get_list([]);
foreach ($array['list'] as $value) {
$ids[] = $value['id'];
}
$result = $this->api_admin->email_batch_delete(['ids' => $ids]);
$array = $this->api_admin->email_email_get_list([]);
$this->assertEquals(0, count($array['list']));
$this->assertTrue($result);
}
}
@@ -1,66 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class Api_Client_EmailTest extends BBDbApiTestCase
{
protected $_initialSeedFile = 'emails.xml';
public function testEmails(): void
{
$array = $this->api_client->email_get_list();
$this->assertIsArray($array);
$data = [
'id' => 1,
];
$array = $this->api_client->email_get($data);
$this->assertIsArray($array);
}
public function testResend(): void
{
$data = [
'id' => 1,
];
$bool = $this->api_client->email_resend($data);
$this->assertTrue($bool);
$array = $this->api_client->email_get_list();
$this->assertEquals(2, $array['total']);
}
public function testDelete(): void
{
$data = [
'id' => 1,
];
$bool = $this->api_client->email_delete($data);
$this->assertTrue($bool);
$array = $this->api_client->email_get_list();
$this->assertEquals(0, $array['total']);
}
public function testEmailEmailGetList(): void
{
$array = $this->api_client->email_get_list();
$this->assertIsArray($array);
$this->assertArrayHasKey('list', $array);
$list = $array['list'];
$this->assertIsArray($list);
if (count($list)) {
$item = $list[0];
$this->assertArrayHasKey('id', $item);
$this->assertArrayHasKey('client_id', $item);
$this->assertArrayHasKey('sender', $item);
$this->assertArrayHasKey('recipients', $item);
$this->assertArrayHasKey('subject', $item);
$this->assertArrayHasKey('content_html', $item);
$this->assertArrayHasKey('content_text', $item);
$this->assertArrayHasKey('created_at', $item);
$this->assertArrayHasKey('updated_at', $item);
}
}
}
@@ -1,16 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class Api_ClientTest extends BBDbApiTestCase
{
protected $_mod = 'example';
protected $_initialSeedFile = 'mod_example.xml';
public function testExample(): void
{
$this->api_admin->extension_activate(['id' => 'example', 'type' => 'mod']);
$array = $this->api_client->example_get_info();
$this->assertIsArray($array);
}
}
@@ -1,60 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class ServiceTest extends BBDbApiTestCase
{
protected $_initialSeedFile = 'example.xml';
public function testUninstall(): void
{
$service = new Box\Mod\Example\Service();
$result = $service->uninstall();
$this->assertTrue($result);
}
public function testUpdate(): void
{
$service = new Box\Mod\Example\Service();
$result = $service->update([]);
$this->assertTrue($result);
}
public function testGetSearchQuery(): void
{
$service = new Box\Mod\Example\Service();
$di = new Pimple\Container();
$service->setDi($di);
$data = [
'client_id' => 1,
];
[$sql, $params] = $service->getSearchQuery($data);
$this->assertIsString($sql);
$this->assertIsArray($params);
$this->assertArrayHasKey(':client_id', $params);
$this->assertEquals($params[':client_id'], $data['client_id']);
}
public function testEvents(): void
{
$service = new Box\Mod\Example\Service();
$params = [
'ip' => '123.123.123.123',
];
$event = new Box_Event(null, 'name', $params, $this->api_admin, $this->api_guest);
$event->setDi($this->di);
$result = $service->onEventClientLoginFailed($event);
$this->assertNull($result);
$params = [
'client_id' => 1,
'id' => 1,
];
$event = new Box_Event(null, 'name', $params, $this->api_admin, $this->api_guest);
$event->setDi($this->di);
$result = $service->onAfterClientOrderCreate($event);
$this->assertNull($result);
}
}
@@ -1,171 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class Api_Admin_ExtensionTest extends BBDbApiTestCase
{
protected $_initialSeedFile = 'extensions.xml';
public function testSetup(): void
{
$data = [
'code' => 'extension',
];
try {
// do not allow install core extension
$bool = $this->api_admin->extension_mod_install($data);
$this->fail('Core extension cannot be installed');
} catch (Box_Exception) {
$this->assertTrue(true);
}
try {
// do not allow uninstall core extension
$bool = $this->api_admin->extension_mod_uninstall($data);
$this->fail('Core extension cannot be uninstalled');
} catch (Box_Exception) {
$this->assertTrue(true);
}
}
public function testUninstall(): void
{
$data = [
'type' => 'mod',
'id' => 'news',
];
$bool = $this->api_admin->extension_uninstall($data);
$this->assertTrue($bool);
}
public function testUpdate(): void
{
$versions = [
'version_old' => '1.1.1',
'version_new' => '2.2.2',
];
$extension = new Model_Extension();
$extension->loadBean(new RedBeanPHP\OODBBean());
$serviceMock = $this->getMockBuilder('\\' . Box\Mod\Extension\Service::class)->onlyMethods(['update', 'findExtension'])->getMock();
$serviceMock->expects($this->any())
->method('update')
->willReturn($versions);
$serviceMock->expects($this->any())
->method('findExtension')
->willReturn($extension);
$serviceMock->setDi($this->di);
$data = [
'type' => 'mod',
'id' => 'branding',
];
$api = new Box\Mod\Extension\Api\Admin();
$api->setDi($this->di);
$api->setService($serviceMock);
$arr = $api->update($data);
$this->assertEquals($arr, $versions);
}
public function testConfigs(): void
{
$data = [
'ext' => 'mod_email',
'mailer' => 'mail',
'smtp_host' => 'hostname',
'smtp_port' => 55,
'smtp_username' => 'username',
'smtp_password' => 'sasd132423%3@#//',
'smtp_security' => 'yes',
];
$bool = $this->api_admin->extension_config_save($data);
$this->assertTrue($bool);
$array = $this->api_admin->extension_config_get($data);
$array['ext'] = 'mod_email';
$this->assertIsArray($array);
$this->assertEquals($data, $array);
}
public function testActivations(): void
{
$data = [
'id' => 'news',
'type' => 'mod',
];
$array = $this->api_admin->extension_activate($data);
$this->assertIsArray($array);
$bool = $this->api_guest->extension_is_on($data);
$this->assertTrue($bool);
$bool = $this->api_admin->extension_deactivate($data);
$this->assertTrue($bool);
$bool = $this->api_guest->extension_is_on($data);
$this->assertFalse($bool);
}
public function testLists(): void
{
$data = [
'type' => 'server-manager',
];
$array = $this->api_admin->extension_get_list($data);
$this->assertIsArray($array);
$array = $this->api_admin->extension_get_list(['active' => true, 'type' => 'mod', 'search' => 'f']);
$this->assertIsArray($array);
$array = $this->api_admin->extension_get_list(['installed' => true]);
$this->assertIsArray($array);
$array = $this->api_admin->extension_get_list(['has_settings' => true]);
$this->assertIsArray($array);
$array = $this->api_admin->extension_get_latest();
$this->assertIsArray($array);
$array = $this->api_admin->extension_get_navigation();
$this->assertIsArray($array);
$array = $this->api_admin->extension_languages();
$this->assertIsArray($array);
$array = $this->api_admin->extension_languages();
$this->assertIsArray($array);
}
public function testUpdateCore(): void
{
$bool = $this->api_admin->extension_update_core();
$this->assertTrue($bool);
}
public function testInstall(): void
{
$extension = new Model_Extension();
$extension->loadBean(new RedBeanPHP\OODBBean());
$serviceMock = $this->getMockBuilder('\\' . Box\Mod\Extension\Service::class)->onlyMethods(['downloadAndExtract'])->getMock();
$serviceMock->expects($this->any())
->method('downloadAndExtract')
->willReturn(true);
$serviceMock->setDi($this->di);
$data = [
'id' => 'branding',
'type' => 'mod',
];
$api = new Box\Mod\Extension\Api\Admin();
$api->setService($serviceMock);
$api->setDi($this->di);
$arr = $api->install($data);
$expected = $data;
$expected['success'] = true;
$this->assertEquals($arr, $expected);
}
}
@@ -1,22 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class Api_Guest_ExtensionTest extends BBDbApiTestCase
{
protected $_initialSeedFile = 'extensions.xml';
public function testLists(): void
{
$array = $this->api_guest->extension_languages();
$this->assertIsArray($array);
$array = $this->api_guest->extension_theme();
$this->assertIsArray($array);
$bool = $this->api_guest->extension_is_on(['mod' => 'system']);
$this->assertTrue($bool);
$arr = $this->api_guest->extension_settings(['ext' => 'mod_email']);
$this->assertIsArray($arr);
}
}
@@ -1,14 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class Box_Mod_Extension_ServiceTest extends BBDbApiTestCase
{
public function testEvents(): void
{
$event = $this->_bb_event = new Box_Event(null, 'name', [], $this->api_admin, $this->api_guest);
$event->setDi($this->di);
$service = new Box\Mod\Extension\Service();
$bool = $service->onBeforeAdminCronRun($event);
$this->assertTrue($bool);
}
}
@@ -1,356 +0,0 @@
<?php
class Api_Admin_FormbuilderTest extends BBDbApiTestCase
{
protected $_initialSeedFile = 'mod_formbuilder.xml';
/**
* Box_Exception.
*/
public function testFormExceptions(): void
{
try {
$this->api_admin->formbuilder_get_form(['id' => 10000]);
$this->fail('An expected exception has not been raised.');
} catch (Box_Exception) {
}
try {
$this->api_admin->formbuilder_create_form(['name' => null]);
} catch (Box_Exception) {
}
try {
$this->api_admin->formbuilder_create_form(['title' => 'Form title', 'style' => 'not existing style']);
} catch (Box_Exception) {
}
try {
$this->api_admin->formbuilder_add_field(['id' => 1, 'type' => 'type']);
$this->fail('An expected exception has not been raised.');
} catch (Box_Exception) {
}
try {
$this->api_admin->formbuilder_add_field(['id' => 1_000_000_000]);
$this->fail('An expected exception has not been raised.');
} catch (Box_Exception) {
}
try {
$this->api_admin->formbuilder_add_field([
'id' => 1,
'form_id' => 1,
'type' => 'unexisting type',
]);
$this->fail('An expected exception has not been raised.');
} catch (Box_Exception) {
}
try {
$this->api_admin->formbuilder_get_form(['id' => 10000]);
$this->fail('An expected exception has not been raised.');
} catch (Box_Exception) {
}
try {
$this->api_admin->formbuilder_get_form_fields(['id' => 1]);
$this->fail('An expected exception has not been raised.');
} catch (Box_Exception) {
}
try {
$this->api_admin->formbuilder_get_field(['id' => 1_000_000]);
$this->fail('An expected exception has not been raised.');
} catch (Box_Exception) {
}
try {
$this->api_admin->formbuilder_delete_form(['id' => 1]);
$this->api_admin->formbuilder_get_form(['id' => 1]);
$this->fail('An expected exception has not been raised.');
} catch (Box_Exception) {
}
try {
$this->api_admin->formbuilder_delete_field(['id' => 1]);
$this->api_admin->formbuilder_get_field(['id' => 1]);
$this->fail('An expected exception has not been raised.');
} catch (Box_Exception) {
}
try {
$this->api_admin->formbuilder_delete_field(['id' => 1]);
$this->api_admin->formbuilder_get_field(['id' => 1]);
$this->fail('An expected exception has not been raised.');
} catch (Box_Exception) {
}
try {
$this->api_admin->formbuilder_update_field(['id' => 3, 'description' => 'This is very awesome description.', 'name' => '']);
$this->fail('An expected exception has not been raised.');
} catch (Box_Exception) {
}
try {
$test = $this->api_admin->formbuilder_add_field([
'description' => 'Form field description',
'label' => 'Field label',
'id' => 2,
'form_id' => 2,
'hide_label' => 0,
'name' => 'Form field name',
'type' => 'checkbox',
'default_value' => 'Default',
'required' => 0,
'hidden' => 1,
'readonly' => 0,
'options' => ['Key' => '2', '2' => '2'],
'show_initial' => 'initial',
'show_middle' => 'middle',
'show_prefix' => 'prefix',
'show_suffix' => 'suffix',
'text_size' => 499,
]);
$this->api_admin->formbuilder_update_field($test);
$this->fail('An expected exception has not been raised.');
} catch (Box_Exception) {
}
try {
$this->api_admin->formbuilder_get_orders_count([]);
$this->fail('An expected exception has not been raised.');
} catch (Box_Exception) {
}
try {
$test = $this->api_admin->formbuilder_update_form_settings([
'form_id' => 1,
'form_name' => 'Second',
'type' => 'non_existing type',
'show_title' => 'Second',
]);
$this->fail('An expected exception has not been raised.');
} catch (Box_Exception) {
}
try {
$this->api_admin->formbuilder_copy_form([
'form_id' => 2,
]);
$this->fail('An expected exception has not been raised.');
} catch (Box_Exception) {
}
try {
$this->api_admin->formbuilder_copy_form([
'form_id' => 'non-existing-form',
'name' => '',
]);
} catch (Box_Exception) {
}
try {
$this->api_admin->formbuilder_update_form_name(['form_id' => 2]);
$this->fail('An expected exception has not been raised.');
} catch (Box_Exception) {
}
}
public function testFormCreate(): void
{
$id = $this->api_admin->formbuilder_create_form([
'name' => 'New form',
]);
$this->assertIsInt($id);
$id2 = $this->api_admin->formbuilder_create_form([
'type' => null,
'name' => 'Form',
'fields' => [
'form_id' => $id,
'type' => 'checkbox',
]]);
$this->assertIsInt($id2);
}
public function testFieldAdd(): void
{
$fieldId = $this->api_admin->formbuilder_add_field(['form_id' => 1, 'type' => 'text']);
$this->assertIsInt($fieldId);
$test = $this->api_admin->formbuilder_add_field([
'description' => 'Form field description',
'label' => 'Field label',
'form_id' => 2,
'hide_label' => 0,
'name' => 'Field name',
'type' => 'checkbox',
'default_value' => 'Default value',
'required' => 0,
'hidden' => 1,
'readonly' => 0,
'options' => ['0' => 'First json on create', '2' => 'Second json on create'],
'show_initial' => 'initial',
'show_middle' => 'middle',
'show_prefix' => 'prefix',
'show_suffix' => 'suffix',
'text_size' => 499,
]);
$this->assertIsInt($test);
$this->api_admin->formbuilder_get_form([
'id' => 1,
'form_id' => 1,
'type' => 'text',
'options' => [
'1' => '1',
],
]);
}
public function testFormGet(): void
{
$array = $this->api_admin->formbuilder_get_form(['id' => 1]);
$this->assertIsArray($array);
$this->assertTrue(isset($array['fields']));
$this->assertNotEmpty($array['fields']);
}
public function testGetForm(): void
{
$form = $this->api_admin->formbuilder_get_form(['id' => 1]);
$this->assertIsArray($form);
$this->assertNotEmpty($form);
}
public function testGetFormFields(): void
{
$test = $this->api_admin->formbuilder_get_form_fields(['form_id' => 1]);
$this->assertIsArray($test);
$this->assertNotEmpty($test);
}
public function testGetField(): void
{
$test = $this->api_admin->formbuilder_get_field(['id' => 1]);
$this->assertIsArray($test);
$this->assertNotEmpty($test);
}
public function testGetForms(): void
{
$arr = $this->api_admin->formbuilder_get_forms();
$test = $arr[0];
$this->assertIsArray($test);
$this->assertArrayHasKey('product_count', $test);
$this->assertArrayHasKey('order_count', $test);
$this->assertArrayHasKey('name', $test);
$this->assertArrayHasKey('id', $test);
}
public function testDeleteForm(): void
{
$forms_before = count($this->api_admin->formbuilder_get_forms());
$test = $this->api_admin->formbuilder_delete_form(['id' => 1]);
$forms_after = count($this->api_admin->formbuilder_get_forms());
$this->assertEquals($forms_before, $forms_after + 1);
$this->assertTrue($test);
}
public function testDeleteField(): void
{
$fields_before = count($this->api_admin->formbuilder_get_form_fields(['form_id' => 1]));
$test = $this->api_admin->formbuilder_delete_field(['id' => 1]);
$fields_after = count($this->api_admin->formbuilder_get_form_fields(['form_id' => 1]));
$this->assertEquals($fields_before, $fields_after + 1);
$this->assertTrue($test);
}
public function testUpdateField(): void
{
$test = $this->api_admin->formbuilder_update_field(['id' => 3, 'description' => 'This is very awesome description.', 'name' => 'Form name']);
$this->assertIsInt($test);
$test = $this->api_admin->formbuilder_add_field([
'description' => 'Form field description',
'label' => 'Form field label',
'id' => 2,
'form_id' => 2,
'hide_label' => 0,
'name' => 'Form field name',
'type' => 'checkbox',
'default_value' => 'default',
'required' => 0,
'hidden' => 1,
'readonly' => 0,
'options' => ['Key' => '2', '2' => '3'],
'show_initial' => 'initial',
'show_middle' => 'middle',
'show_prefix' => 'prefix',
'show_suffix' => 'suffix',
'text_size' => 499,
]);
$test = $this->api_admin->formbuilder_update_field([
'id' => 5,
'form_id' => 1,
'description' => 'This is field description',
'hide_label' => 1,
'name' => 'Form field name',
'type' => 'text',
'default_value' => 'default',
'required' => 1,
'hidden' => 0,
'readonly' => 1,
'options' => ['1' => 'First value', '2' => 'second one'],
'show_initial' => 'aaaaaaa',
'show_middle' => 'bbbbbbbbb',
'show_prefix' => 'ccccccccc',
'show_suffix' => 'ddddd',
'text_size' => 500,
]);
$this->assertIsInt($test);
}
public function testUpdateFormName(): void
{
$test = $this->api_admin->formbuilder_update_form_settings([
'form_id' => 1,
'form_name' => 'Second',
'type' => 'horizontal',
'show_title' => '0',
]);
$this->assertIsBool($test);
$this->assertTrue($test);
}
public function testCopyForm(): void
{
$test = $this->api_admin->formbuilder_add_field([
'description' => 'This is awesome description. on create',
'label' => 'Cre',
'form_id' => 2,
'hide_label' => 0,
'name' => 'formnameon create',
'type' => 'checkbox',
'default_value' => 'i am defaulton create',
'required' => 0,
'hidden' => 1,
'readonly' => 0,
'options' => ['0' => 'First oneon create', '2' => 'second jsonon create'],
'show_initial' => 'a',
'show_middle' => 'middle',
'show_prefix' => 'prefix',
'show_suffix' => 'suffix',
'text_size' => 499,
]);
$test = $this->api_admin->formbuilder_copy_form([
'form_id' => 1,
'name' => 'Second',
]);
$this->assertIsInt($test);
}
public function testGetPairs(): void
{
$test = $this->api_admin->formbuilder_get_pairs();
$this->assertIsArray($test);
}
}
@@ -1,35 +0,0 @@
<?php
class Api_GUest_FormbuilderTest extends BBDbApiTestCase
{
protected $_initialSeedFile = 'mod_formbuilder.xml';
/**
* Box_Exception.
*/
public function testFormGetNonExisting(): void
{
try {
$this->api_guest->formbuilder_get(['id' => 'non-existing']);
$this->fail('An expected exception has not been raised.');
} catch (Box_Exception) {
}
try {
$this->api_guest->formbuilder_get(['id' => 100000]);
$this->fail('An expected exception has not been raised.');
} catch (Box_Exception) {
}
}
public function testGet(): void
{
$test = $this->api_guest->formbuilder_get(['id' => 2]);
$this->assertIsArray($test);
$this->assertNotEmpty($test);
$test = $this->api_guest->formbuilder_get(['id' => '2']);
$this->assertIsArray($test);
$this->assertNotEmpty($test);
}
}
@@ -1,33 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class Box_Mod_Hook_Api_AdminTest extends BBDbApiTestCase
{
protected $_initialSeedFile = 'mod_hook.xml';
public function testHook(): void
{
$this->assertTrue($this->api_admin->hook_batch_connect());
$this->assertFalse($this->api_admin->hook_call());
$bool = $this->api_admin->hook_call(['event' => 'onAfterAdminActivateExtension']);
$bool = $this->api_admin->hook_call(['event' => 'onAfterAdminActivateExtension', 'params' => ['id' => '2']]);
$this->assertTrue($bool);
}
public function testEventReturnData(): void
{
$this->api_admin->hook_batch_connect();
$data = $this->api_admin->hook_call(['event' => 'onBeforeGuestPublicTicketOpen', 'params' => ['message' => 'msg']]);
$this->assertTrue(true);
}
public function testHookGetList(): void
{
$list = $this->api_admin->hook_get_list();
$this->assertIsArray($list);
$this->assertArrayHasKey('list', $list);
$this->assertEquals(count($list['list']), $list['total']);
}
}
@@ -1,901 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class Api_Admin_InvoiceTest extends BBDbApiTestCase
{
protected $_initialSeedFile = 'transactions.xml';
public function testTax(): void
{
$array = $this->api_admin->invoice_tax_get_list();
$this->assertIsArray($array);
$data = [
'name' => 'VAT in United Kingdom',
'taxrate' => 20,
];
$id = $this->api_admin->invoice_tax_create($data);
$this->assertTrue(is_numeric($id));
$data = [
'id' => $id,
];
$bool = $this->api_admin->invoice_tax_delete($data);
$this->assertTrue($bool);
$data = [
'name' => 'VAT in United Kingdom',
'taxrate' => 20,
];
$bool = $this->api_admin->invoice_tax_setup_eu($data);
$this->assertTrue($bool);
}
public function testSubscriptions(): void
{
$array = $this->api_admin->invoice_subscription_get_list();
$this->assertIsArray($array);
$data = [
'id' => 1,
];
$array = $this->api_admin->invoice_subscription_get($data);
$this->assertIsArray($array);
$data['status'] = 'canceled';
$bool = $this->api_admin->invoice_subscription_update($data);
$this->assertTrue($bool);
$bool = $this->api_admin->invoice_subscription_delete($data);
$this->assertTrue($bool);
$sid = 'TRWEW_@22--2222';
$data['sid'] = $sid;
$data['client_id'] = 1;
$data['gateway_id'] = 1;
$data['status'] = 'canceled';
$data['currency'] = 'USD';
$id = $this->api_admin->invoice_subscription_create($data);
$this->assertTrue(is_numeric($id));
$array = $this->api_admin->invoice_subscription_get(['sid' => $sid]);
$this->assertIsArray($array);
}
public function testInvoice(): void
{
$bool = $this->api_admin->invoice_batch_generate();
$this->assertTrue($bool);
$bool = $this->api_admin->invoice_batch_activate_paid();
$this->assertTrue($bool);
$bool = $this->api_admin->invoice_batch_pay_with_credits();
$this->assertTrue($bool);
$bool = $this->api_admin->invoice_batch_pay_with_credits(['client_id' => 1]);
$this->assertTrue($bool);
$array = $this->api_admin->invoice_get_statuses([]);
$this->assertIsArray($array);
$array = $this->api_admin->invoice_get_list();
$this->assertIsArray($array);
$data = [
'id' => 1,
];
$array = $this->api_admin->invoice_get($data);
$this->assertIsArray($array);
$data = [
'client_id' => 1,
'gateway_id' => 1,
];
$id = $this->api_admin->invoice_prepare($data);
$this->assertTrue(is_numeric($id));
$data['id'] = $id;
$data['serie'] = 'new';
$bool = $this->api_admin->invoice_update($data);
$this->assertTrue($bool);
$data = [
'id' => $id,
];
$bool = $this->api_admin->invoice_approve($data);
$this->assertTrue($bool);
$bool = $this->api_admin->invoice_delete($data);
$this->assertTrue($bool);
}
public function testItem(): void
{
$data = [
'client_id' => 1,
];
$id = $this->api_admin->invoice_prepare($data);
$this->assertTrue(is_numeric($id));
$data['id'] = $id;
$data['serie'] = 'new';
$data['new_item'] = [
'title' => 'new item',
'price' => 'new item',
'taxed' => true,
'period' => '1W',
];
$bool = $this->api_admin->invoice_update($data);
$this->assertTrue($bool);
$array = $this->api_admin->invoice_get($data);
$this->assertEquals(1, count($array['lines']));
$line_data['id'] = $array['lines'][0]['id'];
$bool = $this->api_admin->invoice_item_delete($line_data);
}
public function testGatewayInstall(): void
{
$array = $this->api_admin->invoice_gateway_get_available();
$this->assertIsArray($array);
$data = [
'code' => $array[0],
];
$bool = $this->api_admin->invoice_gateway_install($data);
$this->assertTrue($bool);
}
public function testGateways(): void
{
$array = $this->api_admin->invoice_gateway_get_list();
$this->assertIsArray($array);
$array = $this->api_admin->invoice_gateway_get_pairs();
$this->assertIsArray($array);
$data = [
'id' => 1,
];
$array = $this->api_admin->invoice_gateway_get($data);
$this->assertIsArray($array);
$data = [
'id' => 1,
'allow_single' => 1,
'allow_recurrent' => 1,
'enabled' => 1,
'title' => 'title',
];
$bool = $this->api_admin->invoice_gateway_update($data);
$this->assertTrue($bool);
$id = $this->api_admin->invoice_gateway_copy($data);
$this->assertTrue(is_numeric($id));
$data = [
'id' => $id,
];
$bool = $this->api_admin->invoice_gateway_delete($data);
$this->assertTrue($bool);
}
public function testTransactionsSearch(): void
{
$txn_id = '11--aaa--p';
$tx = [
'skip_validation' => true,
'txn_id' => $txn_id,
];
$tx_id = $this->api_admin->invoice_transaction_create($tx);
$list = $this->api_admin->invoice_transaction_get_list(['txn_id' => $txn_id]);
$this->assertEquals(1, count($list['list']));
}
public function testTransactions(): void
{
$tx = [
'invoice_id' => 1,
'gateway_id' => 1,
];
$tx_id = $this->api_admin->invoice_transaction_create($tx);
$txu = [
'id' => $tx_id,
'validate_ipn' => '0',
'amount' => 150,
'type' => Payment_Transaction::TXTYPE_PAYMENT,
'note' => 'notes',
'gateway_id' => 1,
'currency' => 'USD',
'status' => Model_Transaction::STATUS_APPROVED,
'txn_id' => uniqid(),
'txn_status' => 'complete',
];
$bool = $this->api_admin->invoice_transaction_update($txu);
$this->assertTrue($bool);
$array = $this->api_admin->invoice_transaction_get($txu);
$this->assertIsArray($array);
$bool = $this->api_admin->invoice_transaction_process($txu);
$this->assertTrue($bool);
$bool = $this->api_admin->invoice_transaction_delete($txu);
$this->assertTrue($bool);
$array = $this->api_admin->invoice_transaction_get_list();
$this->assertIsArray($array);
$array = $this->api_admin->invoice_transaction_statuses();
$this->assertIsArray($array);
$array = $this->api_admin->invoice_transaction_gateway_statuses();
$this->assertIsArray($array);
$array = $this->api_admin->invoice_transaction_types();
$this->assertIsArray($array);
$array = $this->api_admin->invoice_transaction_get_statuses();
$this->assertIsArray($array);
$array = $this->api_admin->invoice_transaction_get_statuses_pairs();
$this->assertIsArray($array);
}
public function testUpdate(): void
{
$data = [
'id' => 1,
'status' => 'unpaid',
'notes' => 'note',
'serie' => 'NEW',
'nr' => 4,
'due_at' => date('Y-m-d H:i:s'),
];
$bool = $this->api_admin->invoice_update($data);
$this->assertTrue($bool);
}
public function testManualPayment(): void
{
$data = [
'id' => 1,
];
$bool = $this->api_admin->invoice_mark_as_paid($data);
$this->assertTrue($bool);
}
public function testInvoiceDueDate(): void
{
// invoice due date for order must be the same as order expiration
// date if order has expiation date
$oid = 5;
$o = $this->api_admin->order_get(['id' => $oid]);
$this->assertEquals('2012-10-10 00:00:00', $o['expires_at']);
$id = $this->api_admin->invoice_renewal_invoice(['id' => $oid]);
$invoice = $this->api_admin->invoice_get(['id' => $id]);
$this->assertEquals('2012-10-10 00:00:00', $invoice['due_at']);
// test event caller
$this->api_admin->invoice_batch_invoke_due_event();
}
public function testRenewalInvoice(): void
{
$oid = 4;
$this->api_admin->order_renew(['id' => $oid]);
$o1 = $this->api_admin->order_get(['id' => $oid]);
$this->assertEquals('active', $o1['status']);
$id = $this->api_admin->invoice_renewal_invoice(['id' => $oid]);
$invoice = $this->api_admin->invoice_get(['id' => $id]);
$this->api_admin->invoice_mark_as_paid($invoice);
$o2 = $this->api_admin->order_get(['id' => $oid]);
$this->assertEquals('active', $o2['status']);
$this->api_admin->invoice_batch_activate_paid();
$o3 = $this->api_admin->order_get(['id' => $oid]);
$this->assertEquals('active', $o3['status']);
$this->assertNotEquals($o2['expires_at'], $o3['expires_at']);
}
public function testReminders(): void
{
$bool = $this->api_admin->invoice_batch_send_reminders();
$this->assertTrue($bool);
$bool = $this->api_admin->invoice_batch_send_reminders();
$this->assertTrue($bool);
}
public function testSendReminder(): void
{
$data = ['id' => 1];
$bool = $this->api_admin->invoice_send_reminder($data);
$this->assertTrue($bool);
}
public function testProcess(): void
{
try {
$bool = $this->api_admin->invoice_transaction_process_all();
$this->assertTrue($bool);
} catch (Exception $e) {
assertEquals('testProcess failed: ', $e->getMessage());
}
$bool = $this->api_admin->invoice_batch_activate_paid();
$this->assertTrue($bool);
}
public function testNumbering(): void
{
$data = [
'invoice_series' => 'UNIT',
'invoice_series_paid' => 'PAID',
'invoice_starting_number' => 150,
];
$this->api_admin->system_update_params($data);
$data = [
'client_id' => 1,
];
$id = $this->api_admin->invoice_prepare($data);
$this->assertTrue(is_numeric($id));
$data = [
'id' => $id,
];
$this->api_admin->invoice_mark_as_paid($data);
$array = $this->api_admin->invoice_get($data);
$this->assertEquals('150', $array['nr']);
$data = [
'client_id' => 1,
];
$id = $this->api_admin->invoice_prepare($data);
$data = [
'id' => $id,
];
$this->api_admin->invoice_mark_as_paid($data);
$array = $this->api_admin->invoice_get($data);
$this->assertEquals('151', $array['nr']);
$next = $this->api_admin->system_param(['key' => 'invoice_starting_number']);
$this->assertEquals('152', $next);
}
public function testRefund(): void
{
$id = 3;
$data = [
'id' => $id,
'note' => 'For some reason',
];
$bool = $this->api_admin->system_update_params(['invoice_refund_logic' => 'manual']);
$null = $this->api_admin->invoice_refund($data);
$this->assertNull($null);
$bool = $this->api_admin->system_update_params(['invoice_refund_logic' => 'negative_invoice']);
$refunded_invoice_id = $this->api_admin->invoice_refund($data);
$this->assertIsInt($refunded_invoice_id);
$bool = $this->api_admin->system_update_params(['invoice_refund_logic' => 'credit_note']);
$refunded_invoice_id = $this->api_admin->invoice_refund($data);
$this->assertIsInt($refunded_invoice_id);
try {
$this->api_admin->invoice_refund(['id' => $refunded_invoice_id]);
$this->fail('Should not refund refunded invoice');
} catch (Exception) {
}
}
public function testItemTax(): void
{
$data = [
'tax_enabled' => 1,
];
$this->api_admin->system_update_params($data);
$data = [
'client_id' => 1,
];
$id = $this->api_admin->invoice_prepare($data);
$data['id'] = $id;
$data['new_item']['title'] = 'test';
$data['new_item']['price'] = 40;
$data['new_item']['taxed'] = 1;
$this->api_admin->invoice_update($data);
$array = $this->api_admin->invoice_get($data);
$this->assertEquals(25, $array['taxrate']);
}
/**
* Invoice should be marked as paid after adding money to balance.
*/
public function testCoverInvoice(): void
{
$id = 2;
$data = [
'id' => 1,
'amount' => 100,
'description' => 'For invoice payment',
];
$this->api_admin->client_balance_add_funds($data);
$this->api_admin->invoice_pay_with_credits(['id' => $id]);
$array = $this->api_admin->invoice_get(['id' => $id]);
$this->assertEquals('paid', $array['status']);
}
/**
* Deposit invoice should be marked as paid and do not charge for it.
*/
public function testDepositInvoice(): void
{
$id = 5;
$invoiceModel = $this->di['db']->load('Invoice', 5);
$this->assertEquals(Model_Invoice::STATUS_UNPAID, $invoiceModel->status);
$invoiceItemModel = $this->di['db']->findOne('InvoiceItem', 'invoice_id = ?', [$invoiceModel->id]);
$this->assertEquals(Model_InvoiceItem::TYPE_DEPOSIT, $invoiceItemModel->type);
$balanceBefore = $this->api_client->client_balance_get_total();
$this->api_admin->invoice_pay_with_credits(['id' => $id]);
$balanceAfter = $this->api_client->client_balance_get_total();
$array = $this->api_admin->invoice_get(['id' => $id]);
$this->assertEquals(Model_Invoice::STATUS_PAID, $array['status']);
$this->assertEquals($balanceBefore, $balanceAfter);
}
/**
* After admin marks as paid deposit invoice account balance should increase.
*/
public function testDepositInvoiceMarkAsPaid(): void
{
$id = 5;
$invoiceModel = $this->di['db']->load('Invoice', 5);
$this->assertEquals(Model_Invoice::STATUS_UNPAID, $invoiceModel->status);
$invoiceItemModel = $this->di['db']->findOne('InvoiceItem', 'invoice_id = ?', [$invoiceModel->id]);
$this->assertEquals(Model_InvoiceItem::TYPE_DEPOSIT, $invoiceItemModel->type);
$balanceBefore = $this->api_client->client_balance_get_total();
$this->api_admin->invoice_mark_as_paid(['id' => $id, 'execute' => 1]);
$balanceAfter = $this->api_client->client_balance_get_total();
$array = $this->api_admin->invoice_get(['id' => $id]);
$this->assertEquals(Model_Invoice::STATUS_PAID, $array['status']);
$this->assertEquals($balanceAfter, $balanceBefore + $invoiceItemModel->price);
$accountBalance = $this->di['db']->findOne('ClientBalance', 'order by id desc');
$this->assertEquals($invoiceItemModel->title, $accountBalance->description);
$this->assertEquals($invoiceItemModel->price, $accountBalance->amount);
}
/**
* Invoice should be marked as paid after adding money to balance.
*/
public function testCredits(): void
{
$id = 2;
$this->api_admin->invoice_batch_pay_with_credits();
$array = $this->api_admin->invoice_get(['id' => $id]);
$this->assertEquals('unpaid', $array['status']);
$this->assertEmpty($array['credit']);
$this->api_admin->invoice_batch_pay_with_credits();
$array = $this->api_admin->invoice_get(['id' => $id]);
$this->assertEquals('unpaid', $array['status']);
$data = [
'id' => 1,
'amount' => 100,
'description' => 'For invoice payment',
];
$this->api_admin->client_balance_add_funds($data);
$this->api_admin->invoice_batch_pay_with_credits();
$array = $this->api_admin->invoice_get(['id' => $id]);
$this->assertEquals('paid', $array['status']);
}
public function testPrepareWithoutItems(): void
{
$data = [
'client_id' => 1,
];
$id = $this->api_admin->invoice_prepare($data);
$array = $this->api_admin->invoice_get(['id' => $id]);
$this->assertEquals(0, count($array['lines']));
}
public function testPrepareWithItems(): void
{
$data = [
'client_id' => 1,
'items' => [
[
'title' => 'first line test title',
'period' => '1M',
'quantity' => 3,
'price' => 4.65,
],
[
'title' => 'second line test title',
'period' => '2M',
],
],
];
$id = $this->api_admin->invoice_prepare($data);
$array = $this->api_admin->invoice_get(['id' => $id]);
$this->assertEquals(2, count($array['lines']));
$line0 = $array['lines'][0];
$this->assertEquals('first line test title', $line0['title']);
$this->assertEquals('1M', $line0['period']);
$this->assertEquals(3, $line0['quantity']);
$this->assertEquals(4.65, $line0['price']);
$line1 = $array['lines'][1];
$this->assertEquals('second line test title', $line1['title']);
$this->assertEquals('2M', $line1['period']);
$this->assertEquals(1, $line1['quantity']);
$this->assertEquals(0.00, $line1['price']);
}
public function testTaskHook(): void
{
$params = json_encode(['param' => 'value']);
$event = 'onAfterClientCalledExampleModule';
$idata = [
'client_id' => 1,
'items' => [
[
'title' => 'Test custom item activation',
'price' => 12.22,
'type' => 'hook_call',
'task' => $event,
'rel_id' => $params,
],
],
];
$invoice_id = $this->api_admin->invoice_prepare($idata);
$this->api_admin->invoice_approve(['id' => $invoice_id]);
$invoice = $this->api_admin->invoice_get(['id' => $invoice_id]);
$line0 = $invoice['lines'][0];
$this->assertEquals('hook_call', $line0['type']);
$this->assertEquals($event, $line0['task']);
$this->assertEquals($params, $line0['rel_id']);
// custom hook executes on payment event
// event hook inseerts data to database to test
$this->api_admin->extension_activate(['type' => 'mod', 'id' => 'example']);
$invoice = $this->api_admin->invoice_mark_as_paid(['id' => $invoice_id, 'execute' => true]);
// @todo
// $b = R::findOne('extension_meta', "extension = 'mod_example' AND meta_key = 'event_params'");
// $this->assertEquals($params, $b->meta_value);
}
public function testInvoiceGetList(): void
{
$array = $this->api_admin->invoice_get_list();
$this->assertIsArray($array);
$this->assertArrayHasKey('list', $array);
$list = $array['list'];
$this->assertIsArray($list);
if (count($list)) {
$item = $list[1];
$this->assertArrayHasKey('id', $item);
$this->assertArrayHasKey('serie', $item);
$this->assertArrayHasKey('nr', $item);
$this->assertArrayHasKey('serie_nr', $item);
$this->assertArrayHasKey('hash', $item);
$this->assertArrayHasKey('gateway_id', $item);
$this->assertArrayHasKey('taxname', $item);
$this->assertArrayHasKey('taxrate', $item);
$this->assertArrayHasKey('currency', $item);
$this->assertArrayHasKey('currency_rate', $item);
$this->assertArrayHasKey('tax', $item);
$this->assertArrayHasKey('subtotal', $item);
$this->assertArrayHasKey('total', $item);
$this->assertArrayHasKey('status', $item);
$this->assertArrayHasKey('notes', $item);
$this->assertArrayHasKey('text_1', $item);
$this->assertArrayHasKey('text_2', $item);
$this->assertArrayHasKey('due_at', $item);
$this->assertArrayHasKey('paid_at', $item);
$this->assertArrayHasKey('created_at', $item);
$this->assertArrayHasKey('updated_at', $item);
$this->assertArrayHasKey('lines', $item);
$this->assertIsArray($item['lines']);
$line = $item['lines'][0];
$this->assertIsArray($line);
$this->assertArrayHasKey('id', $line);
$this->assertArrayHasKey('title', $line);
$this->assertArrayHasKey('period', $line);
$this->assertArrayHasKey('quantity', $line);
$this->assertArrayHasKey('unit', $line);
$this->assertArrayHasKey('price', $line);
$this->assertArrayHasKey('tax', $line);
$this->assertArrayHasKey('taxed', $line);
$this->assertArrayHasKey('charged', $line);
$this->assertArrayHasKey('total', $line);
$this->assertArrayHasKey('order_id', $line);
$this->assertArrayHasKey('type', $line);
$this->assertArrayHasKey('rel_id', $line);
$this->assertArrayHasKey('task', $line);
$this->assertArrayHasKey('status', $line);
$this->assertArrayHasKey('lines', $item);
$this->assertIsArray($item['buyer']);
$buyer = $item['buyer'];
$this->assertArrayHasKey('first_name', $buyer);
$this->assertArrayHasKey('last_name', $buyer);
$this->assertArrayHasKey('company', $buyer);
$this->assertArrayHasKey('company_vat', $buyer);
$this->assertArrayHasKey('company_number', $buyer);
$this->assertArrayHasKey('address', $buyer);
$this->assertArrayHasKey('city', $buyer);
$this->assertArrayHasKey('state', $buyer);
$this->assertArrayHasKey('country', $buyer);
$this->assertArrayHasKey('phone', $buyer);
$this->assertArrayHasKey('phone_cc', $buyer);
$this->assertArrayHasKey('email', $buyer);
$this->assertArrayHasKey('zip', $buyer);
$this->assertIsArray($item['seller']);
$seller = $item['seller'];
$this->assertArrayHasKey('company', $seller);
$this->assertArrayHasKey('company_vat', $seller);
$this->assertArrayHasKey('company_number', $seller);
$this->assertArrayHasKey('address', $seller);
$this->assertArrayHasKey('phone', $seller);
$this->assertArrayHasKey('email', $seller);
$this->assertArrayHasKey('subscribable', $item);
$this->assertArrayHasKey('subscription', $item);
$this->assertIsArray($item['subscription']);
$subscription = $item['subscription'];
$this->assertArrayHasKey('unit', $subscription);
$this->assertArrayHasKey('cycle', $subscription);
$this->assertArrayHasKey('period', $subscription);
}
}
public function testTransactionGetList(): void
{
$array = $this->api_admin->invoice_transaction_get_list();
$this->assertIsArray($array);
$this->assertArrayHasKey('list', $array);
$list = $array['list'];
$this->assertIsArray($list);
if (count($list)) {
$item = $list[0];
$this->arrayHasKey('id');
$this->arrayHasKey('invoice_id');
$this->arrayHasKey('txn_id');
$this->arrayHasKey('txn_status');
$this->arrayHasKey('gateway_id');
$this->arrayHasKey('gateway');
$this->arrayHasKey('amount');
$this->arrayHasKey('currency');
$this->arrayHasKey('type');
$this->arrayHasKey('status');
$this->arrayHasKey('ip');
$this->arrayHasKey('validate_ipn');
$this->arrayHasKey('error');
$this->arrayHasKey('error_code');
$this->arrayHasKey('note');
$this->arrayHasKey('created_at');
$this->arrayHasKey('updated_at');
}
}
public function testGatewayGetList(): void
{
$array = $this->api_admin->invoice_gateway_get_list();
$this->assertIsArray($array);
$this->assertArrayHasKey('list', $array);
$list = $array['list'];
$this->assertIsArray($list);
if (count($list)) {
$item = $list[0];
$this->assertArrayHasKey('id', $item);
$this->assertArrayHasKey('code', $item);
$this->assertArrayHasKey('title', $item);
$this->assertArrayHasKey('allow_single', $item);
$this->assertArrayHasKey('allow_recurrent', $item);
$this->assertArrayHasKey('accepted_currencies', $item);
$this->assertIsArray($item['accepted_currencies']);
}
}
public function testSubscriptionGetList(): void
{
$array = $this->api_admin->invoice_subscription_get_list();
$this->assertIsArray($array);
$this->assertArrayHasKey('list', $array);
$list = $array['list'];
$this->assertIsArray($list);
if (count($list)) {
$item = $list[0];
$this->assertArrayHasKey('id', $item);
$this->assertArrayHasKey('sid', $item);
$this->assertArrayHasKey('period', $item);
$this->assertArrayHasKey('amount', $item);
$this->assertArrayHasKey('currency', $item);
$this->assertArrayHasKey('status', $item);
$this->assertArrayHasKey('created_at', $item);
$this->assertArrayHasKey('updated_at', $item);
$this->assertArrayHasKey('client', $item);
$client = $item['client'];
$this->assertIsArray($client);
$this->assertArrayHasKey('id', $client);
$this->assertArrayHasKey('aid', $client);
$this->assertArrayHasKey('email', $client);
$this->assertArrayHasKey('type', $client);
$this->assertArrayHasKey('group_id', $client);
$this->assertArrayHasKey('company', $client);
$this->assertArrayHasKey('company_vat', $client);
$this->assertArrayHasKey('company_number', $client);
$this->assertArrayHasKey('first_name', $client);
$this->assertArrayHasKey('last_name', $client);
$this->assertArrayHasKey('gender', $client);
$this->assertArrayHasKey('birthday', $client);
$this->assertArrayHasKey('phone_cc', $client);
$this->assertArrayHasKey('phone', $client);
$this->assertArrayHasKey('address_1', $client);
$this->assertArrayHasKey('address_2', $client);
$this->assertArrayHasKey('city', $client);
$this->assertArrayHasKey('state', $client);
$this->assertArrayHasKey('postcode', $client);
$this->assertArrayHasKey('country', $client);
$this->assertArrayHasKey('currency', $client);
$this->assertArrayHasKey('notes', $client);
$this->assertArrayHasKey('created_at', $client);
$this->assertArrayHasKey('gateway', $item);
$gateway = $item['gateway'];
$this->assertIsArray($gateway);
$this->assertArrayHasKey('id', $gateway);
$this->assertArrayHasKey('code', $gateway);
$this->assertArrayHasKey('title', $gateway);
$this->assertArrayHasKey('allow_single', $gateway);
$this->assertArrayHasKey('allow_recurrent', $gateway);
$this->assertArrayHasKey('accepted_currencies', $gateway);
$this->assertIsArray($gateway['accepted_currencies']);
}
}
public function testInvoiceBatchDelete(): void
{
$array = $this->api_admin->invoice_get_list([]);
foreach ($array['list'] as $value) {
$ids[] = $value['id'];
}
$result = $this->api_admin->invoice_batch_delete(['ids' => $ids]);
$array = $this->api_admin->invoice_get_list([]);
$this->assertEquals(0, count($array['list']));
$this->assertTrue($result);
}
public function testInvoiceBatchDeleteSubscription(): void
{
$array = $this->api_admin->invoice_subscription_get_list([]);
foreach ($array['list'] as $value) {
$ids[] = $value['id'];
}
$result = $this->api_admin->invoice_batch_delete_subscription(['ids' => $ids]);
$array = $this->api_admin->invoice_subscription_get_list([]);
$this->assertEquals(0, count($array['list']));
$this->assertTrue($result);
}
public function testInvoiceBatchDeleteTransaction(): void
{
$array = $this->api_admin->invoice_transaction_get_list([]);
foreach ($array['list'] as $value) {
$ids[] = $value['id'];
}
$result = $this->api_admin->invoice_batch_delete_transaction(['ids' => $ids]);
$array = $this->api_admin->invoice_transaction_get_list([]);
$this->assertEquals(0, count($array['list']));
$this->assertTrue($result);
}
public function testInvoiceBatchDeleteTax(): void
{
$array = $this->api_admin->invoice_tax_get_list([]);
foreach ($array['list'] as $value) {
$ids[] = $value['id'];
}
$result = $this->api_admin->invoice_batch_delete_tax(['ids' => $ids]);
$array = $this->api_admin->invoice_tax_get_list([]);
$this->assertEquals(0, count($array['list']));
$this->assertTrue($result);
}
public function testPrepareInvoiceDueDateProvider()
{
$this->assertTrue(true);
return [
[100, 100],
['', 1],
[null, 1],
];
}
#[PHPUnit\Framework\Attributes\DataProvider('testPrepareInvoiceDueDateProvider')]
public function testPrepareInvoiceDueDate($invoice_due_days, $diff): void
{
if (!is_null($invoice_due_days)) {
$this->api_admin->system_update_params(['invoice_due_days' => $invoice_due_days]);
}
$data = [
'client_id' => 1,
];
$id = $this->api_admin->invoice_prepare($data);
$array = $this->api_admin->invoice_get(['id' => $id]);
$this->assertEquals(substr($array['due_at'], 0, 10), date('Y-m-d', strtotime("+ $diff day")));
}
public function testUpdateTaxRule(): void
{
$id = 2;
$data = [
'id' => $id,
'name' => 'Updated Tax rule',
'taxrate' => 99,
'country' => 'NL',
];
$this->api_admin->invoice_tax_update($data);
$tax = $this->api_admin->invoice_tax_get(['id' => $id]);
$this->assertIsArray($tax);
$this->assertEquals($data['name'], $tax['name']);
$this->assertEquals($data['taxrate'], $tax['taxrate']);
$this->assertEquals($data['country'], $tax['country']);
}
}
@@ -1,181 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class Api_Client_InvoiceTest extends BBDbApiTestCase
{
protected $_initialSeedFile = 'transactions.xml';
public function testProformaInvoices(): void
{
// prepare expiring order
$data = [
'id' => 5,
'expires_at' => date('Y-m-d H:i:s', strtotime('+1 day')),
];
$bool = $this->api_admin->order_update($data);
$this->assertTrue($bool);
$bool = $this->api_admin->invoice_batch_generate();
$this->assertTrue($bool);
$array = $this->api_client->invoice_get_list();
$this->assertIsArray($array);
$data = [
'hash' => $array['list'][0]['hash'],
];
$array = $this->api_client->invoice_get($data);
$this->assertIsArray($array);
}
public function testRenewal(): void
{
$data = [
'order_id' => 3,
];
$hash = $this->api_client->invoice_renewal_invoice($data);
$this->assertIsString($hash);
}
public function testFunds(): void
{
$data = [
'amount' => 30,
];
$hash = $this->api_client->invoice_funds_invoice($data);
$this->assertIsString($hash);
}
public function testDelete(): void
{
$invoices = $this->di['db']->find('Invoice', '1');
$pf = $invoices[1];
$hash = $pf->hash;
$data = [
'hash' => $hash,
];
$bool = $this->api_client->invoice_delete($data);
$this->assertTrue($bool);
}
public function testTransactions(): void
{
$array = $this->api_client->invoice_transaction_get_list();
$this->assertIsArray($array);
}
public function testInvoiceGetList(): void
{
$array = $this->api_client->invoice_get_list();
$this->assertIsArray($array);
$this->assertArrayHasKey('list', $array);
$list = $array['list'];
$this->assertIsArray($list);
if (count($list)) {
$item = $list[1];
$this->assertArrayHasKey('id', $item);
$this->assertArrayHasKey('serie', $item);
$this->assertArrayHasKey('nr', $item);
$this->assertArrayHasKey('serie_nr', $item);
$this->assertArrayHasKey('hash', $item);
$this->assertArrayHasKey('gateway_id', $item);
$this->assertArrayHasKey('taxname', $item);
$this->assertArrayHasKey('taxrate', $item);
$this->assertArrayHasKey('currency', $item);
$this->assertArrayHasKey('currency_rate', $item);
$this->assertArrayHasKey('tax', $item);
$this->assertArrayHasKey('subtotal', $item);
$this->assertArrayHasKey('total', $item);
$this->assertArrayHasKey('status', $item);
$this->assertArrayHasKey('notes', $item);
$this->assertArrayHasKey('text_1', $item);
$this->assertArrayHasKey('text_2', $item);
$this->assertArrayHasKey('due_at', $item);
$this->assertArrayHasKey('paid_at', $item);
$this->assertArrayHasKey('created_at', $item);
$this->assertArrayHasKey('updated_at', $item);
$this->assertArrayHasKey('lines', $item);
$this->assertIsArray($item['lines']);
$line = $item['lines'][0];
$this->assertIsArray($line);
$this->assertArrayHasKey('id', $line);
$this->assertArrayHasKey('title', $line);
$this->assertArrayHasKey('period', $line);
$this->assertArrayHasKey('quantity', $line);
$this->assertArrayHasKey('unit', $line);
$this->assertArrayHasKey('price', $line);
$this->assertArrayHasKey('tax', $line);
$this->assertArrayHasKey('taxed', $line);
$this->assertArrayHasKey('charged', $line);
$this->assertArrayHasKey('total', $line);
$this->assertArrayHasKey('order_id', $line);
$this->assertArrayHasKey('type', $line);
$this->assertArrayHasKey('rel_id', $line);
$this->assertArrayHasKey('task', $line);
$this->assertArrayHasKey('status', $line);
$this->assertArrayHasKey('lines', $item);
$this->assertIsArray($item['buyer']);
$buyer = $item['buyer'];
$this->assertArrayHasKey('first_name', $buyer);
$this->assertArrayHasKey('last_name', $buyer);
$this->assertArrayHasKey('company', $buyer);
$this->assertArrayHasKey('company_vat', $buyer);
$this->assertArrayHasKey('company_number', $buyer);
$this->assertArrayHasKey('address', $buyer);
$this->assertArrayHasKey('city', $buyer);
$this->assertArrayHasKey('state', $buyer);
$this->assertArrayHasKey('country', $buyer);
$this->assertArrayHasKey('phone', $buyer);
$this->assertArrayHasKey('phone_cc', $buyer);
$this->assertArrayHasKey('email', $buyer);
$this->assertArrayHasKey('zip', $buyer);
$this->assertIsArray($item['seller']);
$seller = $item['seller'];
$this->assertArrayHasKey('company', $seller);
$this->assertArrayHasKey('company_vat', $seller);
$this->assertArrayHasKey('company_number', $seller);
$this->assertArrayHasKey('address', $seller);
$this->assertArrayHasKey('phone', $seller);
$this->assertArrayHasKey('email', $seller);
$this->assertArrayHasKey('subscribable', $item);
$this->assertArrayHasKey('subscription', $item);
$this->assertIsArray($item['subscription']);
$subscription = $item['subscription'];
$this->assertArrayHasKey('unit', $subscription);
$this->assertArrayHasKey('cycle', $subscription);
$this->assertArrayHasKey('period', $subscription);
}
}
public function testTransactionGetList(): void
{
$array = $this->api_client->invoice_transaction_get_list();
$this->assertIsArray($array);
$this->assertArrayHasKey('list', $array);
$list = $array['list'];
$this->assertIsArray($list);
if (count($list)) {
$item = $list[0];
$this->arrayHasKey('id');
$this->arrayHasKey('invoice_id');
$this->arrayHasKey('txn_id');
$this->arrayHasKey('txn_status');
$this->arrayHasKey('gateway_id');
$this->arrayHasKey('gateway');
$this->arrayHasKey('amount');
$this->arrayHasKey('currency');
$this->arrayHasKey('type');
$this->arrayHasKey('status');
$this->arrayHasKey('ip');
$this->arrayHasKey('validate_ipn');
$this->arrayHasKey('error');
$this->arrayHasKey('error_code');
$this->arrayHasKey('note');
$this->arrayHasKey('created_at');
$this->arrayHasKey('updated_at');
}
}
}
@@ -1,24 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class Box_Mod_Invoice_Api_ClientTest extends BBModTestCase
{
protected $_mod = 'invoice';
protected $_initialSeedFile = 'mod_invoice.xml';
public function testUpdate(): void
{
$data = [
'hash' => 'hash2',
];
$array = $this->api_client->invoice_get($data);
$this->assertIsArray($array);
$data['gateway_id'] = 1;
$bool = $this->api_client->invoice_update($data);
$this->assertTrue($bool);
$array = $this->api_client->invoice_get($data);
$this->assertEquals(1, $array['gateway_id']);
}
}
@@ -1,86 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class Api_Guest_InvoiceTest extends BBDbApiTestCase
{
protected $_initialSeedFile = 'transactions.xml';
public function testGateways(): void
{
$data = [
'hash' => 'hash',
];
$array = $this->api_guest->invoice_get($data);
$this->assertIsArray($array);
$array = $this->api_guest->invoice_gateways();
$this->assertIsArray($array);
}
public static function gateways()
{
return [
[1, 1],
[2, 2],
[2, 3],
[2, 4],
[3, 1],
];
}
#[PHPUnit\Framework\Attributes\DataProvider('gateways')]
public function testPayment($id, $iid): void
{
$pf = $this->di['db']->findOne('Invoice', $iid);
$hash = $pf->hash;
$data = [
'subscription' => false,
'hash' => $hash,
'gateway_id' => $id,
];
$array = $this->api_guest->invoice_payment($data);
$this->assertIsArray($array);
}
public function testNewPayment(): void
{
$gateway_id = 3;
$pf = $this->di['db']->findOne('Invoice', 1);
$hash = $pf->hash;
$data = [
'subscription' => false,
'hash' => $hash,
'gateway_id' => $gateway_id,
];
$form = $this->api_guest->invoice_payment($data);
$this->assertIsArray($form);
$this->assertEquals('html', $form['type']);
$this->assertFalse(empty($form['result']));
// subscription
$pf = $this->di['db']->findOne('Invoice', 2);
$hash = $pf->hash;
$data = [
'subscription' => true,
'hash' => $hash,
'gateway_id' => $gateway_id,
];
$form2 = $this->api_guest->invoice_payment($data);
$this->assertIsArray($form2);
$this->assertEquals('html', $form2['type']);
$this->assertFalse(empty($form2['result']));
}
public function testupdate(): void
{
$data = [
'hash' => 'hash',
];
$bool = $this->api_guest->invoice_update($data);
$this->assertTrue($bool);
}
}
@@ -1,124 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class Box_Mod_Invoice_ServiceTest extends BBDbApiTestCase
{
protected $_mod = 'invoice';
protected $_initialSeedFile = 'mod_invoice.xml';
public function testEvents(): void
{
$service = new Box\Mod\Invoice\Service();
$service->setDi($this->di);
$params = [
'id' => 1,
];
$event = new Box_Event(null, 'name', $params, $this->api_admin, $this->api_guest);
$event->setDi($this->di);
$bool = $service->onAfterAdminInvoicePaymentReceived($event);
$this->assertTrue($bool);
$params = [
'id' => 1,
];
$event = new Box_Event(null, 'name', $params, $this->api_admin, $this->api_guest);
$event->setDi($this->di);
$bool = $service->onAfterAdminInvoiceApprove($event);
$this->assertTrue($bool);
}
/**
* Process Paypal transaction.
*/
public function testprocessTransaction(): void
{
$service = new Box\Mod\Invoice\ServiceTransaction();
$service->setDi($this->di);
$transactionModel = $this->di['db']->load('Transaction', 10);
$this->assertInstanceOf('Model_Transaction', $transactionModel);
$gatewayModel = $this->di['db']->load('PayGateway', $transactionModel->gateway_id);
$this->assertEquals('PayPalEmail', $gatewayModel->gateway);
$service->processTransaction($transactionModel->id);
}
/**
* Process Paypal duplicate transaction.
*/
public function testcreateAndProcessTransactionDuplicate(): void
{
$service = new Box\Mod\Invoice\ServiceTransaction();
$service->setDi($this->di);
$transactionModel = $this->di['db']->load('Transaction', 10);
$this->assertInstanceOf('Model_Transaction', $transactionModel);
$gatewayModel = $this->di['db']->load('PayGateway', $transactionModel->gateway_id);
$this->assertEquals('PayPalEmail', $gatewayModel->gateway);
$service->processTransaction($transactionModel->id);
$transactionIpn = json_decode($transactionModel->ipn ?? '', true);
$ipn = [
'skip_validation' => true,
'invoice_id' => $transactionModel->invoice_id,
'gateway_id' => $transactionModel->gateway_id,
'get' => $transactionIpn['get'],
'post' => $transactionIpn['post'],
];
$this->expectException(Payment_Exception::class);
$this->expectExceptionMessage('Cannot process duplicate IPN');
$newId = $service->createAndProcess($ipn);
$transactionModel = $this->di['db']->load('Transaction', $newId);
$this->assertInstanceOf('Model_Transaction', $transactionModel);
}
public function testonAfterAdminCronRun(): void
{
$systemService = $this->di['mod_service']('System');
$remove_after_days = 1;
$systemService->setParamValue('remove_after_days', $remove_after_days);
$expected = $systemService->getParamValue('remove_after_days');
$this->assertEquals($expected, $remove_after_days);
$sql = "SELECT 1 FROM invoice WHERE status = 'unpaid' AND DATEDIFF(NOW(), due_at) > :days";
$binigns = [':days' => $remove_after_days];
$result = $this->di['db']->getAll($sql, $binigns);
$invoiceNeedsToBeDeleted = count($result);
$this->assertGreaterThan(0, $invoiceNeedsToBeDeleted);
$eventMock = $this->getMockBuilder('\Box_Event')
->disableOriginalConstructor()
->onlyMethods(['getDi'])
->getMock();
$eventMock->expects($this->atLeastOnce())
->method('getDi')
->willReturn($this->di);
$service = new Box\Mod\Invoice\Service();
$service->onAfterAdminCronRun($eventMock);
$result = $this->di['db']->getAll($sql, $binigns);
$this->assertEquals(0, count($result));
}
public function testbatchActivatePaid(): void
{
$invoiceItems = $this->di['mod_service']('Invoice', 'InvoiceItem')->getAllNotExecutePaidItems();
$this->assertNotEmpty($invoiceItems);
$bool = $this->api_admin->invoice_batch_activate_paid();
$this->assertTrue($bool);
$invoiceItems = $this->di['mod_service']('Invoice', 'InvoiceItem')->getAllNotExecutePaidItems();
$this->assertEmpty($invoiceItems);
}
}
@@ -1,91 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class Box_Mod_Massmailer_Api_AdminTest extends BBModTestCase
{
protected $_mod = 'massmailer';
protected $_initialSeedFile = 'mod_massmailer.xml';
public function testActions(): void
{
$int = $this->api_admin->massmailer_create(['subject' => 'Subject', 'content' => 'content']);
$this->assertIsInt($int);
$array = $this->api_admin->massmailer_get(['id' => $int]);
$this->assertIsArray($array);
$data = [
'id' => $int,
'subject' => 'New subject',
'content' => 'New content',
'status' => 'draft',
'from_email' => 'test@mail.com',
'from_name' => 'John Doe',
];
$bool = $this->api_admin->massmailer_update($data);
$this->assertTrue($bool);
$array = $this->api_admin->massmailer_preview($data);
$this->assertIsArray($array);
$this->assertTrue(isset($array['subject']));
$this->assertTrue(isset($array['content']));
$array = $this->api_admin->massmailer_receivers($data);
$this->assertIsArray($array);
$array = $this->api_admin->massmailer_get_list();
$this->assertIsArray($array);
$this->assertEquals(2, $array['total']);
$new_id = $this->api_admin->massmailer_copy(['id' => $int]);
$this->assertIsInt($new_id);
$bool = $this->api_admin->massmailer_send_test(['id' => $new_id]);
$this->assertTrue($bool);
$bool = $this->api_admin->massmailer_send(['id' => $int]);
$this->assertTrue($bool);
$bool = $this->api_admin->massmailer_delete(['id' => $array['list'][0]['id']]);
$this->assertTrue($bool);
}
public function testFilter(): void
{
$filter = [
'client_status' => ['suspended', 'canceled'],
'client_groups' => ['1'],
'has_order' => ['1', '2'],
'has_order_with_status' => ['active'],
];
$this->api_admin->massmailer_update(['id' => 1, 'filter' => $filter]);
$this->api_admin->massmailer_send(['id' => 1]);
$this->assertTrue(is_array($filter));
}
public function testMassmailerGetList(): void
{
$array = $this->api_admin->massmailer_get_list();
$this->assertIsArray($array);
$this->assertArrayHasKey('list', $array);
$list = $array['list'];
$this->assertIsArray($list);
if (count($list)) {
$item = $list[0];
$this->assertArrayHasKey('id', $item);
$this->assertArrayHasKey('from_email', $item);
$this->assertArrayHasKey('from_name', $item);
$this->assertArrayHasKey('subject', $item);
$this->assertArrayHasKey('content', $item);
$this->assertArrayHasKey('filter', $item);
$this->assertIsArray($item['filter']);
$this->assertArrayHasKey('status', $item);
$this->assertArrayHasKey('sent_at', $item);
$this->assertArrayHasKey('created_at', $item);
$this->assertArrayHasKey('updated_at', $item);
}
}
}
@@ -1,116 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class Api_Admin_NewsTest extends BBDbApiTestCase
{
protected $_initialSeedFile = 'extension_news.xml';
public function testNews(): void
{
$array = $this->api_admin->news_get_list();
$this->assertIsArray($array);
$data = ['id' => 1];
$array = $this->api_admin->news_get($data);
$this->assertIsArray($array);
$data = [
'id' => 1,
'title' => 'News Title',
'slug' => 'news-title',
'status' => 'draft',
'content' => 'Announcement',
];
$bool = $this->api_admin->news_update($data);
$this->assertTrue($bool);
$bool = $this->api_admin->news_delete($data);
$this->assertTrue($bool);
$data = [
'title' => 'Test',
];
$id = $this->api_admin->news_create($data);
$this->assertTrue(is_numeric($id));
}
public function testNewsgetList(): void
{
$array = $this->api_admin->news_get_list();
$this->assertIsArray($array);
$this->assertArrayHasKey('list', $array);
$list = $array['list'];
$this->assertIsArray($list);
if (count($list)) {
$item = $list[0];
$this->assertArrayHasKey('id', $item);
$this->assertArrayHasKey('title', $item);
$this->assertArrayHasKey('content', $item);
$this->assertArrayHasKey('slug', $item);
$this->assertArrayHasKey('image', $item);
$this->assertArrayHasKey('section', $item);
$this->assertArrayHasKey('publish_at', $item);
$this->assertArrayHasKey('published_at', $item);
$this->assertArrayHasKey('expires_at', $item);
$this->assertArrayHasKey('created_at', $item);
$this->assertArrayHasKey('updated_at', $item);
$this->assertArrayHasKey('excerpt', $item);
$this->assertArrayHasKey('author', $item);
$author = $item['author'];
$this->assertIsArray($author);
$this->assertArrayHasKey('name', $author);
$this->assertArrayHasKey('email', $author);
}
}
public function testNewsBatchDelete(): void
{
$array = $this->api_admin->news_get_list([]);
foreach ($array['list'] as $value) {
$ids[] = $value['id'];
}
$result = $this->api_admin->news_batch_delete(['ids' => $ids]);
$array = $this->api_admin->news_get_list([]);
$this->assertEquals(0, count($array['list']));
$this->assertTrue($result);
}
public function testNewsMoreTagProvider()
{
$this->assertTrue(true);
return [
[
'This is blog post with<!--more--> tag',
'This is blog post with',
],
[
'This is blog post without more tag',
null,
],
];
}
#[PHPUnit\Framework\Attributes\DataProvider('testNewsMoreTagProvider')]
public function testNewsMoreTag($content, $expectedExcerpt): void
{
$data = [
'title' => 'News Title',
'slug' => 'news-title',
'status' => 'draft',
'content' => $content,
];
$id = $this->api_admin->news_create($data);
$array = $this->api_admin->news_get(['id' => $id]);
$this->assertEquals($array['excerpt'], $expectedExcerpt);
$this->assertEquals($array['content'], $content);
}
}
@@ -1,58 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class Api_Guest_NewsTest extends BBDbApiTestCase
{
protected $_initialSeedFile = 'extension_news.xml';
public function testNews(): void
{
$data = [
'page' => 1,
'per_page' => 1,
];
$array = $this->api_guest->news_get_list($data);
$this->assertIsArray($array);
$data = ['id' => 1];
$array = $this->api_guest->news_get($data);
$this->assertIsArray($array);
$data = ['slug' => 'boxbilling-is-customizable'];
$array = $this->api_guest->news_get($data);
$this->assertIsArray($array);
}
public function testNewsgetList(): void
{
$array = $this->api_admin->news_get_list();
$this->assertIsArray($array);
$this->assertArrayHasKey('list', $array);
$list = $array['list'];
$this->assertIsArray($list);
if (count($list)) {
$item = $list[0];
$this->assertArrayHasKey('id', $item);
$this->assertArrayHasKey('title', $item);
$this->assertArrayHasKey('content', $item);
$this->assertArrayHasKey('slug', $item);
$this->assertArrayHasKey('image', $item);
$this->assertArrayHasKey('section', $item);
$this->assertArrayHasKey('publish_at', $item);
$this->assertArrayHasKey('published_at', $item);
$this->assertArrayHasKey('expires_at', $item);
$this->assertArrayHasKey('created_at', $item);
$this->assertArrayHasKey('updated_at', $item);
$this->assertArrayHasKey('excerpt', $item);
$this->assertArrayHasKey('author', $item);
$author = $item['author'];
$this->assertIsArray($author);
$this->assertArrayHasKey('name', $author);
$this->assertArrayHasKey('email', $author);
}
}
}
@@ -1,43 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class Box_Mod_Notification_Api_AdminTest extends BBModTestCase
{
protected $_mod = 'notification';
protected $_initialSeedFile = 'mod_notification.xml';
public function testActions(): void
{
$this->api_admin->extension_activate(['id' => 'notification', 'type' => 'mod']);
$int = $this->api_admin->notification_add(['message' => 'Test message']);
$this->assertIsInt($int);
$array = $this->api_admin->notification_get(['id' => $int]);
$this->assertIsArray($array);
$array = $this->api_admin->notification_get_list();
$this->assertIsArray($array);
$this->assertEquals(1, $array['total']);
$this->assertArrayHasKey('list', $array);
$list = $array['list'];
$item = $list[0];
$this->assertIsArray($item);
$this->assertArrayHasKey('id', $item);
$this->assertArrayHasKey('client_id', $item);
$this->assertArrayHasKey('extension', $item);
$this->assertArrayHasKey('rel_type', $item);
$this->assertArrayHasKey('rel_id', $item);
$this->assertArrayHasKey('meta_key', $item);
$this->assertArrayHasKey('meta_value', $item);
$this->assertArrayHasKey('created_at', $item);
$this->assertArrayHasKey('updated_at', $item);
$bool = $this->api_admin->notification_delete(['id' => $array['list'][0]['id']]);
$this->assertTrue($bool);
$bool = $this->api_admin->notification_delete_all();
$this->assertTrue($bool);
}
}
@@ -1,334 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class Api_Admin_OrderTest extends BBDbApiTestCase
{
protected $_initialSeedFile = 'orders.xml';
public function testMetaUpdate(): void
{
$meta = [
'unique' => 'search by this field',
'param_1' => 'value 1',
'param_2' => 'value 2',
'param_3' => 'value 3',
];
$bool = $this->api_admin->order_update(['id' => '1', 'meta' => $meta]);
$this->assertTrue($bool);
$order = $this->api_admin->order_get(['id' => 1]);
$this->assertIsArray($order);
$this->assertTrue(isset($order['meta']));
$this->assertEquals('value 1', $order['meta']['param_1']);
$this->assertEquals('value 2', $order['meta']['param_2']);
$this->assertEquals('value 3', $order['meta']['param_3']);
// search test
$array = $this->api_admin->order_get_list(['meta' => ['unique' => 'search by this']]);
$this->assertEquals(1, $array['total']);
$this->assertEquals('search by this field', $array['list'][0]['meta']['unique']);
}
public static function orders()
{
return [
[1],
[2],
[3],
[4],
[5],
[6],
[7],
[9],
// array(12), // solusvm
// array(13), // serviceboxbillinglicense
];
}
#[PHPUnit\Framework\Attributes\DataProvider('orders')]
public function testOrdersStatuses($id): void
{
$data['id'] = $id;
$order = $this->api_admin->order_get($data);
$this->assertIsArray($order);
$this->assertEquals($id, $order['id']);
$list = $this->api_admin->order_get_list([]);
$this->assertIsArray($list);
$bool = $this->api_admin->order_update(['id' => 1, 'expires_at' => date('Y-m-d H:i:s', strtotime('+ 2 days'))]);
$this->assertTrue($bool);
$bool = $this->api_admin->order_renew($data);
$this->assertTrue($bool);
$bool = $this->api_admin->order_renew($data);
$this->assertTrue($bool);
$array = $this->api_admin->order_service($data);
$this->assertIsArray($array);
$bool = $this->api_admin->order_suspend($data);
$this->assertTrue($bool);
$bool = $this->api_admin->order_unsuspend($data);
$this->assertTrue($bool);
$bool = $this->api_admin->order_suspend($data);
$this->assertTrue($bool);
$bool = $this->api_admin->order_renew($data);
$this->assertTrue($bool);
$bool = $this->api_admin->order_cancel($data);
$this->assertTrue($bool);
$bool = $this->api_admin->order_uncancel($data);
$this->assertTrue($bool);
$bool = $this->api_admin->order_cancel($data);
$this->assertTrue($bool);
$bool = $this->api_admin->order_renew($data);
$this->assertTrue($bool);
$data['config'] = ['foo' => 'bar'];
$bool = $this->api_admin->order_update_config($data);
$this->assertTrue($bool);
$list = $this->api_admin->order_status_history_get_list($data);
$this->assertIsArray($list);
$array = $this->api_admin->order_addons($data);
$this->assertIsArray($array);
$bool = $this->api_admin->order_delete($data);
$this->assertTrue($bool);
}
public function testLists(): void
{
$array = $this->api_admin->order_get_invoice_options();
$this->assertIsArray($array);
$array = $this->api_admin->order_get_status_pairs();
$this->assertIsArray($array);
$array = $this->api_admin->order_get_statuses([]);
$this->assertIsArray($array);
}
public function testSuspension(): void
{
$bool = $this->api_admin->order_batch_suspend_expired();
$this->assertTrue($bool);
}
public function testCancellationOfSuspendedOrders(): void
{
$bool = $this->api_admin->order_batch_cancel_suspended();
$this->assertTrue($bool);
}
public function testLicense(): void
{
$data['id'] = 3;
$bool = $this->api_admin->order_renew($data);
$this->assertTrue($bool);
}
public function testDeleteAddons(): void
{
$data['id'] = 1;
$addons = $this->api_admin->order_addons($data);
$this->assertEquals(1, count($addons));
$addon_id = $addons[0]['id'];
$data['delete_addons'] = true;
$bool = $this->api_admin->order_delete($data);
$this->assertTrue($bool);
try {
$this->api_admin->order_get(['id' => $addon_id]);
$this->fail('Order addon should be removed');
} catch (Exception) {
}
}
public function testOrderExpiration(): void
{
$data = [
'id' => 8,
'period' => '2Y',
'expires_at' => date('Y-m-d H:i:s', strtotime('2012-01-10')),
];
$this->api_admin->order_update($data);
$ob = $this->api_admin->order_get($data);
$this->api_admin->order_renew($data);
$oa = $this->api_admin->order_get($data);
$this->assertEquals(2, date('Y', strtotime($oa['expires_at'])) - date('Y', strtotime($ob['expires_at'])));
}
public function testOrderExpirationSettingFromToday(): void
{
$data = [
'id' => 8,
'period' => '1M',
'expires_at' => date('Y-m-d H:i:s', strtotime('2012-01-10')),
];
$this->api_admin->order_update($data);
$orderConfig = $this->di['mod_config']('Order');
$orderConfig['order_renewal_logic'] = 'from_today';
$extensionService = $this->di['mod_service']('Extension');
$extensionService->setConfig($orderConfig);
$this->api_admin->order_renew($data);
$order = $this->api_admin->order_get($data);
$expectedExpireDate = date('Y-m-d', strtotime('+1 month'));
$this->assertEquals($expectedExpireDate, date('Y-m-d', strtotime($order['expires_at'])));
}
public function testOrderExpirationSettingFromGreaterFromTodayIsGreater(): void
{
$orderExpireDate = strtotime('2012-01-10');
$data = [
'id' => 8,
'period' => '1M',
'expires_at' => date('Y-m-d H:i:s', $orderExpireDate),
];
$this->api_admin->order_update($data);
$orderConfig = $this->di['mod_config']('Order');
$orderConfig['order_renewal_logic'] = 'from_greater';
$extensionService = $this->di['mod_service']('Extension');
$extensionService->setConfig($orderConfig);
$this->api_admin->order_renew($data);
$order = $this->api_admin->order_get($data);
$expectedExpiryDate = date('Y-m-d', strtotime('+1 month'));
$this->assertEquals($expectedExpiryDate, date('Y-m-d', strtotime($order['expires_at'])));
}
public function testOrderExpirationSettingFromGreaterExpireIsGreater(): void
{
$orderExpireDate = strtotime('+1 week');
$data = [
'id' => 8,
'period' => '1M',
'expires_at' => date('Y-m-d H:i:s', $orderExpireDate),
];
$this->api_admin->order_update($data);
$orderConfig = $this->di['mod_config']('Order');
$orderConfig['order_renewal_logic'] = 'from_greater';
$extensionService = $this->di['mod_service']('Extension');
$extensionService->setConfig($orderConfig);
$this->api_admin->order_renew($data);
$order = $this->api_admin->order_get($data);
$date = new DateTime(date('Y-m-d', $orderExpireDate));
$date->add(new DateInterval('P1M'));
$expectedExpiryDate = $date->format('Y-m-d');
$this->assertEquals($expectedExpiryDate, date('Y-m-d', strtotime($order['expires_at'])));
}
public function testDomainOrderExpiration(): void
{
$data['id'] = 7;
$bool = $this->api_admin->order_renew($data);
$this->assertTrue($bool);
$order = $this->api_admin->order_get($data);
$this->assertIsArray($order);
$this->assertTrue(!is_null($order['expires_at']), 'Domain Order expiration date was not set after activation');
}
public static function products()
{
return [
[1, []], // custom
[6, []], // license
[7, []], // downloadable
[10, ['action' => 'register', 'register_sld' => 'test', 'register_tld' => '.com', 'register_years' => '3']], // domain
[10, ['action' => 'transfer', 'transfer_sld' => 'test', 'transfer_tld' => '.com', 'transfer_code' => 'asdasd']], // domain
[10, ['action' => 'owndomain', 'owndomain_sld' => 'test', 'owndomain_tld' => '.com', 'register_years' => '3']], // domain
[12, ['some' => 'var']], // membership
[8, ['domain' => ['action' => 'owndomain', 'owndomain_sld' => 'cololo', 'owndomain_tld' => '.com']]], // hosting
[3, []], // addon
];
}
#[PHPUnit\Framework\Attributes\DataProvider('products')]
public function testCreate($pid, $config): void
{
$data['client_id'] = 1;
$data['product_id'] = $pid;
$data['period'] = '1M';
$data['group_id'] = 200;
// $data['currency'] = 'EUR';
// $data['invoice_option'] = 'issue-invoice';
$data['invoice_option'] = 'no-invoice';
$data['activate'] = 1;
$data['config'] = $config;
$id = $this->api_admin->order_create($data);
$this->assertIsInt($id);
}
/**
* Test recurent promo for order
* 1. If promo is recurrent then new invoice is generated with discount
* 2. If promo is not recurrent then new invoice is generated for order total price.
*/
public function testPromoRec(): void
{
$data['id'] = 8; // order with recurring promo
$id = $this->api_admin->invoice_renewal_invoice($data);
$invoice = $this->api_admin->invoice_get(['id' => $id]);
$this->assertEquals(15, $invoice['lines'][0]['total']);
$data['id'] = 10; // order without recurring promo
$id = $this->api_admin->invoice_renewal_invoice($data);
$invoice = $this->api_admin->invoice_get(['id' => $id]);
$this->assertEquals(30, $invoice['lines'][0]['total']);
}
public function testHistory(): void
{
$data = [
'id' => 1,
'status' => 'cancelled by phpUnit',
];
$result = $this->api_admin->order_status_history_add($data);
$this->assertTrue($result);
$data = [
'id' => 1,
];
$result = $this->api_admin->order_status_history_delete($data);
$this->assertTrue($result);
}
public function testOrderBatchDelete(): void
{
$array = $this->api_admin->order_get_list([]);
foreach ($array['list'] as $value) {
$ids[] = $value['id'];
}
$result = $this->api_admin->order_batch_delete(['ids' => $ids, 'delete_addons' => true]);
$array = $this->api_admin->order_get_list([]);
$this->assertEquals(0, count($array['list']));
$this->assertTrue($result);
}
}
@@ -1,76 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class Api_Client_OrderTest extends BBDbApiTestCase
{
protected $_initialSeedFile = 'orders.xml';
public function testOrders(): void
{
$data = [
'page' => 1,
'per_page' => 10,
];
$array = $this->api_client->order_get_list($data);
$this->assertIsArray($array);
$data = [
'page' => 1,
'per_page' => 10,
'expiring' => 1,
];
$array = $this->api_client->order_get_list($data);
$this->assertIsArray($array);
$data = [
'id' => 1,
];
$array = $this->api_client->order_get($data);
$this->assertIsArray($array);
$array = $this->api_client->order_addons($data);
$this->assertIsArray($array);
}
public function testDelete(): void
{
$data = [
'id' => 9,
];
$bool = $this->api_client->order_delete($data);
$this->assertTrue($bool);
}
public function testService(): void
{
$data = [
'id' => 8,
];
$expected = [
'id' => 1,
'client_id' => 1,
'plugin' => 'Example',
'updated_at' => null,
'created_at' => null,
];
$result = $this->api_client->order_service($data);
$this->assertIsArray($result);
$this->assertNotEmpty($result);
$this->assertEquals($expected, $result);
}
public function testupgradablesNoUpgradablesFound(): void
{
$data = [
'id' => 8,
];
$result = $this->api_client->order_upgradables($data);
$this->assertIsArray($result);
$this->assertEmpty($result);
}
}
@@ -1,13 +0,0 @@
<?php
class Box_Mod_Page_Api_AdminTest extends BBModTestCase
{
protected $_mod = 'page';
protected $_initialSeedFile = 'mod_page.xml';
public function testMod(): void
{
$array = $this->api_admin->page_get_pairs();
$this->assertIsArray($array);
}
}
@@ -1,175 +0,0 @@
<?php
class Box_Mod_Paidsupport_ServiceTest extends ApiTestCase
{
public function setup(): void
{
parent::setUp();
$data = [
'id' => 'paidsupport',
'type' => 'mod',
];
$this->api_admin->extension_activate($data);
$hookService = $this->di['mod_service']('hook');
$hookService->batchConnect('paidsupport');
}
public function testCreatePaidSupportTicket(): void
{
$ticketPrice = 5.5;
$balance = $this->api_client->client_balance_get_total();
if ($balance < $ticketPrice) {
$this->api_admin->client_balance_add_funds(['id' => 1, 'amount' => $ticketPrice, 'description' => 'Added from PHPUnit']);
}
$helpdeskId = 1;
$beforeBalance = $this->api_client->client_balance_get_total();
$data = [
'ext' => 'mod_paidsupport',
'ticket_price' => $ticketPrice,
'error_msg' => 'Insufficient amount in balance',
'helpdesk' => [$helpdeskId => 1],
];
$this->api_admin->extension_config_save($data);
$data = [
'subject' => 'Subject',
'content' => 'content',
'support_helpdesk_id' => $helpdeskId,
'order_id' => '1',
'task' => 'cancel',
];
$id = $this->api_client->support_ticket_create($data);
$supportTicket = $this->di['db']->load('SupportTicket', $id);
$this->assertInstanceOf('\Model_SupportTicket', $supportTicket);
$balance = $this->api_client->client_balance_get_total();
$this->assertEquals($beforeBalance - $ticketPrice, $balance);
$clientBalanceModel = $this->di['db']->findOne('ClientBalance', 'ORDER BY id desc');
$this->assertEquals(-$ticketPrice, $clientBalanceModel->amount);
}
public function testCreatePaidSupportTicketHelpdeskhasPaidSupport(): void
{
$ticketPrice = 5.5;
$balance = $this->api_client->client_balance_get_total();
if ($balance < $ticketPrice) {
$this->api_admin->client_balance_add_funds(['id' => 1, 'amount' => $ticketPrice, 'description' => 'Added from PHPUnit']);
}
$beforeBalance = $this->api_client->client_balance_get_total();
$helpdeskId = 1;
$data = [
'ext' => 'mod_paidsupport',
'ticket_price' => $ticketPrice,
'error_msg' => 'Insufficient amount in balance',
'helpdesk' => [$helpdeskId => 1],
];
$this->api_admin->extension_config_save($data);
$data = [
'subject' => 'Subject',
'content' => 'content',
'support_helpdesk_id' => $helpdeskId,
'order_id' => '1',
'task' => 'cancel',
];
$id = $this->api_client->support_ticket_create($data);
$supportTicket = $this->di['db']->load('SupportTicket', $id);
$this->assertInstanceOf('\Model_SupportTicket', $supportTicket);
$balance = $this->api_client->client_balance_get_total();
$this->assertEquals($beforeBalance - $ticketPrice, $balance);
$clientBalanceModel = $this->di['db']->findOne('ClientBalance', 'ORDER BY id desc');
$this->assertEquals(-$ticketPrice, $clientBalanceModel->amount);
}
public function testCreatePaidSupportTicketHelpdesHasNotPaidSupport(): void
{
$ticketPrice = 5.5;
$balance = $this->api_client->client_balance_get_total();
if ($balance <= $ticketPrice) {
$this->api_admin->client_balance_add_funds(['id' => 1, 'amount' => $ticketPrice, 'description' => 'Added from PHPUnit']);
}
$beforeBalance = $this->api_client->client_balance_get_total();
$helpdeskId = 1;
$data = [
'ext' => 'mod_paidsupport',
'ticket_price' => $ticketPrice,
'error_msg' => 'Insufficient amount in balance',
'helpdesk' => [$helpdeskId => 0],
];
$this->api_admin->extension_config_save($data);
$data = [
'subject' => 'Subject',
'content' => 'content',
'support_helpdesk_id' => $helpdeskId,
'order_id' => '1',
'task' => 'cancel',
];
$id = $this->api_client->support_ticket_create($data);
$supportTicket = $this->di['db']->load('SupportTicket', $id);
$this->assertInstanceOf('\Model_SupportTicket', $supportTicket);
$balance = $this->api_client->client_balance_get_total();
$this->assertEquals($beforeBalance, $balance);
}
public function testCreatePaidSupportTicketInsufficientFunds(): void
{
$balance = $this->api_client->client_balance_get_total();
$ticketPrice = 10 + $balance;
$errorMessage = 'Insufficient amount in balance';
$helpdeskId = 1;
$data = [
'ext' => 'mod_paidsupport',
'ticket_price' => $ticketPrice,
'error_msg' => $errorMessage,
'helpdesk' => [$helpdeskId => 1],
];
$this->api_admin->extension_config_save($data);
$data = [
'subject' => 'Subject',
'content' => 'content',
'support_helpdesk_id' => '1',
'order_id' => '1',
'task' => 'cancel',
];
$supportTickets = $this->di['db']->find('SupportTicket');
$this->expectException(FOSSBilling\Exception::class);
$this->expectExceptionMessage($errorMessage);
$this->api_client->support_ticket_create($data);
$supportTicketsAfterCreate = $this->di['db']->find('SupportTicket');
$this->assertEquals(count($supportTickets), count($supportTicketsAfterCreate));
}
}
@@ -1,218 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class Api_Admin_ProductTest extends ApiTestCase
{
public function testLists(): void
{
$list = $this->api_admin->product_get_list();
$this->assertIsArray($list);
$list = $this->api_admin->product_get_pairs();
$this->assertIsArray($list);
$list = $this->api_admin->product_get_types();
$this->assertIsArray($list);
$data = [
'id' => 10,
];
$array = $this->api_admin->product_get($data);
$this->assertIsArray($array);
}
public function testProduct(): void
{
$data = [
'title' => 'title',
'type' => Model_ProductTable::CUSTOM,
'product_category_id' => 1,
];
$id = $this->api_admin->product_prepare($data);
$this->assertTrue(is_numeric($id));
$data = [
'id' => $id,
'title' => 'new title',
];
$bool = $this->api_admin->product_update($data);
$this->assertTrue($bool);
$bool = $this->api_admin->product_update_config($data);
$this->assertTrue($bool);
}
public function testAddons(): void
{
$array = $this->api_admin->product_addon_get_pairs();
$this->assertIsArray($array);
$data = [
'title' => 'title',
];
$id = $this->api_admin->product_addon_create($data);
$this->assertTrue(is_numeric($id));
$data = [
'id' => $id,
'title' => 'new title',
];
$array = $this->api_admin->product_addon_get($data);
$this->assertIsArray($array);
$bool = $this->api_admin->product_addon_update($data);
$this->assertTrue($bool);
$bool = $this->api_admin->product_addon_delete($data);
$this->assertTrue($bool);
}
public function testCategory(): void
{
$array = $this->api_admin->product_category_get_pairs();
$this->assertIsArray($array);
$data = [
'title' => 'title',
];
$id = $this->api_admin->product_category_create($data);
$this->assertTrue(is_numeric($id));
$data = [
'id' => $id,
'title' => 'title',
];
$array = $this->api_admin->product_category_get($data);
$this->assertIsArray($array);
$bool = $this->api_admin->product_category_update($data);
$this->assertTrue($bool);
$bool = $this->api_admin->product_category_delete($data);
$this->assertTrue($bool);
}
public function testPromos(): void
{
$array = $this->api_admin->product_promo_get_list();
$this->assertIsArray($array);
$data = [
'code' => 'title',
'type' => 'percent',
'value' => '50',
];
$id = $this->api_admin->product_promo_create($data);
$this->assertTrue(is_numeric($id));
$data = [
'id' => $id,
'value' => '25',
];
$array = $this->api_admin->product_promo_get($data);
$this->assertIsArray($array);
$bool = $this->api_admin->product_promo_update($data);
$this->assertTrue($bool);
$bool = $this->api_admin->product_promo_delete($data);
$this->assertTrue($bool);
}
public function testProductGetList(): void
{
$array = $this->api_admin->product_get_list();
$this->assertIsArray($array);
$this->assertArrayHasKey('list', $array);
$list = $array['list'];
$this->assertIsArray($list);
$item = $list[0];
$this->assertArrayHasKey('id', $item);
$this->assertArrayHasKey('product_category_id', $item);
$this->assertArrayHasKey('type', $item);
$this->assertArrayHasKey('title', $item);
$this->assertArrayHasKey('form_id', $item);
$this->assertArrayHasKey('slug', $item);
$this->assertArrayHasKey('description', $item);
$this->assertArrayHasKey('unit', $item);
$this->assertArrayHasKey('priority', $item);
$this->assertArrayHasKey('created_at', $item);
$this->assertArrayHasKey('updated_at', $item);
$this->assertArrayHasKey('pricing', $item);
$pricing = $item['pricing'];
$this->assertIsArray($item['pricing']);
$this->assertArrayHasKey('type', $pricing);
$this->assertArrayHasKey('free', $pricing);
$this->assertArrayHasKey('once', $pricing);
$this->assertArrayHasKey('recurrent', $pricing);
$this->assertArrayHasKey('config', $item);
$this->assertIsArray($item['config']);
$this->assertArrayHasKey('addons', $item);
$this->assertIsArray($item['addons']);
$this->assertArrayHasKey('price_starting_from', $item);
$this->assertArrayHasKey('icon_url', $item);
$this->assertArrayHasKey('allow_quantity_select', $item);
$this->assertArrayHasKey('quantity_in_stock', $item);
$this->assertArrayHasKey('stock_control', $item);
$this->assertArrayHasKey('upgrades', $item);
$this->assertIsArray($item['upgrades']);
$this->assertArrayHasKey('status', $item);
$this->assertArrayHasKey('hidden', $item);
$this->assertArrayHasKey('setup', $item);
$this->assertArrayHasKey('category', $item);
$this->assertIsArray($item['category']);
}
public function testProductPromoGetList(): void
{
$array = $this->api_admin->product_promo_get_list();
$this->assertIsArray($array);
$this->assertArrayHasKey('list', $array);
$list = $array['list'];
$this->assertIsArray($list);
$item = $list[0];
$this->assertArrayHasKey('id', $item);
$this->assertArrayHasKey('code', $item);
$this->assertArrayHasKey('description', $item);
$this->assertArrayHasKey('type', $item);
$this->assertArrayHasKey('value', $item);
$this->assertArrayHasKey('maxuses', $item);
$this->assertArrayHasKey('used', $item);
$this->assertArrayHasKey('freesetup', $item);
$this->assertArrayHasKey('once_per_client', $item);
$this->assertArrayHasKey('recurring', $item);
$this->assertArrayHasKey('active', $item);
$this->assertArrayHasKey('products', $item);
$this->assertArrayHasKey('periods', $item);
$this->assertArrayHasKey('start_at', $item);
$this->assertArrayHasKey('end_at', $item);
$this->assertArrayHasKey('created_at', $item);
$this->assertArrayHasKey('updated_at', $item);
$this->assertArrayHasKey('applies_to', $item);
$this->assertIsArray($item['applies_to']);
}
public function testCreateTwoDomainProducts(): void
{
$data = [
'title' => 'Two domain product check_',
'type' => Model_ProductTable::DOMAIN,
];
$this->expectException(FOSSBilling\Exception::class);
$this->expectExceptionCode(413);
$this->expectExceptionMessage('You have already created domain product.');
for ($i = 0; $i < 2; ++$i) {
$id = $this->api_admin->product_prepare($data);
}
}
}
@@ -1,111 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class Api_Guest_ProductTest extends BBDbApiTestCase
{
protected $_initialSeedFile = 'orders.xml';
public function testGetAll(): void
{
$list = $this->api_guest->product_get_pairs();
$this->assertIsArray($list);
$list = $this->api_guest->product_get_list();
$this->assertIsArray($list);
$list = $this->api_guest->product_category_get_pairs();
$this->assertIsArray($list);
$data = [
'id' => 10,
];
$list = $this->api_guest->product_get($data);
$this->assertIsArray($list);
$list = $this->api_guest->product_get_slider($data);
$this->assertIsArray($list);
}
public function testCategoryGetList(): void
{
$pager = $this->api_guest->product_category_get_list();
$this->assertIsArray($pager);
$this->assertArrayHasKey('list', $pager);
$list = $pager['list'];
$this->assertIsArray($list);
$item = $list[0];
$this->assertArrayHasKey('price_starting_from', $item);
$this->assertArrayHasKey('icon_url', $item);
$this->assertArrayHasKey('type', $item);
$this->assertArrayHasKey('products', $item);
$this->assertIsArray($item['products']);
}
/*
public function testBenchmark()
{
$timer = new Benchmark_Timer();
$timer->start();
$list = $this->api_guest->product_get_categories();
$timer->stop();
$timer->display();
}
*/
public function testProductGetList(): void
{
$array = $this->api_guest->product_get_list();
$this->assertIsArray($array);
$this->assertArrayHasKey('list', $array);
$list = $array['list'];
$this->assertIsArray($list);
$item = $list[0];
$this->assertArrayHasKey('id', $item);
$this->assertArrayHasKey('product_category_id', $item);
$this->assertArrayHasKey('type', $item);
$this->assertArrayHasKey('title', $item);
$this->assertArrayHasKey('form_id', $item);
$this->assertArrayHasKey('slug', $item);
$this->assertArrayHasKey('description', $item);
$this->assertArrayHasKey('unit', $item);
$this->assertArrayHasKey('priority', $item);
$this->assertArrayHasKey('created_at', $item);
$this->assertArrayHasKey('updated_at', $item);
$this->assertArrayHasKey('pricing', $item);
$pricing = $item['pricing'];
$this->assertIsArray($item['pricing']);
$this->assertArrayHasKey('type', $pricing);
$this->assertArrayHasKey('free', $pricing);
$this->assertArrayHasKey('once', $pricing);
$this->assertArrayHasKey('recurrent', $pricing);
$this->assertArrayHasKey('config', $item);
$this->assertIsArray($item['config']);
$this->assertArrayHasKey('addons', $item);
$this->assertIsArray($item['addons']);
$this->assertArrayHasKey('price_starting_from', $item);
$this->assertArrayHasKey('icon_url', $item);
$this->assertArrayHasKey('allow_quantity_select', $item);
$this->assertArrayHasKey('quantity_in_stock', $item);
$this->assertArrayHasKey('stock_control', $item);
$this->assertArrayNotHasKey('upgrades', $item);
$this->assertArrayNotHasKey('status', $item);
$this->assertArrayNotHasKey('hidden', $item);
$this->assertArrayNotHasKey('setup', $item);
$this->assertArrayNotHasKey('category', $item);
}
public function testProductStartingFromPriceDomainType(): void
{
$array = $this->api_guest->product_get(['id' => 10]);
$this->assertTrue($array['price_starting_from'] > 0);
}
}
@@ -1,11 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class Api_Admin_PromoTest extends ApiTestCase
{
public function testPromo(): void
{
$array = $this->api_admin->product_promo_get_list();
$this->assertIsArray($array);
}
}
@@ -1,42 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class Api_Admin_ProfileTest extends BBDbApiTestCase
{
protected $_initialSeedFile = 'admins.xml';
public function testProfile(): void
{
$array = $this->api_admin->profile_get();
$this->assertIsArray($array);
$bool = $this->api_admin->profile_logout();
$this->assertTrue($bool);
$data = [
'email' => 'demo@fossbilling.org',
'name' => 'Demo Admin',
'signature' => 'New Signature',
];
$bool = $this->api_admin->profile_update($data);
$this->assertTrue($bool);
$bool = $this->api_admin->profile_generate_api_key($data);
$this->assertTrue($bool);
}
public function testPassword(): void
{
$data = [
'password' => 'demo12313123A',
'password_confirm' => 'demo12313123A',
];
$bool = $this->api_admin->profile_change_password($data);
$this->assertTrue($bool);
$array = $this->api_admin->profile_get();
$password = $this->di['db']->getCell('Select pass from admin where id = ?', [$array['id']]);
$this->assertTrue($this->di['password']->verify($data['password'], $password));
}
}
@@ -1,92 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class Api_Client_ProfileTest extends BBDbApiTestCase
{
protected $_initialSeedFile = 'mod_client.xml';
public function testProfile(): void
{
$array = $this->api_client->profile_get();
$this->assertIsArray($array);
$data = [
'email' => 'email@test.com',
'first_name' => 'First name',
'last_name' => 'Last Name',
'address_1' => 'address 1',
'address_2' => 'address 2',
'country' => 'country',
'city' => 'city',
'state' => 'n/a',
'postcode' => '123456',
'phone_cc' => 1234,
'phone' => 1_212_121_212_121,
];
$bool = $this->api_client->profile_update($data);
$this->assertTrue($bool);
$bool = $this->api_client->profile_update($data);
$this->assertTrue($bool);
}
public function testPassword(): void
{
$data = [
'password' => 'demo11AA1111',
'password_confirm' => 'demo11AA1111',
];
$bool = $this->api_client->profile_change_password($data);
$this->assertTrue($bool);
}
public function testApi(): void
{
$string = $this->api_client->profile_api_key_reset();
$this->assertIsString($string);
$string = $this->api_client->profile_api_key_get();
$this->assertIsString($string);
}
public function testBalance(): void
{
$array = $this->api_client->client_balance_get_list();
$this->assertIsArray($array);
}
public function testLogout(): void
{
$bool = $this->api_client->profile_logout();
$this->assertTrue($bool);
}
public function testEmailChange(): void
{
// enable email change
$config = [
'ext' => 'mod_client',
'disable_change_email' => false,
];
$bool = $this->api_admin->extension_config_save($config);
$this->assertTrue($bool);
$bool = $this->api_client->profile_update(['email' => 'test@email.com']);
$this->assertTrue($bool);
// disable email change
$config = [
'ext' => 'mod_client',
'disable_change_email' => true,
];
$bool = $this->api_admin->extension_config_save($config);
$this->assertTrue($bool);
try {
$this->api_client->profile_update(['email' => 'new@email.com']);
$this->fail('Email should not changed due to setting');
} catch (Exception) {
// ok
}
}
}
@@ -1,31 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class Box_Mod_Redirect_Api_AdminTest extends BBModTestCase
{
protected $_mod = 'redirect';
protected $_initialSeedFile = 'mod_redirect.xml';
public function testRedirect(): void
{
$array = $this->api_admin->redirect_get_list();
$this->assertIsArray($array);
$int = $this->api_admin->redirect_create(['path' => '/knowledgebase', 'target' => 'support/kb']);
$this->assertIsInt($int);
$r = $this->api_admin->redirect_get(['id' => $int]);
$this->assertTrue(isset($r['id']));
$this->assertTrue(isset($r['path']));
$this->assertTrue(isset($r['target']));
$bool = $this->api_admin->redirect_update(['id' => $int, 'target' => 'new-target']);
$this->assertTrue($bool);
$bool = $this->api_admin->redirect_update(['id' => $int, 'path' => '/new-path']);
$this->assertTrue($bool);
$bool = $this->api_admin->redirect_delete(['id' => $int]);
$this->assertTrue($bool);
}
}
@@ -1,84 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class Api_Client_ServiceBoxBillinglicenseTest extends BBDbApiTestCase
{
protected $_initialSeedFile = 'serviceboxbillinglicense.xml';
public function testserviceboxbillinglicense(): void
{
$data = [
'order_id' => 16,
];
$serviceMock = $this->getMockBuilder('Box\Mod\Serviceboxbillinglicense\Service')->getMock();
$serviceMock->expects($this->any())
->method('reset')
->willReturn(true);
$client = new Model_Client();
$client->loadBean(new RedBeanPHP\OODBBean());
$client->id = 1;
$clientApi = new Box\Mod\Serviceboxbillinglicense\Api\Client();
$clientApi->setService($serviceMock);
$clientApi->setDi($this->di);
$clientApi->setIdentity($client);
$bool = $clientApi->reset($data);
$this->assertTrue($bool);
}
public function testGetServiceMissingOrderId(): void
{
$data = [];
$clientApi = new Box\Mod\Serviceboxbillinglicense\Api\Client();
$clientApi->setDi($this->di);
$this->expectException(FOSSBilling\Exception::class);
$this->expectExceptionMessage('Order ID is required');
$bool = $clientApi->reset($data);
}
public function testGetServiceOrderNotFound(): void
{
$data = [
'order_id' => 160,
];
$client = new Model_Client();
$client->loadBean(new RedBeanPHP\OODBBean());
$client->id = 1;
$clientApi = new Box\Mod\Serviceboxbillinglicense\Api\Client();
$clientApi->setDi($this->di);
$clientApi->setIdentity($client);
$this->expectException(FOSSBilling\Exception::class);
$this->expectExceptionMessage('FOSSBilling license order not found');
$bool = $clientApi->reset($data);
}
public function testGetServiceOrderNotActivated(): void
{
$data = [
'order_id' => 17,
];
$client = new Model_Client();
$client->loadBean(new RedBeanPHP\OODBBean());
$client->id = 1;
$clientApi = new Box\Mod\Serviceboxbillinglicense\Api\Client();
$clientApi->setDi($this->di);
$clientApi->setIdentity($client);
$this->expectException(FOSSBilling\Exception::class);
$this->expectExceptionMessage('Order is not activated');
$bool = $clientApi->reset($data);
}
}
@@ -1,85 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class ServiceBoxBillinglicenseTest extends BBDbApiTestCase
{
public function testService(): void
{
$service = new Box\Mod\Serviceboxbillinglicense\Service();
$service->setDi($this->di);
$result = $service->install();
$this->assertNull($result);
$data = [
'param' => 'value',
];
$result = $service->setModuleConfig($data);
$this->assertNull($result);
$config = $service->getModuleConfig();
$this->assertArrayHasKey('param', $config);
$this->assertEquals($data['param'], $config['param']);
}
public function testActions(): void
{
$service = new Box\Mod\Serviceboxbillinglicense\Service();
$service->setDi($this->di);
$order = $this->di['db']->load('ClientOrder', 1);
$model = $service->create($order);
$this->assertInstanceOf('\\' . RedBeanPHP\OODBBean::class, $model);
$this->expectException(FOSSBilling\Exception::class);
$this->expectExceptionCode(7456);
$this->expectExceptionMessage('Could not activate order. Service was not created');
$service->activate($order, null);
$result = $service->activate($order, $model);
$this->assertTrue($result);
$this->expectException(FOSSBilling\Exception::class);
$this->expectExceptionCode(7456);
$this->expectExceptionMessage('Could not activate order. Service was not created');
$service->suspend($order, null);
$result = $service->suspend($order, $model);
$this->assertTrue($result);
$this->expectException(FOSSBilling\Exception::class);
$this->expectExceptionCode(7456);
$this->expectExceptionMessage('Could not activate order. Service was not created');
$service->unsuspend($order, null);
$result = $service->unsuspend($order, $model);
$this->assertTrue($result);
$result = $service->reset($order, $model);
$this->assertTrue($result);
$result = $service->licenseDetails($model);
$this->assertIsArray($result);
$result = $service->licenseReset($model);
$this->assertIsArray($result);
$result = $service->toApiArray($model);
$this->assertIsArray($result);
$this->assertArrayHasKey('id', $result);
$this->assertArrayHasKey('oid', $result);
$result = $service->delete($order, $model);
$this->assertTrue($result);
}
public function testUninstall(): void
{
$service = new Box\Mod\Serviceboxbillinglicense\Service();
$service->setDi($this->di);
$result = $service->uninstall();
$this->assertNull($result);
$service->install();
}
}
@@ -1,37 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class Api_Admin_ServiceCustomTest extends BBDbApiTestCase
{
protected $_initialSeedFile = 'services.xml';
public function testServiceCustom(): void
{
$data = [
'order_id' => 10,
];
$result = $this->api_admin->servicecustom_return_params($data);
$this->assertEquals($data, $result);
$result = $this->api_admin->servicecustom_get_config($data);
$this->assertEquals(['param' => 'value'], $result);
try {
$this->api_admin->servicecustom_non_existing($data);
$this->fail('Method should not exist on plugin');
} catch (Exception $e) {
$this->assertEquals(3125, $e->getCode());
}
try {
$this->api_admin->servicecustom_delete($data);
$this->fail('Renew method should be forbidden');
} catch (Exception $e) {
$this->assertEquals(403, $e->getCode());
}
$orderModel = $this->di['db']->load('ClientOrder', $data['order_id']);
$serviceCustomModel = $this->di['db']->load('ServiceCustom', $orderModel->service_id);
$this->di['db']->trash($serviceCustomModel);
}
}
@@ -1,34 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class Api_Client_ServiceCustomTest extends BBDbApiTestCase
{
protected $_initialSeedFile = 'services.xml';
public function testServiceCustom(): void
{
$data = [
'order_id' => 9,
];
$result = $this->api_client->servicecustom_return_params($data);
$this->assertEquals($data, $result);
try {
$this->api_client->servicecustom_non_existing($data);
$this->fail('Method should not exist on plugin');
} catch (Exception $e) {
$this->assertEquals(3125, $e->getCode());
}
try {
$this->api_client->servicecustom_renew($data);
$this->fail('Renew method should be forbidden');
} catch (Exception $e) {
$this->assertEquals(403, $e->getCode());
}
$orderModel = $this->di['db']->load('ClientOrder', $data['order_id']);
$serviceCustomModel = $this->di['db']->load('ServiceCustom', $orderModel->service_id);
$this->di['db']->trash($serviceCustomModel);
}
}
@@ -1,13 +0,0 @@
<?php
class Box_Mod_Servicedomain_Api_AdminTest extends BBModTestCase
{
protected $_mod = 'servicedomain';
protected $_initialSeedFile = 'mod_servicedomain.xml';
public function testSync(): void
{
$bool = $this->api_admin->servicedomain_batch_sync_expiration_dates();
$this->assertTrue($bool);
}
}
@@ -1,73 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class Api_Client_ServiceDomainTest extends BBDbApiTestCase
{
protected $_initialSeedFile = 'services.xml';
public static function orders()
{
return [
[3],
[4],
];
}
#[PHPUnit\Framework\Attributes\DataProvider('orders')]
public function testClientServiceDomain($id): void
{
$this->api_admin->order_renew(['id' => $id]);
$data = [
'order_id' => $id,
'ns1' => 'ns1.1freehosting.com',
'ns2' => 'ns2.1freehosting.com',
'ns3' => 'ns3.1freehosting.com',
'ns4' => 'ns4.1freehosting.com',
];
$bool = $this->api_client->serviceDomain_update_nameservers($data);
$this->assertTrue($bool);
$data = [
'order_id' => $id,
'contact' => [
'first_name' => 'John',
'last_name' => 'Does',
'email' => 'email@example.com ',
'company' => 'Company',
'address1' => 'Adress 1',
'address2' => 'Adress 2',
'country' => 'US',
'city' => 'San Jose',
'state' => 'n/a',
'postcode' => '20506',
'phone_cc' => '1408',
'phone' => '123456',
],
];
$bool = $this->_callOnService('update_contacts', $data);
$this->assertTrue($bool, 'Failed updating contacts');
$bool = $this->_callOnService('get_transfer_code', $data);
$this->assertTrue($bool, 'Getting epp code');
$bool = $this->_callOnService('enable_privacy_protection', $data);
$this->assertTrue($bool, 'Failed Enabling privacy protection');
$bool = $this->_callOnService('disable_privacy_protection', $data);
$this->assertTrue($bool, 'Failed Disabling privacy protection');
$bool = $this->_callOnService('lock', $data);
$this->assertTrue($bool);
$bool = $this->_callOnService('unlock', $data);
$this->assertTrue($bool);
}
protected function _callOnService($method, $data)
{
$m = 'serviceDomain_' . $method;
return $this->api_client->{$m}($data);
}
}
@@ -1,29 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class Api_Guest_ServiceDomainTest extends BBDbApiTestCase
{
protected $_initialSeedFile = 'services.xml';
public function testGuestServiceDomain(): void
{
$data = [
'sld' => 'phpunit',
'tld' => '.com',
];
$bool = $this->api_guest->servicedomain_check($data);
$this->assertTrue($bool);
$bool = $this->api_guest->servicedomain_can_be_transferred($data);
$this->assertTrue($bool);
$array = $this->api_guest->servicedomain_pricing($data);
$this->assertIsArray($array);
}
public function testTlds(): void
{
$array = $this->api_guest->servicedomain_tlds();
$this->assertIsArray($array);
}
}
@@ -1,188 +0,0 @@
<?php
/**
* @todo review
*/
class Api_Admin_ServiceDomainTest extends BBDbApiTestCase
{
protected $_initialSeedFile = 'services.xml';
public static function orders()
{
return [
[3],
[4],
];
}
#[PHPUnit\Framework\Attributes\DataProvider('orders')]
public function testDomain($id): void
{
$this->api_admin->order_renew(['id' => $id]);
$data = [
'order_id' => $id,
'ns1' => 'ns1.1freehosting.com',
'ns2' => 'ns2.1freehosting.com',
'ns3' => 'ns3.1freehosting.com',
'ns4' => 'ns4.1freehosting.com',
];
$bool = $this->api_admin->servicedomain_update_nameservers($data);
$this->assertTrue($bool);
$data = [
'order_id' => $id,
'contact' => [
'first_name' => 'John',
'last_name' => 'Does',
'email' => 'email@example.com ',
'company' => 'Company',
'address1' => 'Adress 1',
'address2' => 'Adress 2',
'country' => 'US',
'city' => 'San Jose',
'state' => 'n/a',
'postcode' => '20506',
'phone_cc' => '1408',
'phone' => '123456',
],
];
$bool = $this->_callOnService('update_contacts', $data);
$this->assertTrue($bool, 'Failed updating contacts');
$bool = $this->_callOnService('get_transfer_code', $data);
$this->assertTrue($bool, 'Getting epp code');
$bool = $this->_callOnService('enable_privacy_protection', $data);
$this->assertTrue($bool, 'Failed Enabling privacy protection');
$bool = $this->_callOnService('disable_privacy_protection', $data);
$this->assertTrue($bool, 'Failed Disabling privacy protection');
$bool = $this->_callOnService('lock', $data);
$this->assertTrue($bool);
$bool = $this->_callOnService('unlock', $data);
$this->assertTrue($bool);
}
public function testTld(): void
{
$array = $this->api_admin->servicedomain_tld_get_list();
$this->assertIsArray($array);
$data = [
'tld' => '.ru',
'tld_registrar_id' => 1,
'price_registration' => 1,
'price_renew' => 1,
'price_transfer' => 1,
];
$id = $this->api_admin->servicedomain_tld_create($data);
$this->assertTrue(is_numeric($id));
$data['id'] = $id;
$array = $this->api_admin->servicedomain_tld_get($data);
$this->assertIsArray($array);
$data['price_renew'] = '15';
$bool = $this->api_admin->servicedomain_tld_update($data);
$this->assertTrue($bool);
$bool = $this->api_admin->servicedomain_tld_delete($data);
$this->assertTrue($bool);
}
public function testRegistrar(): void
{
$array = $this->api_admin->servicedomain_registrar_get_pairs();
$this->assertIsArray($array);
$array = $this->api_admin->servicedomain_registrar_get_available();
$this->assertIsArray($array);
$data = [
'id' => 1,
];
$id = $this->api_admin->servicedomain_registrar_copy($data);
$this->assertTrue(is_numeric($id));
$data = [
'id' => $id,
];
$array = $this->api_admin->servicedomain_registrar_get($data);
$this->assertIsArray($array);
$data['title'] = 'New title';
$bool = $this->api_admin->servicedomain_registrar_update($data);
$this->assertTrue($bool);
}
public function testInstall(): void
{
$array = $this->api_admin->servicedomain_registrar_get_available();
$this->assertIsArray($array);
$data = [
'code' => $array[0],
];
$bool = $this->api_admin->servicedomain_registrar_install($data);
$this->assertTrue($bool);
$array_after = $this->api_admin->servicedomain_registrar_get_available();
$this->assertFalse(count($array) == count($array_after));
}
public function testRegistrarGetList(): void
{
$array = $this->api_admin->servicedomain_registrar_get_list();
$this->assertIsArray($array);
$this->assertArrayHasKey('list', $array);
$list = $array['list'];
$this->assertIsArray($list);
if (count($list)) {
$item = $list[0];
$this->assertIsArray($item);
$this->assertArrayHasKey('id', $item);
$this->assertArrayHasKey('title', $item);
$this->assertArrayHasKey('label', $item);
$this->assertArrayHasKey('config', $item);
$this->assertIsArray($item['config']);
$this->assertArrayHasKey('form', $item);
$this->assertArrayHasKey('test_mode', $item);
}
}
public function testTldGetList(): void
{
$array = $this->api_admin->servicedomain_tld_get_list();
$this->assertIsArray($array);
$this->assertArrayHasKey('list', $array);
$list = $array['list'];
$this->assertIsArray($list);
if (count($list)) {
$item = $list[0];
$this->assertIsArray($item);
$this->assertArrayHasKey('tld', $item);
$this->assertArrayHasKey('price_registration', $item);
$this->assertArrayHasKey('price_renew', $item);
$this->assertArrayHasKey('price_transfer', $item);
$this->assertArrayHasKey('active', $item);
$this->assertArrayHasKey('allow_register', $item);
$this->assertArrayHasKey('allow_transfer', $item);
$this->assertArrayHasKey('min_years', $item);
$this->assertArrayHasKey('registrar', $item);
$registrar = $item['registrar'];
$this->assertIsArray($registrar);
$this->assertArrayHasKey('id', $registrar);
$this->assertArrayHasKey('title', $registrar);
}
}
protected function _callOnService($method, $data)
{
$m = 'serviceDomain_' . $method;
return $this->api_admin->{$m}($data);
}
}
@@ -1,26 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class Api_Admin_ServiceDownloadableTest extends BBDbApiTestCase
{
protected $_initialSeedFile = 'orders.xml';
public function testAdminServiceDownloadable(): void
{
$this->assertTrue(true);
/*
$endpoint = SYSTEM_URL . 'bb-api/rest.php/admin/servicedownloadable/upload';
$file_name = PATH_TESTS.'/fixtures/services.xml';
$params = array(
'id' => 7, // product id
'file_data' => '@'.realpath($file_name),
);
// @TODO Post the file
$this->assertEquals('{"result":true,"error":null}', $rsp);
*/
}
}
@@ -1,25 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class Api_Client_ServiceDownloadableTest extends BBDbApiTestCase
{
protected $_initialSeedFile = 'services.xml';
public function testServiceDownload(): void
{
$this->expectException(FOSSBilling\Exception::class);
$data = [
'order_id' => 1,
];
$bool = $this->_callOnService('send_file', $data);
$this->assertTrue($bool);
}
protected function _callOnService($method, $data)
{
$m = 'serviceDownloadable_' . $method;
return $this->api_client->{$m}($data);
}
}
@@ -1,181 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class Api_Admin_ServiceHostingTest extends BBDbApiTestCase
{
protected $_initialSeedFile = 'services.xml';
public function testAdminServiceHosting(): void
{
$array = $this->api_admin->servicehosting_manager_get_pairs();
$this->assertIsArray($array);
}
public function testAccountManagement(): void
{
$data = [
'order_id' => 8,
'sld' => 'example',
'tld' => '.com',
];
$bool = $this->api_admin->servicehosting_change_domain($data);
$this->assertTrue($bool);
$data['plan_id'] = 2;
$bool = $this->api_admin->servicehosting_change_plan($data);
$this->assertTrue($bool);
$data['username'] = 'new-username';
$bool = $this->api_admin->servicehosting_change_username($data);
$this->assertTrue($bool);
$data['ip'] = 'kitoks';
$bool = $this->api_admin->servicehosting_change_ip($data);
$this->assertTrue($bool);
$data['password'] = 'qwerty123';
$data['password_confirm'] = 'qwerty123';
$bool = $this->api_admin->servicehosting_change_password($data);
$this->assertTrue($bool);
$bool = $this->api_admin->servicehosting_sync($data);
$this->assertTrue($bool);
$data['username'] = 'username123';
$bool = $this->api_admin->servicehosting_update($data);
$this->assertTrue($bool);
}
public function testHp(): void
{
$array = $this->api_admin->servicehosting_hp_get_list();
$this->assertIsArray($array);
$array = $this->api_admin->servicehosting_hp_get_pairs();
$this->assertIsArray($array);
$data = [
'name' => 'test',
];
$id = $this->api_admin->servicehosting_hp_create($data);
$this->assertTrue(is_numeric($id));
$data['id'] = $id;
$array = $this->api_admin->servicehosting_hp_get($data);
$this->assertIsArray($array);
$data['quota'] = 12345;
$bool = $this->api_admin->servicehosting_hp_update($data);
$this->assertTrue($bool);
$bool = $this->api_admin->servicehosting_hp_delete($data);
$this->assertTrue($bool);
}
public function testServer(): void
{
$array = $this->api_admin->servicehosting_server_get_pairs();
$this->assertIsArray($array);
$data = [
'name' => 'test',
'ip' => '127.15.15.1',
'manager' => 'Custom',
];
$id = $this->api_admin->servicehosting_server_create($data);
$this->assertTrue(is_numeric($id));
$data['id'] = $id;
$array = $this->api_admin->servicehosting_server_get($data);
$this->assertIsArray($array);
$bool = $this->api_admin->servicehosting_server_test_connection($data);
$this->assertTrue($bool);
$data['quota'] = 12345;
$bool = $this->api_admin->servicehosting_server_update($data);
$this->assertTrue($bool);
$bool = $this->api_admin->servicehosting_server_delete($data);
$this->assertTrue($bool);
}
public function testServerIps(): void
{
$data = [
'id' => 1,
];
$array = $this->api_admin->servicehosting_server_get($data);
$this->assertIsArray($array);
$this->assertIsArray($array['assigned_ips']);
$data['assigned_ips'] = '127.85.81.156' . PHP_EOL . '189.156.45.78' . PHP_EOL;
$bool = $this->api_admin->servicehosting_server_update($data);
$this->assertTrue($bool);
$array = $this->api_admin->servicehosting_server_get($data);
$this->assertIsArray($array['assigned_ips']);
$this->assertEquals(2, count($array['assigned_ips']));
}
public function testServicehostingServerGetList(): void
{
$array = $this->api_admin->servicehosting_server_get_list([]);
$this->assertIsArray($array);
$this->assertArrayHasKey('list', $array);
$list = $array['list'];
$this->assertIsArray($list);
if (count($list)) {
$item = $list[0];
$this->assertIsArray($item);
$this->assertArrayHasKey('name', $item);
$this->assertArrayHasKey('hostname', $item);
$this->assertArrayHasKey('ip', $item);
$this->assertArrayHasKey('ns1', $item);
$this->assertArrayHasKey('ns2', $item);
$this->assertArrayHasKey('ns3', $item);
$this->assertArrayHasKey('ns4', $item);
$this->assertArrayHasKey('cpanel_url', $item);
$this->assertArrayHasKey('reseller_cpanel_url', $item);
$this->assertArrayHasKey('id', $item);
$this->assertArrayHasKey('active', $item);
$this->assertArrayHasKey('secure', $item);
$this->assertArrayHasKey('assigned_ips', $item);
$this->assertIsArray($item['assigned_ips']);
$this->assertArrayHasKey('status_url', $item);
$this->assertArrayHasKey('max_accounts', $item);
$this->assertArrayHasKey('manager', $item);
$this->assertArrayHasKey('username', $item);
$this->assertArrayHasKey('password', $item);
$this->assertArrayHasKey('accesshash', $item);
$this->assertArrayHasKey('port', $item);
$this->assertArrayHasKey('created_at', $item);
$this->assertArrayHasKey('updated_at', $item);
}
}
public function testServicehostingHpGetList(): void
{
$array = $this->api_admin->servicehosting_hp_get_list([]);
$this->assertIsArray($array);
$this->assertArrayHasKey('list', $array);
$list = $array['list'];
$this->assertIsArray($list);
$item = $list[0];
$this->assertIsArray($item);
$this->assertArrayHasKey('id', $item);
$this->assertArrayHasKey('name', $item);
$this->assertArrayHasKey('bandwidth', $item);
$this->assertArrayHasKey('quota', $item);
$this->assertArrayHasKey('max_ftp', $item);
$this->assertArrayHasKey('max_sql', $item);
$this->assertArrayHasKey('max_pop', $item);
$this->assertArrayHasKey('max_sub', $item);
$this->assertArrayHasKey('max_park', $item);
$this->assertArrayHasKey('max_addon', $item);
$this->assertArrayHasKey('config', $item);
$this->assertArrayHasKey('created_at', $item);
$this->assertArrayHasKey('updated_at', $item);
}
}
@@ -1,57 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class Api_Client_ServiceHostingTest extends BBDbApiTestCase
{
protected $_initialSeedFile = 'services.xml';
public function testLists(): void
{
$array = $this->api_client->servicehosting_hp_get_pairs();
$this->assertIsArray($array);
}
public static function orders()
{
return [
[5],
[6],
];
}
#[PHPUnit\Framework\Attributes\DataProvider('orders')]
public function testServiceHosting($id): void
{
$this->api_admin->order_renew(['id' => $id]);
$data = [
'order_id' => $id,
'password' => 'test',
'password_confirm' => 'test',
];
$bool = $this->_callOnService('change_password', $data);
$this->assertTrue($bool);
$data = [
'order_id' => $id,
'username' => 'John',
];
$bool = $this->_callOnService('change_username', $data);
$this->assertTrue($bool);
$data = [
'order_id' => $id,
'sld' => 'mynewdomain',
'tld' => '.com',
];
$bool = $this->_callOnService('change_domain', $data);
$this->assertTrue($bool);
}
protected function _callOnService($method, $data)
{
$m = 'serviceHosting_' . $method;
return $this->api_client->{$m}($data);
}
}
@@ -1,27 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class Api_Admin_ServiceLicenseTest extends BBDbApiTestCase
{
protected $_initialSeedFile = 'services.xml';
public function testAdminServiceLicense(): void
{
$array = $this->api_admin->servicelicense_plugin_get_pairs();
$this->assertIsArray($array);
$data = [
'order_id' => 2,
'validate_ip' => 0,
'validate_host' => 0,
'validate_version' => 0,
'validate_path' => 0,
'versions' => '1' . PHP_EOL . '2',
];
$bool = $this->api_admin->servicelicense_update($data);
$this->assertTrue($bool);
$service = $this->api_admin->order_service(['id' => 2]);
$this->assertEquals(2, count($service['versions']));
}
}
@@ -1,27 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class Api_Client_ServiceLicenseTest extends BBDbApiTestCase
{
protected $_initialSeedFile = 'services.xml';
public function testServiceLicense(): void
{
$id = 2;
$service = $this->api_client->order_service(['id' => $id]);
$data = [
'order_id' => $id,
];
$bool = $this->_callOnService('reset', $data);
$this->assertTrue($bool);
}
protected function _callOnService($method, $data)
{
$m = 'serviceLicense_' . $method;
return $this->api_client->{$m}($data);
}
}
@@ -1,48 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class Api_Guest_ServiceLicenseTest extends BBDbApiTestCase
{
protected $_initialSeedFile = 'licensing-server.xml';
public static function variations()
{
return [
[[
'fail' => '',
'legacy' => 1,
], false],
[[
'license' => 'BOX-NOT-EXISTS',
'host' => 'tests.com',
'path' => __DIR__,
'version' => '0.0.2',
'legacy' => 1,
], false],
[[
'license' => 'no_validation',
'host' => 'tests.com',
'path' => __DIR__,
'version' => '0.0.2',
'legacy' => 1,
], false],
[[
'license' => 'valid',
'host' => 'www.tests.com',
'path' => __DIR__,
'version' => '0.0.2',
'legacy' => 1,
], true],
];
}
#[PHPUnit\Framework\Attributes\DataProvider('variations')]
public function testGuestServiceLicense($data, $valid): void
{
$result = $this->api_guest->servicelicense_check($data);
$this->assertEquals($valid, $result['valid']);
}
}
@@ -1,244 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class Box_Mod_Servicelicense_ServerTest extends BBDbApiTestCase
{
protected $_initialSeedFile = 'servicelicense.xml';
public static function variations()
{
return [
// array(array(
// 'fail' => '',
// ), false),
[[
'license' => 'BOX-NOT-EXISTS',
'host' => 'tests.com',
'path' => __DIR__,
'version' => '0.0.2',
], false, false],
[[
'license' => 'no_validation',
'host' => 'tests.com',
'path' => __DIR__,
'version' => '0.0.2',
], false, false],
[[
'license' => 'valid',
'host' => 'www.tests.com',
'path' => __DIR__,
'version' => '0.0.2',
], true, true],
];
}
#[PHPUnit\Framework\Attributes\DataProvider('variations')]
public function testLicenseServer($data, $valid, $validation): void
{
$service = $this->getMockBuilder(Box\Mod\Servicelicense\Service::class)->getMock();
$service->expects($this->any())
->method('isLicenseActive')
->willReturn(true);
if ($validation) {
$service->expects($this->atLeastOnce())
->method('isValidIp')
->willReturn(true);
$service->expects($this->atLeastOnce())
->method('isValidHost')
->willReturn(true);
$service->expects($this->atLeastOnce())
->method('isValidVersion')
->willReturn(true);
$service->expects($this->atLeastOnce())
->method('isValidPath')
->willReturn(true);
}
$di = new Pimple\Container();
$di['db'] = $this->di['db'];
$di['logger'] = new Box_Log();
$di['mod'] = $di->protect(fn () => new Box_Mod('servicelicense'));
$di['mod_service'] = $di->protect(fn () => $service);
$server = new Box\Mod\Servicelicense\Server($di['logger']);
$server->setDi($di);
$result = $server->handle_deprecated(json_encode($data));
$this->assertEquals($valid, $result['valid'], print_r($result, 1));
}
public function testLicenseServerProcessProvicer()
{
$this->assertTrue(true);
return [
[[
'license' => 'validation_fail',
'host' => 'tests.com',
'path' => __DIR__,
'version' => '0.0.2',
], false],
[[
'license' => 'valid',
'host' => 'www.tests.com',
'path' => __DIR__,
'version' => '0.0.2',
], true],
];
}
public function testLicenseServerProcess(): void
{
$data = [
'license' => 'valid',
'host' => 'tests.com',
'path' => __DIR__,
'version' => '0.0.2',
];
$valid = true;
$service = $this->getMockBuilder(Box\Mod\Servicelicense\Service::class)->getMock();
$service->expects($this->any())
->method('isLicenseActive')
->willReturn(true);
$service->expects($this->atLeastOnce())
->method('isValidIp')
->willReturn(true);
$service->expects($this->atLeastOnce())
->method('isValidHost')
->willReturn(true);
$service->expects($this->atLeastOnce())
->method('isValidVersion')
->willReturn(true);
$service->expects($this->atLeastOnce())
->method('isValidPath')
->willReturn(true);
$di = new Pimple\Container();
$di['db'] = $this->di['db'];
$di['logger'] = $this->di['logger'];
$di['mod'] = $di->protect(fn () => new Box_Mod('servicelicense'));
$di['mod_service'] = $di->protect(fn () => $service);
$server = new Box\Mod\Servicelicense\Server($this->di['logger']);
$server->setDi($di);
$result = $server->process(json_encode($data));
$this->assertEquals($valid, $result['valid'], print_r($result, 1));
}
/**
* @expectedException \LogicException
*/
public function testLicenseServerProcessNotFound(): void
{
$data = [
'license' => 'non_existing',
'host' => 'tests.com',
'path' => __DIR__,
'version' => '0.0.2',
];
$valid = true;
$service = $this->getMockBuilder(Box\Mod\Servicelicense\Service::class)->getMock();
$service->expects($this->never())
->method('isLicenseActive')
->willReturn(true);
$service->expects($this->never())
->method('isValidIp')
->willReturn(true);
$service->expects($this->never())
->method('isValidHost')
->willReturn(true);
$service->expects($this->never())
->method('isValidVersion')
->willReturn(true);
$service->expects($this->never())
->method('isValidPath')
->willReturn(true);
$di = new Pimple\Container();
$di['db'] = $this->di['db'];
$di['logger'] = $this->di['logger'];
$di['mod'] = $di->protect(fn () => new Box_Mod('servicelicense'));
$di['mod_service'] = $di->protect(fn () => $service);
$server = new Box\Mod\Servicelicense\Server($this->di['logger']);
$server->setDi($di);
$result = $server->process(json_encode($data));
$this->assertEquals($valid, $result['valid'], print_r($result, 1));
}
public function testLicenseServerProcessValidationFailProvider()
{
$this->assertTrue(true);
return [
[false, false, false, false, false, [
$this->atLeastOnce(), $this->never(), $this->never(), $this->never(), $this->never(),
]],
[true, false, false, false, false, [
$this->atLeastOnce(), $this->atLeastOnce(), $this->never(), $this->never(), $this->never(),
]],
[true, true, false, false, false, [
$this->atLeastOnce(), $this->atLeastOnce(), $this->atLeastOnce(), $this->never(), $this->never(),
]],
[true, true, true, false, false, [
$this->atLeastOnce(), $this->atLeastOnce(), $this->atLeastOnce(), $this->atLeastOnce(), $this->never(),
]],
[true, true, true, true, false, [
$this->atLeastOnce(), $this->atLeastOnce(), $this->atLeastOnce(), $this->atLeastOnce(), $this->atLeastOnce(),
]],
];
}
/**
* @expectedException \LogicException
*/
#[PHPUnit\Framework\Attributes\DataProvider('testLicenseServerProcessValidationFailProvider')]
public function testLicenseServerProcessValidationFail($isActive, $validIp, $validHost, $validVersion, $validPath, $called): void
{
$data = [
'license' => 'valid',
'host' => 'tests.com',
'path' => __DIR__,
'version' => '0.0.2',
];
$valid = true;
$service = $this->getMockBuilder(Box\Mod\Servicelicense\Service::class)->getMock();
$service->expects($called[0])
->method('isLicenseActive')
->willReturn($isActive);
$service->expects($called[1])
->method('isValidIp')
->willReturn($validIp);
$service->expects($called[2])
->method('isValidHost')
->willReturn($validHost);
$service->expects($called[3])
->method('isValidVersion')
->willReturn($validVersion);
$service->expects($called[4])
->method('isValidPath')
->willReturn($validPath);
$di = new Pimple\Container();
$di['db'] = $this->di['db'];
$di['logger'] = $this->di['logger'];
$di['mod'] = $di->protect(fn () => new Box_Mod('servicelicense'));
$di['mod_service'] = $di->protect(fn () => $service);
$server = new Box\Mod\Servicelicense\Server($this->di['logger']);
$server->setDi($di);
$result = $server->process(json_encode($data));
$this->assertEquals($valid, $result['valid'], print_r($result, 1));
}
}
@@ -1,19 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class Box_Mod_Spamchecker_ServiceTest extends BBDbApiTestCase
{
protected $_initialSeedFile = 'mod_spamchecker.xml';
public function testOnAfterClientSignUp(): void
{
$parameters = [
'ip' => '127.0.0.1',
];
$event = new Box_Event(null, 'any', $parameters, $this->api_admin);
$event->setDi($this->di);
$object = new Box\Mod\Spamchecker\Service();
$object->onBeforeClientSignUp($event);
}
}
@@ -1,184 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class Api_Admin_StaffTest extends BBDbApiTestCase
{
protected $_initialSeedFile = 'admins.xml';
public function testStaff(): void
{
$array = $this->api_admin->staff_get_list(['status' => 'active']);
$this->assertIsArray($array);
$data = [
'admin_group_id' => 1,
'email' => random_int(5, 8_787_878) . '_test@admin.com',
'password' => 'dem2123123AAo',
'name' => 'John Doe',
'signature' => 'this is test sig',
'status' => 'active',
];
$id = $this->api_admin->staff_create($data);
$this->assertIsInt($id);
$staffModel = $this->di['db']->load('Admin', $id);
$this->assertNotEquals($data['password'], $staffModel->pass);
$data['id'] = $id;
$array = $this->api_admin->staff_get($data);
$this->assertIsArray($array);
$data['id'] = $id;
$data['email'] = 'new@email.com';
$bool = $this->api_admin->staff_update($data);
$this->assertTrue($bool);
$data['password'] = 'new123123';
$data['password_confirm'] = 'new123123';
$bool = $this->api_admin->staff_change_password($data);
$this->assertTrue($bool);
$staffModel = $this->di['db']->load('Admin', $id);
$this->assertNotEquals($data['password'], $staffModel->pass);
$bool = $this->api_admin->staff_delete($data);
$this->assertTrue($bool);
$staffModel = $this->di['db']->load('Admin', $id);
$this->isNull();
}
public function testChangePasswordException(): void
{
$this->expectException(FOSSBilling\Exception::class);
$data = [
'id' => 1,
'password' => 'new123123',
'password_confirm' => 'wrong_confirmation',
];
$data['password'] = 'new123123';
$data['password_confirm'] = 'wrong_confirmation';
$bool = $this->api_admin->staff_change_password($data);
$this->assertTrue($bool);
}
public function testPermissions(): void
{
$data = [
'id' => 1,
];
$array = $this->api_admin->staff_permissions_get($data);
$this->assertIsArray($array);
$perms = [];
$perms['activity'] = 1;
$data = [
'id' => 1,
'permissions' => $perms,
];
$bool = $this->api_admin->staff_permissions_update($data);
$this->assertTrue($bool);
$array = $this->api_admin->staff_permissions_get($data);
$this->assertIsArray($array);
$this->assertEquals($perms, $array);
}
public function testGroups(): void
{
$data = [
'name' => 'Support',
];
$id = $this->api_admin->staff_group_create($data);
$this->assertTrue(is_numeric($id));
$data = [
'id' => $id,
'name' => 'Staff',
];
$bool = $this->api_admin->staff_group_update($data);
$this->assertTrue($bool);
$array = $this->api_admin->staff_group_get_list($data);
$this->assertIsArray($array);
$array = $this->api_admin->staff_group_get_pairs($data);
$this->assertIsArray($array);
$array = $this->api_admin->staff_group_get($data);
$this->assertIsArray($array);
$bool = $this->api_admin->staff_group_delete($data);
$this->assertTrue($bool);
}
public function testHistory(): void
{
$array = $this->api_admin->staff_login_history_get_list();
$this->assertIsArray($array);
$data = [
'id' => 1,
];
$array = $this->api_admin->staff_login_history_get($data);
$this->assertIsArray($array);
$bool = $this->api_admin->staff_login_history_delete($data);
$this->assertTrue($bool);
}
public function testStaffActivityHistoryList(): void
{
$array = $this->api_admin->staff_login_history_get_list(['status' => 'active']);
$this->assertIsArray($array);
$this->assertArrayHasKey('list', $array);
$list = $array['list'];
$this->assertIsArray($list);
if (count($list)) {
$item = $list[0];
$this->assertIsArray($item);
$this->assertArrayHasKey('id', $item);
$this->assertArrayHasKey('ip', $item);
$this->assertArrayHasKey('created_at', $item);
$this->assertArrayHasKey('staff', $item);
$staff = $item['staff'];
$this->assertIsArray($staff);
$this->assertArrayHasKey('id', $staff);
$this->assertArrayHasKey('name', $staff);
$this->assertArrayHasKey('email', $staff);
}
}
public function testStaffGroupGetList(): void
{
$array = $this->api_admin->staff_group_get_list([]);
$this->assertIsArray($array);
$this->assertArrayHasKey('list', $array);
$list = $array['list'];
$this->assertIsArray($list);
$item = $list[0];
$this->assertArrayHasKey('id', $item);
$this->assertArrayHasKey('name', $item);
$this->assertArrayHasKey('created_at', $item);
$this->assertArrayHasKey('updated_at', $item);
}
public function testBatchDelete(): void
{
$array = $this->api_admin->staff_login_history_get_list([]);
foreach ($array['list'] as $value) {
$ids[] = $value['id'];
}
$result = $this->api_admin->staff_batch_delete_logs(['ids' => $ids]);
$array = $this->api_admin->staff_login_history_get_list([]);
$this->assertEquals(0, count($array['list']));
$this->assertTrue($result);
}
}
@@ -1,42 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class Api_Guest_StaffTest extends BBDbApiTestCase
{
protected $_initialSeedFile = 'admins.xml';
public function testCreate(): void
{
$data = [
'email' => 'admin@fossbilling.org',
'password' => 'adminPa55word',
];
$this->api_admin->staff_delete(['id' => 1]);
$this->api_guest->staff_create($data);
}
public function testCreateException(): void
{
try {
$this->api_guest->staff_create();
$this->fail('Should not allow create admin account if one already exists');
} catch (Exception $e) {
$this->assertEquals(55, $e->getCode());
}
}
public function testLogin(): void
{
$data = [
'email' => 'admin@fossbilling.org',
'password' => 'demo',
];
$array = $this->api_guest->staff_login($data);
$this->assertIsArray($array);
$this->assertIsArray($this->session->get('admin'));
$bool = $this->api_admin->staff_profile_logout($data);
$this->assertObjectNotHasProperty('admin', $this->session);
}
}
@@ -1,17 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class Box_Mod_Staff_ServiceTest extends ApiTestCase
{
public function testEvents(): void
{
$params = [
'id' => 1,
];
$event = $this->_bb_event = new Box_Event(null, 'name', $params, $this->api_admin, $this->api_guest);
$event->setDi($this->di);
$service = new Box\Mod\Staff\Service();
$bool = $service->onAfterClientSignUp($event);
$this->assertTrue($bool);
}
}
@@ -1,55 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class Api_Admin_StatsTest extends BBDbApiTestCase
{
protected $_initialSeedFile = 'orders.xml';
public function testSummary(): void
{
$array = $this->api_admin->stats_get_summary();
$this->assertIsArray($array);
$array = $this->api_admin->stats_get_summary_income();
$this->assertIsArray($array);
$array = $this->api_admin->stats_get_orders_statuses();
$this->assertIsArray($array);
$array = $this->api_admin->stats_get_income_vs_refunds();
$this->assertIsArray($array);
$array = $this->api_admin->stats_get_product_summary();
$this->assertIsArray($array);
$array = $this->api_admin->stats_get_product_sales();
$this->assertIsArray($array);
$array = $this->api_admin->stats_client_countries();
$this->assertIsArray($array);
$array = $this->api_admin->stats_sales_countries();
$this->assertIsArray($array);
}
public function testGraphs(): void
{
$array = $this->api_admin->stats_get_orders();
$this->assertIsArray($array);
$array = $this->api_admin->stats_get_clients();
$this->assertIsArray($array);
$array = $this->api_admin->stats_get_invoices();
$this->assertIsArray($array);
$array = $this->api_admin->stats_get_refunds();
$this->assertIsArray($array);
$array = $this->api_admin->stats_get_income();
$this->assertIsArray($array);
$array = $this->api_admin->stats_get_tickets();
$this->assertIsArray($array);
}
}
@@ -1,433 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class Api_Admin_SupportTest extends BBDbApiTestCase
{
protected $_initialSeedFile = 'mod_support.xml';
public function testCanned(): void
{
$array = $this->api_admin->support_canned_pairs();
$this->assertIsArray($array);
$array = $this->api_admin->support_canned_get_list();
$this->assertIsArray($array);
$list = $array['list'];
$this->assertIsArray($list);
$item = $list[0];
$this->assertArrayHasKey('category', $item);
$data = [
'id' => '1',
];
$data['category_id'] = 1;
$data['title'] = 'new canned title';
$id = $this->api_admin->support_canned_create($data);
$this->assertTrue(is_numeric($id));
$array = $this->api_admin->support_canned_get($data);
$this->assertIsArray($array);
$data['id'] = $id;
$data['title'] = 'new title';
$bool = $this->api_admin->support_canned_update($data);
$this->assertTrue($bool);
$bool = $this->api_admin->support_canned_delete($data);
$this->assertTrue($bool);
}
public function testCannedCategory(): void
{
$array = $this->api_admin->support_canned_category_pairs();
$this->assertIsArray($array);
$data = [
'id' => '1',
];
$array = $this->api_admin->support_canned_category_get($data);
$this->assertIsArray($array);
$data['title'] = 'new cat title';
$id = $this->api_admin->support_canned_category_create($data);
$this->assertTrue(is_numeric($id));
$data['id'] = $id;
$data['title'] = 'new title';
$bool = $this->api_admin->support_canned_category_update($data);
$this->assertTrue($bool);
$bool = $this->api_admin->support_canned_category_delete($data);
$this->assertTrue($bool);
}
public function testPublicTickets(): void
{
$array = $this->api_admin->support_public_ticket_get_statuses();
$this->assertIsArray($array);
$array = $this->api_admin->support_public_ticket_get_list();
$this->assertIsArray($array);
$list = $array['list'];
$this->assertIsArray($list);
$bool = $this->api_admin->support_batch_public_ticket_auto_close();
$this->assertTrue($bool);
$data = [
'name' => 'This is me',
'email' => 'email@email.com',
'subject' => 'subject',
'message' => 'Message',
];
$id = $this->api_admin->support_public_ticket_create($data);
$this->assertTrue(is_numeric($id));
$data['id'] = $id;
$array = $this->api_admin->support_public_ticket_get($data);
$this->assertIsArray($array);
$data['subject'] = 'new subject';
$data['status'] = 'closed';
$bool = $this->api_admin->support_public_ticket_update($data);
$this->assertTrue($bool);
$data['content'] = 'new message';
$id = $this->api_admin->support_public_ticket_reply($data);
$this->assertTrue(is_numeric($id));
$id = $this->api_admin->support_public_ticket_reply($data);
$this->assertTrue(is_numeric($id));
$bool = $this->api_admin->support_public_ticket_close($data);
$this->assertTrue($bool);
$bool = $this->api_admin->support_public_ticket_delete($data);
$this->assertTrue($bool);
}
public function testSupport(): void
{
$bool = $this->api_admin->support_batch_ticket_auto_close();
$this->assertTrue($bool);
$array = $this->api_admin->support_ticket_get_statuses([]);
$this->assertIsArray($array);
$data = [
'client_id' => 1,
'support_helpdesk_id' => 1,
'subject' => 'this is subject',
'content' => 'this is content',
];
$id = $this->api_admin->support_ticket_create($data);
$this->assertTrue(is_numeric($id));
$data['id'] = $id;
$array = $this->api_admin->support_ticket_get($data);
$this->assertIsArray($array);
$data['content'] = 'other message';
$mid = $this->api_admin->support_ticket_reply($data);
$this->assertTrue(is_numeric($mid));
$mid = $this->api_admin->support_ticket_reply($data);
$this->assertTrue(is_numeric($mid));
$bool = $this->api_admin->support_ticket_message_update(['id' => $mid, 'content' => 'This is a new content']);
$this->assertTrue($bool);
$bool = $this->api_admin->support_ticket_close($data);
$this->assertTrue($bool);
$data['subject'] = 'new subject';
$bool = $this->api_admin->support_ticket_update($data);
$this->assertTrue($bool);
$data = [
'ticket_id' => $id,
'note' => 'this is note',
];
$nid = $this->api_admin->support_note_create($data);
$this->assertTrue(is_numeric($id));
$data['id'] = $nid;
$bool = $this->api_admin->support_note_delete($data);
$this->assertTrue($bool);
$data['id'] = $id;
$bool = $this->api_admin->support_ticket_delete($data);
$this->assertTrue($bool);
}
public function testHelpdesk(): void
{
$data = [
'name' => 'title',
];
$id = $this->api_admin->support_helpdesk_create($data);
$this->assertTrue(is_numeric($id));
$data['id'] = $id;
$array = $this->api_admin->support_helpdesk_get($data);
$this->assertIsArray($array);
$data['name'] = 'new name';
$data['can_reopen'] = 1;
$data['close_after'] = 15;
$data['signature'] = 'new name';
$data['email'] = 'new@email.com';
$bool = $this->api_admin->support_helpdesk_update($data);
$this->assertTrue($bool);
$bool = $this->api_admin->support_helpdesk_delete($data);
$this->assertTrue($bool);
$array = $this->api_admin->support_helpdesk_get_list($data);
$this->assertIsArray($array);
$array = $this->api_admin->support_helpdesk_get_pairs($data);
$this->assertIsArray($array);
}
public function testExpirePublicTicket(): void
{
$data = [
'name' => 'Me',
'email' => 'test@test.com',
'subject' => 'test@test.com',
'message' => 'test@test.com',
];
$hash = $this->api_guest->support_ticket_create($data);
$ticket = $this->api_guest->support_ticket_get(['hash' => $hash]);
$model = $this->di['db']->load('SupportPTicket', $ticket['id']);
$model->status = 'on_hold';
$model->updated_at = date('Y-m-d H:i:s', strtotime('-50 days'));
$this->di['db']->store($model);
$bool = $this->api_admin->support_batch_public_ticket_auto_close();
$array = $this->api_admin->support_public_ticket_get_list(['status' => 'on_hold']);
$this->assertIsArray($array);
$this->assertTrue(empty($array['list']));
}
public function testTicketTask(): void
{
$data = [
'support_helpdesk_id' => 1,
'subject' => 'test@test.com',
'content' => 'test@test.com',
'rel_type' => 'order',
'rel_task' => 'cancel',
];
$id = $this->api_client->support_ticket_create($data);
$data = [
'id' => $id,
];
$bool = $this->api_admin->support_task_complete($data);
$this->assertTrue($bool);
}
public function testSupportTicketGetList(): void
{
$array = $this->api_admin->support_ticket_get_list([]);
$this->assertIsArray($array);
$this->assertArrayHasKey('list', $array);
$list = $array['list'];
$this->assertIsArray($list);
if (count($list)) {
$item = $list[0];
$this->assertIsArray($item);
$this->assertArrayHasKey('id', $item);
$this->assertArrayHasKey('support_helpdesk_id', $item);
$this->assertArrayHasKey('client_id', $item);
$this->assertArrayHasKey('priority', $item);
$this->assertArrayHasKey('subject', $item);
$this->assertArrayHasKey('status', $item);
$this->assertArrayHasKey('rel_type', $item);
$this->assertArrayHasKey('rel_task', $item);
$this->assertArrayHasKey('rel_new_value', $item);
$this->assertArrayHasKey('rel_status', $item);
$this->assertArrayHasKey('created_at', $item);
$this->assertArrayHasKey('updated_at', $item);
$this->assertArrayHasKey('replies', $item);
$this->assertArrayHasKey('first', $item);
$this->assertIsArray($item['first']);
$this->assertArrayHasKey('helpdesk', $item);
$helpdesk = $item['helpdesk'];
if (count($helpdesk)) {
$this->assertIsArray($helpdesk);
$this->assertArrayHasKey('id', $helpdesk);
$this->assertArrayHasKey('name', $helpdesk);
$this->assertArrayHasKey('email', $helpdesk);
$this->assertArrayHasKey('close_after', $helpdesk);
$this->assertArrayHasKey('can_reopen', $helpdesk);
$this->assertArrayHasKey('signature', $helpdesk);
$this->assertArrayHasKey('created_at', $helpdesk);
$this->assertArrayHasKey('updated_at', $helpdesk);
}
$this->assertArrayHasKey('messages', $item);
$this->assertIsArray($item['messages']);
$this->assertArrayHasKey('rel', $item);
$this->assertIsArray($item['rel']);
$this->assertArrayHasKey('client', $item);
$this->assertIsArray($item['client']);
}
}
public function testTicketBatchDelete(): void
{
$array = $this->api_admin->support_ticket_get_list([]);
foreach ($array['list'] as $value) {
$ids[] = $value['id'];
}
$result = $this->api_admin->support_batch_delete(['ids' => $ids]);
$array = $this->api_admin->support_ticket_get_list([]);
$this->assertEquals(0, count($array['list']));
$this->assertTrue($result);
}
public function testPublicTicketBatchDelete(): void
{
$array = $this->api_admin->support_public_ticket_get_list([]);
foreach ($array['list'] as $value) {
$ids[] = $value['id'];
}
$result = $this->api_admin->support_batch_delete_public(['ids' => $ids]);
$array = $this->api_admin->support_public_ticket_get_list([]);
$this->assertEquals(0, count($array['list']));
$this->assertTrue($result);
}
public function testKbCategory(): void
{
$array = $this->api_admin->support_kb_category_get_list();
$this->assertIsArray($array);
$array = $this->api_admin->support_kb_category_get_pairs();
$this->assertIsArray($array);
$data = [
'title' => 'test',
];
$id = $this->api_admin->support_kb_category_create($data);
$this->assertTrue(is_numeric($id));
$data = [
'id' => $id,
];
$array = $this->api_admin->support_kb_category_get($data);
$this->assertIsArray($array);
$data['id'] = $id;
$data['title'] = 'new';
$bool = $this->api_admin->support_kb_category_update($data);
$this->assertTrue($bool);
$bool = $this->api_admin->support_kb_category_delete($data);
$this->assertTrue($bool);
}
public function testKbArticle(): void
{
$array = $this->api_admin->support_kb_article_get_list();
$this->assertIsArray($array);
$data = [
'id' => 1,
];
$array = $this->api_admin->support_kb_article_get($data);
$this->assertIsArray($array);
$data = [
'kb_article_category_id' => 1,
'title' => 'test',
];
$id = $this->api_admin->support_kb_article_create($data);
$this->assertTrue(is_numeric($id));
$data['id'] = $id;
$data['title'] = 'new';
$bool = $this->api_admin->support_kb_article_update($data);
$this->assertTrue($bool);
$bool = $this->api_admin->support_kb_article_delete($data);
$this->assertTrue($bool);
}
public function testKbArticleGetList(): void
{
$array = $this->api_admin->support_kb_article_get_list();
$this->assertIsArray($array);
$this->assertArrayHasKey('list', $array);
$list = $array['list'];
$this->assertIsArray($list);
if (count($list)) {
$item = $list[0];
$this->assertArrayHasKey('id', $item);
$this->assertArrayHasKey('slug', $item);
$this->assertArrayHasKey('title', $item);
$this->assertArrayHasKey('views', $item);
$this->assertArrayHasKey('created_at', $item);
$this->assertArrayHasKey('updated_at', $item);
$this->assertArrayHasKey('category', $item);
$category = $item['category'];
$this->assertIsArray($category);
$this->assertArrayHasKey('id', $category);
$this->assertArrayHasKey('slug', $category);
$this->assertArrayHasKey('title', $category);
}
}
public function testKbCategoryGetList(): void
{
$array = $this->api_admin->support_kb_category_get_list();
$this->assertIsArray($array);
$this->assertArrayHasKey('list', $array);
$list = $array['list'];
$this->assertIsArray($list);
if (count($list)) {
$item = $list[0];
$this->assertArrayHasKey('id', $item);
$this->assertArrayHasKey('title', $item);
$this->assertArrayHasKey('description', $item);
$this->assertArrayHasKey('slug', $item);
$this->assertArrayHasKey('created_at', $item);
$this->assertArrayHasKey('updated_at', $item);
$this->assertArrayHasKey('articles', $item);
$articles = $item['articles'];
if (count($articles)) {
$article = $articles[0];
$this->assertIsArray($article);
$this->assertArrayHasKey('id', $article);
$this->assertArrayHasKey('slug', $article);
$this->assertArrayHasKey('title', $article);
}
}
}
}
@@ -1,121 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class Api_Client_SupportTest extends BBDbApiTestCase
{
protected $_initialSeedFile = 'mod_support.xml';
public function testAutoresponder(): void
{
// enable autoresponder
$config = [
'ext' => 'mod_support',
'autorespond_enable' => true,
'autorespond_message_id' => 1,
];
$bool = $this->api_admin->extension_config_save($config);
$this->assertTrue($bool);
$data = [
'subject' => 'Subject',
'content' => 'content',
'support_helpdesk_id' => '1',
];
$id = $this->api_client->support_ticket_create($data);
$this->assertIsInt($id);
$data = [
'id' => $id,
];
$array = $this->api_client->support_ticket_get($data);
$this->assertIsArray($array);
$this->assertEquals(2, count($array['messages']));
}
public function testSupport(): void
{
$array = $this->api_client->support_ticket_get_list();
$this->assertIsArray($array);
$array = $this->api_client->support_helpdesk_get_pairs();
$this->assertIsArray($array);
$data = [
'subject' => 'Subject',
'content' => 'content',
'support_helpdesk_id' => '1',
];
$id = $this->api_client->support_ticket_create($data);
$this->assertIsInt($id);
$data = [
'id' => $id,
];
$array = $this->api_client->support_ticket_get($data);
$this->assertIsArray($array);
$data = [
'id' => $id,
'content' => 'This is reply message',
];
$bool = $this->api_client->support_ticket_reply($data);
$this->assertTrue($bool);
$data = [
'id' => $id,
];
$bool = $this->api_client->support_ticket_close($data);
$this->assertTrue($bool);
}
public function testTicketTask(): void
{
$data = [
'subject' => 'Subject',
'content' => 'content',
'support_helpdesk_id' => '1',
'order_id' => '1',
'task' => 'cancel',
];
$id = $this->api_client->support_ticket_create($data);
$this->assertIsInt($id);
}
/**
* @expectedException \FOSSBilling\Exception
*/
public function testCanSubmitTicketException(): void
{
$this->api_admin->extension_config_save(
[
'ext' => 'mod_support',
'wait_hours' => 24,
]);
$data = [
'client_id' => 1,
'support_helpdesk_id' => 1,
'subject' => 'this is subject',
'content' => 'this is content',
];
$this->api_client->support_ticket_create($data);
$this->api_client->support_ticket_create($data); // should throw an exception because 1 ticket per 24 hours is allowed
}
public function testCanSubmitTicket(): void
{
$this->api_admin->extension_config_save(
[
'ext' => 'mod_support',
'wait_hours' => '',
]);
$data = [
'client_id' => 1,
'support_helpdesk_id' => 1,
'subject' => 'this is subject',
'content' => 'this is content',
];
$this->api_client->support_ticket_create($data);
$this->api_client->support_ticket_create($data); // should not throw an exception as delay time is not set
}
}
@@ -1,124 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class Api_Guest_SupportTest extends ApiTestCase
{
public function testContact(): void
{
$data = [
'name' => 'This is me',
'email' => 'email@email.com',
'subject' => 'subject',
'message' => 'Message',
];
$hash = $this->api_guest->support_ticket_create($data);
$this->assertIsString($hash);
$data = [
'hash' => $hash,
];
$array = $this->api_guest->support_ticket_get($data);
$this->assertIsArray($array);
$data = [
'hash' => $hash,
'message' => 'Hello',
];
$hash = $this->api_guest->support_ticket_reply($data);
$this->assertIsString($hash);
$bool = $this->api_guest->support_ticket_close($data);
$this->assertTrue($bool);
}
public function testKb(): void
{
$array = $this->api_guest->support_kb_article_get_list();
$this->assertIsArray($array);
$array = $this->api_guest->support_kb_category_get_list();
$this->assertIsArray($array);
$data = [
'id' => 1,
];
$array = $this->api_guest->support_kb_article_get($data);
$this->assertIsArray($array);
$data = [
'slug' => 'how-to-contact-support',
];
$array = $this->api_guest->support_kb_article_get($data);
$this->assertIsArray($array);
$data = [
'slug' => 'discuss-about-everything',
];
$array = $this->api_guest->support_kb_category_get($data);
$this->assertIsArray($array);
}
public function testKbCategoryGetPairs(): void
{
$array = $this->api_guest->support_kb_category_get_pairs();
$this->assertIsArray($array);
}
public function testKbArticleGetList(): void
{
$array = $this->api_guest->support_kb_article_get_list();
$this->assertIsArray($array);
$this->assertArrayHasKey('list', $array);
$list = $array['list'];
$this->assertIsArray($list);
if (count($list)) {
$item = $list[0];
$this->assertArrayHasKey('id', $item);
$this->assertArrayHasKey('id', $item);
$this->assertArrayHasKey('slug', $item);
$this->assertArrayHasKey('title', $item);
$this->assertArrayHasKey('views', $item);
$this->assertArrayHasKey('created_at', $item);
$this->assertArrayHasKey('updated_at', $item);
$this->assertArrayHasKey('category', $item);
$category = $item['category'];
$this->assertIsArray($category);
$this->assertArrayHasKey('id', $category);
$this->assertArrayHasKey('slug', $category);
$this->assertArrayHasKey('title', $category);
}
}
public function testKbCategoryGetList(): void
{
$array = $this->api_admin->support_kb_category_get_list();
$this->assertIsArray($array);
$this->assertArrayHasKey('list', $array);
$list = $array['list'];
$this->assertIsArray($list);
if (count($list)) {
$item = $list[0];
$this->assertArrayHasKey('id', $item);
$this->assertArrayHasKey('title', $item);
$this->assertArrayHasKey('description', $item);
$this->assertArrayHasKey('slug', $item);
$this->assertArrayHasKey('created_at', $item);
$this->assertArrayHasKey('updated_at', $item);
$this->assertArrayHasKey('articles', $item);
$articles = $item['articles'];
if (count($articles)) {
$article = $articles[0];
$this->assertIsArray($article);
$this->assertArrayHasKey('id', $article);
$this->assertArrayHasKey('slug', $article);
$this->assertArrayHasKey('title', $article);
}
}
}
}
@@ -1,112 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class Api_Admin_SystemTest extends BBDbApiTestCase
{
protected $_initialSeedFile = 'settings.xml';
public function testUpdateParams(): void
{
$data = [
'captcha_enabled' => '1',
'captcha_recaptcha_publickey' => 'pub',
'captcha_recaptcha_privatekey' => 'priv',
];
$bool = $this->api_admin->system_update_params($data);
$array = $this->api_admin->system_get_params();
$this->assertEquals('1', $array['captcha_enabled']);
$this->assertEquals('priv', $array['captcha_recaptcha_privatekey']);
$this->assertEquals('pub', $array['captcha_recaptcha_publickey']);
}
public function testFiles(): void
{
$bool = $this->api_admin->system_template_exists();
$this->assertFalse($bool);
$bool = $this->api_admin->system_template_exists(['file' => 'non_existing_template.html.twig']);
$this->assertFalse($bool);
$bool = $this->api_admin->system_template_exists(['file' => 'mod_index_dashboard.html.twig']);
$this->assertTrue($bool);
}
public function testRender(): void
{
$vars = [
'_tpl' => '{{ now|date("Y") }}',
];
$string = $this->api_admin->system_string_render($vars);
$this->assertEquals(date('Y'), $string);
// test guest API in template
$vars = [
'_tpl' => '{{ guest.system_states | json_encode }}',
];
$string = $this->api_admin->system_string_render($vars);
$json = html_entity_decode($string);
$result = json_decode($json ?? '', true);
$expected = $this->api_guest->system_states();
$this->assertEquals($expected, $result);
// test admin API in template
$vars = [
'_tpl' => '{{ admin.cron_info | json_encode }}',
];
$string = $this->api_admin->system_string_render($vars);
$json = html_entity_decode($string);
$result = json_decode($json ?? '', true);
$expected = $this->api_admin->cron_info();
$this->assertEquals($expected, $result);
// test client API in template
$vars = [
'_tpl' => '{{ client.order_get_list | json_encode }}',
'_client_id' => 1,
];
$string = $this->api_admin->system_string_render($vars);
$json = html_entity_decode($string);
$result = json_decode($json ?? '', true);
$expected = $this->api_client->order_get_list();
$this->assertEquals($expected, $result);
}
public function testPermissions(): void
{
$bool = $this->api_admin->system_is_allowed(['mod' => 'order']);
$this->assertTrue($bool);
$bool = $this->api_admin->system_is_allowed(['mod' => 'notexisting']);
$this->assertTrue($bool);
}
public function testInfos(): void
{
$array = $this->api_admin->system_env();
$this->assertIsArray($array);
$array = $this->api_admin->system_messages();
$this->assertIsArray($array);
$array = $this->api_admin->system_license_info();
$this->assertIsArray($array);
$array = $this->api_admin->system_get_params();
$this->assertIsArray($array);
$string = $this->api_admin->system_param(['key' => 'db_version']);
$this->assertEquals('2', '2');
}
public function testRenderDate(): void
{
$result = date($this->di['config']['locale_date_format']);
$data = [
'id' => 1,
'_tpl' => '{{ now|date("Y-m-d")|format_date }}',
];
$string = $this->api_admin->email_template_render($data);
$this->assertEquals($result, $string);
}
}
@@ -1,68 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class Api_Guest_SystemTest extends BBDbApiTestCase
{
protected $_initialSeedFile = 'settings.xml';
public function testPhoneCodes(): void
{
$array = $this->api_guest->system_phone_codes();
$this->assertIsArray($array);
$str = $this->api_guest->system_phone_codes(['country' => 'US']);
$this->assertEquals('1', $str);
foreach ($this->api_guest->system_countries() as $code => $name) {
$this->api_guest->system_phone_codes(['country' => $code]);
}
}
public function testCompany(): void
{
$array = $this->api_guest->system_countries();
$this->assertIsArray($array);
$array = $this->api_guest->system_countries_eunion();
$this->assertIsArray($array);
$array = $this->api_guest->system_states();
$this->assertIsArray($array);
$array = $this->api_guest->system_company();
$this->assertIsArray($array);
}
public function testFiles(): void
{
$bool = $this->api_guest->system_template_exists();
$this->assertFalse($bool);
$bool = $this->api_guest->system_template_exists(['file' => 'non_existing_template.html.twig']);
$this->assertFalse($bool);
$bool = $this->api_guest->system_template_exists(['file' => 'mod_index_dashboard.html.twig']);
$this->assertTrue($bool);
}
public function testSystem(): void
{
$string = $this->api_guest->system_version();
$this->assertIsString($string);
$array = $this->api_guest->system_company();
$this->assertIsArray($array);
$string = $this->api_guest->system_param(['key' => 'phpunit']);
$this->assertIsString($string);
$array = $this->api_guest->system_countries();
$this->assertIsArray($array);
$array = $this->api_guest->system_periods();
$this->assertIsArray($array);
$string = $this->api_guest->system_locale();
$this->assertIsString($string);
}
}
@@ -1,41 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class Api_Admin_ThemeTest extends BBDbApiTestCase
{
protected $_initialSeedFile = 'mod_theme.xml';
public function testLists(): void
{
$code = 'boxbilling';
$array = $this->api_admin->theme_get(['code' => $code]);
$this->assertIsArray($array);
$this->assertEquals($array['code'], $code);
$array = $this->api_admin->theme_get_list();
$this->assertIsArray($array);
$bool = $this->api_admin->theme_select(['code' => 'boxbilling']);
$this->assertTrue($bool);
$array = $this->api_admin->theme_get_list(['type' => 'admin']);
$this->assertIsArray($array);
}
/**
* @expectedException \FOSSBilling\Exception
*/
public function testThemeNotFound(): void
{
$this->api_admin->theme_get(['code' => 'non-existing-theme']);
}
public function testPresets(): void
{
$bool = $this->api_admin->theme_preset_select(['code' => 'boxbilling', 'preset' => 'Default']);
$this->assertTrue($bool);
$bool = $this->api_admin->theme_preset_delete(['code' => 'boxbilling', 'preset' => 'Default']);
$this->assertTrue($bool);
}
}
@@ -1,35 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class Mode_ThemeTest extends PHPUnit\Framework\TestCase
{
private Box\Mod\Theme\Model\Theme $model;
public function setup(): void
{
$this->model = new Box\Mod\Theme\Model\Theme('boxbilling');
}
public function testTypes(): void
{
$theme1 = new Box\Mod\Theme\Model\Theme('boxbilling');
$this->assertFalse($theme1->isAdminAreaTheme());
$theme2 = new Box\Mod\Theme\Model\Theme('admin_default');
$this->assertTrue($theme2->isAdminAreaTheme());
}
public function testFolder(): void
{
$this->model->isAssetsPathWritable();
$this->model->getUrl();
$this->model->getPath();
$this->model->getPathConfig();
$this->model->getPathAssets();
$page = $this->model->getSettingsPageHtml();
$this->assertContains('input', $page);
$files = $this->model->getUploadedAssets();
}
}
@@ -1,92 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class Box_Mod_Theme_ServiceTest extends BBDbApiTestCase
{
public function testgetCurrentThemePreset(): void
{
$service = new Box\Mod\Theme\Service();
$service->setDi($this->di);
$themeModel = $service->getTheme('huraga');
$result = $service->getCurrentThemePreset($themeModel);
$this->assertIsString($result);
$this->assertNotEmpty($result);
}
public function testgetThemePresets(): void
{
$service = new Box\Mod\Theme\Service();
$service->setDi($this->di);
$themeModel = $service->getTheme('huraga');
$result = $service->getThemePresets($themeModel);
$this->assertIsArray($result);
$this->assertNotEmpty($result);
}
public function testgetThemeSettings(): void
{
$service = new Box\Mod\Theme\Service();
$service->setDi($this->di);
$themeModel = $service->getTheme('huraga');
$result = $service->getThemeSettings($themeModel);
$this->assertIsArray($result);
}
public function testupdateSettings(): void
{
$service = new Box\Mod\Theme\Service();
$service->setDi($this->di);
$themeModel = $service->getTheme('huraga');
$preset = 'phpUnit';
$params = [];
$result = $service->updateSettings($themeModel, $preset, $params);
$this->assertTrue($result);
}
public function testregenerateThemeSettingsDataFile(): void
{
$service = new Box\Mod\Theme\Service();
$service->setDi($this->di);
$themeModel = $service->getTheme('huraga');
$result = $service->regenerateThemeSettingsDataFile($themeModel);
$this->assertTrue($result);
}
public function testregenerateThemeCssAndJsFiles(): void
{
$service = new Box\Mod\Theme\Service();
$service->setDi($this->di);
$themeModel = $service->getTheme('huraga');
$preset = 'phpUnit';
$result = $service->regenerateThemeCssAndJsFiles($themeModel, $preset, $this->di['api_admin']);
$this->assertTrue($result);
}
public function testgetCurrentAdminAreaTheme(): void
{
$service = new Box\Mod\Theme\Service();
$service->setDi($this->di);
$result = $service->getCurrentAdminAreaTheme();
$this->assertIsArray($result);
$this->assertEquals('admin_default', $result['code']);
$this->assertEquals(SYSTEM_URL . 'themes/admin_default/', $result['url']);
}
public function testgetCurrentClientAreaTheme(): void
{
$service = new Box\Mod\Theme\Service();
$service->setDi($this->di);
$result = $service->getCurrentClientAreaTheme();
$this->assertInstanceOf('\\' . Box\Mod\Theme\Model\Theme::class, $result);
$this->assertEquals('huraga', $result->getName());
}
}
@@ -1,12 +0,0 @@
<?php
#[PHPUnit\Framework\Attributes\Group('Core')]
class Box_ExceptionTest extends PHPUnit\Framework\TestCase
{
public function testException(): void
{
$e = new Box_Exception('php :msg', [':msg' => 'unit'], 789);
$this->assertEquals('php unit', $e->getMessage());
$this->assertEquals(789, $e->getCode());
}
}
@@ -394,7 +394,7 @@ class GuestTest extends \BBTestCase
$client = new Guest();
$client->setDi($di);
// Expect a Box_Exception to be thrown with a specific message
// Expect a FOSSBilling\Exception to be thrown with a specific message
$this->expectException(\FOSSBilling\Exception::class);
$this->expectExceptionMessage('The link has expired or you have already reset your password.');
$client->update_password($data);