mirror of
https://github.com/FOSSBilling/FOSSBilling.git
synced 2026-11-22 21:03:01 +09:00
4.15.2
paidsupport module updates: - ticket price and error message configuration fields are required; - Set default values after extension install; - Delete extension config after uninstall; - Helpdesk must be selected to activate paid support. issue #271
This commit is contained in:
commit
73111ee594
5 files changed
+116
-10
No files matched your search
@@ -112,7 +112,8 @@ class Service implements InjectionAwareInterface
|
||||
public function getErrorMessage()
|
||||
{
|
||||
$config = $this->di['mod_config']('Paidsupport');
|
||||
return isset($config['error_msg']) ? $config['error_msg'] : 'Configure paid support module!';
|
||||
$errorMessage = isset($config['error_msg']) ? $config['error_msg'] : '';
|
||||
return strlen(trim($errorMessage)) > 0 ? $errorMessage : 'Configure paid support module!';
|
||||
}
|
||||
|
||||
public function getPaidHelpdeskConfig()
|
||||
@@ -141,14 +142,31 @@ class Service implements InjectionAwareInterface
|
||||
{
|
||||
$helpdeskConfig = $this->getPaidHelpdeskConfig();
|
||||
|
||||
if (empty ($helpdeskConfig)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (isset($helpdeskConfig[$id]) && $helpdeskConfig[$id] == 1){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function uninstall()
|
||||
{
|
||||
$model = $this->di['db']->findOne('ExtensionMeta', 'extension = :ext AND meta_key = :key',
|
||||
array(':ext'=>'mod_paidsupport', ':key'=>'config'));
|
||||
if ($model instanceof \Model_ExtensionMeta) {
|
||||
$this->di['db']->trash($model);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function install()
|
||||
{
|
||||
$extensionService = $this->di['mod_service']('Extension');
|
||||
$defaultConfig = array(
|
||||
'ext' => 'mod_paidsupport',
|
||||
'error_msg' => 'Insufficient funds'
|
||||
);
|
||||
$extensionService->setConfig($defaultConfig);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -24,21 +24,20 @@
|
||||
<div class="rowElem">
|
||||
<label>{% trans 'Ticket price:' %}</label>
|
||||
<div class="formRight">
|
||||
<input type="text" name="ticket_price" value="{{ params.ticket_price }}" />
|
||||
<input type="text" name="ticket_price" value="{{ params.ticket_price }}" required="required"/>
|
||||
</div>
|
||||
<div class="fix"></div>
|
||||
</div>
|
||||
<div class="rowElem">
|
||||
<label>{% trans 'Error message:' %}</label>
|
||||
<div class="formRight">
|
||||
<input type="text" name="error_msg" value="{{ params.error_msg }}" />
|
||||
<input type="text" name="error_msg" value="{{ params.error_msg }}" required="required" />
|
||||
</div>
|
||||
<div class="fix"></div>
|
||||
</div>
|
||||
<div class="tab_content nopadding" id="tab-addons">
|
||||
<div class="help">
|
||||
<h5>{% trans 'Set paid supoprt for helpdesks: ' %}</h5>
|
||||
<p>{% trans 'Paid support applied for all of them if nothing is selected' %}</p>
|
||||
</div>
|
||||
<table class="tableStatic wide">
|
||||
<tbody>
|
||||
|
||||
@@ -8,5 +8,5 @@
|
||||
"author": "BoxBilling",
|
||||
"author_url": "http://github.com/boxbilling/",
|
||||
"license": "GPL version 2 or later - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html",
|
||||
"version": "1.0.0"
|
||||
"version": "1.0.3"
|
||||
}
|
||||
@@ -510,6 +510,90 @@ class ServiceTest extends \PHPUnit_Framework_TestCase {
|
||||
->willReturn($helpdeskConfig);
|
||||
|
||||
$result = $paidSupportServiceMock->hasHelpdeskPaidSupport($helpdeskId);
|
||||
$this->assertFalse($result);
|
||||
}
|
||||
|
||||
public function testPaidSupportAppliedForAllHelpdesks_AllHelpdesksAreNotChecked()
|
||||
{
|
||||
$di = new \Box_Di();
|
||||
$helpdeskId = 2;
|
||||
$helpdeskId1 = 3;
|
||||
$helpdeskConfig = array(
|
||||
$helpdeskId => 0,
|
||||
$helpdeskId1 => 0
|
||||
);
|
||||
$paidSupportConfig = array(
|
||||
'helpdesk' => $helpdeskConfig,
|
||||
);
|
||||
|
||||
$di['mod_config'] = $di->protect(function($serviceName) use ($paidSupportConfig){
|
||||
if ($serviceName == 'Paidsupport'){
|
||||
return $paidSupportConfig;
|
||||
}
|
||||
});
|
||||
|
||||
$this->service->setDi($di);
|
||||
$result = $this->service->hasHelpdeskPaidSupport($helpdeskId);
|
||||
$this->assertFalse($result);
|
||||
}
|
||||
|
||||
public function testUninstall()
|
||||
{
|
||||
$di = new \Box_Di();
|
||||
|
||||
$dbMock = $this->getMockBuilder('\Box_Database')->getMock();
|
||||
$model = new \Model_ExtensionMeta();
|
||||
$dbMock->expects($this->atLeastOnce())
|
||||
->method('findOne')
|
||||
->with('ExtensionMeta')
|
||||
->willReturn($model);
|
||||
$dbMock->expects($this->atLeastOnce())
|
||||
->method('trash')
|
||||
->with($model);
|
||||
|
||||
$di['db'] = $dbMock;
|
||||
|
||||
$this->service->setDi($di);
|
||||
$result = $this->service->uninstall();
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
public function testUninstall_ConfigNotFound()
|
||||
{
|
||||
$di = new \Box_Di();
|
||||
|
||||
$dbMock = $this->getMockBuilder('\Box_Database')->getMock();
|
||||
$model = new \Model_ExtensionMeta();
|
||||
$dbMock->expects($this->atLeastOnce())
|
||||
->method('findOne')
|
||||
->with('ExtensionMeta');
|
||||
$dbMock->expects($this->never())
|
||||
->method('trash');
|
||||
|
||||
$di['db'] = $dbMock;
|
||||
|
||||
$this->service->setDi($di);
|
||||
$result = $this->service->uninstall();
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
public function testInstall()
|
||||
{
|
||||
$di = new \Box_Di();
|
||||
|
||||
$extensionServiceMock = $this->getMockBuilder('\Box\Mod\Extension\Service')->getMock();
|
||||
$extensionServiceMock->expects($this->atLeastOnce())
|
||||
->method('setConfig')
|
||||
->willReturn(true);
|
||||
|
||||
$di['mod_service'] = $di->protect(function ($serviceName) use ($extensionServiceMock){
|
||||
if ($serviceName == 'Extension'){
|
||||
return $extensionServiceMock;
|
||||
}
|
||||
});
|
||||
|
||||
$this->service->setDi($di);
|
||||
$result = $this->service->install();
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,18 +28,20 @@ class Box_Mod_Paidsupport_ServiceTest extends ApiTestCase
|
||||
$this->api_admin->client_balance_add_funds(array('id' => 1, 'amount' => $ticketPrice, 'description' => 'Added from PHPUnit'));
|
||||
}
|
||||
|
||||
$helpdeskId = 1;
|
||||
$beforeBalance = $this->api_client->client_balance_get_total();
|
||||
$data = array(
|
||||
'ext' => 'mod_paidsupport',
|
||||
'ticket_price' => $ticketPrice,
|
||||
'error_msg' => 'Insufficient amount in balance',
|
||||
'helpdesk' => array($helpdeskId => 1),
|
||||
);
|
||||
|
||||
$this->api_admin->extension_config_save($data);
|
||||
$data = array(
|
||||
'subject' => 'Subject',
|
||||
'content' => 'content',
|
||||
'support_helpdesk_id' => '1',
|
||||
'support_helpdesk_id' => $helpdeskId,
|
||||
|
||||
'order_id' => '1',
|
||||
'task' => 'cancel',
|
||||
@@ -145,10 +147,13 @@ class Box_Mod_Paidsupport_ServiceTest extends ApiTestCase
|
||||
|
||||
$errorMessage = 'Insufficient amount in balance';
|
||||
|
||||
$helpdeskId = 1;
|
||||
|
||||
$data = array(
|
||||
'ext' => 'mod_paidsupport',
|
||||
'ticket_price' => $ticketPrice,
|
||||
'error_msg' => $errorMessage,
|
||||
'helpdesk' => array($helpdeskId => 1),
|
||||
);
|
||||
|
||||
$this->api_admin->extension_config_save($data);
|
||||
|
||||
Reference in new issue
Block a user