add configuration to select helpdesk for paid support module

This commit is contained in:
Vaidas Lungis committed 2015-02-13 13:55:54 +02:00
1 parent 1a8859fe56
commit c8abd00a3c
4 files changed
+348 -11

No files matched your search

+30 -2
View File
@@ -54,8 +54,9 @@ class Service implements InjectionAwareInterface
$paidSupportService = $di['mod_service']('Paidsupport');
$paidSupportService->setDi($di);
$paidSupportService->enoughInBalanceToOpenTicket($client);
if ($paidSupportService->hasHelpdeskPaidSupport($params['support_helpdesk_id'])) {
$paidSupportService->enoughInBalanceToOpenTicket($client);
}
return true;
}
@@ -73,6 +74,10 @@ class Service implements InjectionAwareInterface
$paidSupportService = $di['mod_service']('Paidsupport');
$paidSupportService->setDi($di);
if (!$paidSupportService->hasHelpdeskPaidSupport($supportTicket->support_helpdesk_id)) {
return true;
}
$paidSupportService->enoughInBalanceToOpenTicket($client);
$clientBalanceService = $di['mod_service']('Client', 'Balance');
@@ -110,6 +115,12 @@ class Service implements InjectionAwareInterface
return isset($config['error_msg']) ? $config['error_msg'] : 'Configure paid support module!';
}
public function getPaidHelpdeskConfig()
{
$config = $this->di['mod_config']('Paidsupport');
return isset($config['helpdesk']) ? $config['helpdesk'] : array();
}
public function enoughInBalanceToOpenTicket(\Model_Client $client)
{
$clientBalanceService = $this->di['mod_service']('Client', 'Balance');
@@ -122,5 +133,22 @@ class Service implements InjectionAwareInterface
return true;
}
/**
* @param $id
* @return bool
*/
public function hasHelpdeskPaidSupport($id)
{
$helpdeskConfig = $this->getPaidHelpdeskConfig();
if (empty ($helpdeskConfig)) {
return true;
}
if (isset($helpdeskConfig[$id]) && $helpdeskConfig[$id] == 1){
return true;
}
return false;
}
}
@@ -35,6 +35,38 @@
</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>
{% for id, title in admin.support_helpdesk_get_pairs %}
<tr {% if loop.first %}class="noborder"{% endif %}>
<td style="width:5%">
<input type="hidden" name="helpdesk[{{id}}]" value="0">
<input type="checkbox" name="helpdesk[{{id}}]" value="1" id="helpdesk_{{ id }}" {% if params.helpdesk[id] == 1 %}checked="checked"{% endif %}/>
</td>
<td><label for="helpdesk_{{ id }}">{{title}}</label></td>
<td style="width:5%"><a class="bb-button btn14" href="{{ '/support/helpdesk'|alink }}/{{id}}"><img src="images/icons/dark/pencil.png" alt=""></a></td>
</tr>
{% else %}
<tr>
<td colspan="3">{% trans 'The list is empty' %}</td>
</tr>
{% endfor %}
</tbody>
<tfoot>
<tr>
<td colspan="3">
<a href="{{ 'extension/settings/support'|alink }}#tab-new-helpdesk" title="" class="btnIconLeft mr10 mt5"><img src="images/icons/dark/settings2.png" alt="" class="icon"><span>{% trans 'Create new helpdesk' %}</span></a>
</td>
</tr>
</tfoot>
</table>
<div class="fix"></div>
</div>
<input type="hidden" name="ext" value="mod_paidsupport" />
+193 -1
View File
@@ -160,7 +160,7 @@ class ServiceTest extends \PHPUnit_Framework_TestCase {
$this->assertTrue($result);
}
public function testonBeforeClientOpenTicket()
public function testonBeforeClientOpenTicket_PaidSupportForHelpdeskEnabled()
{
$di = new \Box_Di();
@@ -175,6 +175,9 @@ class ServiceTest extends \PHPUnit_Framework_TestCase {
$di['db'] = $dbMock;
$paidSupportMock = $this->getMockBuilder('\Box\Mod\Paidsupport\Service')->getMock();
$paidSupportMock->expects($this->atLeastOnce())
->method('hasHelpdeskPaidSupport')
->willReturn(true);
$paidSupportMock->expects($this->atLeastOnce())
->method('enoughInBalanceToOpenTicket')
->with($clientModel);
@@ -186,6 +189,51 @@ class ServiceTest extends \PHPUnit_Framework_TestCase {
$params = array(
'client_id' => 1,
'support_helpdesk_id' => 1,
);
$boxEventMock = $this->getMockBuilder('\Box_Event')->disableOriginalConstructor()->getMock();
$boxEventMock->expects($this->atLeastOnce())
->method('getDi')
->willReturn($di);
$boxEventMock->expects($this->atLeastOnce())
->method('getParameters')
->willReturn($params);
$result = $this->service->onBeforeClientOpenTicket($boxEventMock);
$this->assertTrue($result);
}
public function testonBeforeClientOpenTicket_PaidSupportForHelpdeskDisabled()
{
$di = new \Box_Di();
$clientModel = new \Model_Client();
$clientModel->loadBean(new \RedBeanPHP\OODBBean());
$dbMock = $this->getMockBuilder('\Box_Database')->getMock();
$dbMock->expects($this->atLeastOnce())
->method('load')
->with('Client')
->willReturn($clientModel);
$di['db'] = $dbMock;
$paidSupportMock = $this->getMockBuilder('\Box\Mod\Paidsupport\Service')->getMock();
$paidSupportMock->expects($this->atLeastOnce())
->method('hasHelpdeskPaidSupport')
->willReturn(false);
$paidSupportMock->expects($this->never())
->method('enoughInBalanceToOpenTicket')
->with($clientModel);
$di['mod_service'] = $di->protect(function ($serviceName) use($paidSupportMock){
if ($serviceName == 'Paidsupport'){
return $paidSupportMock;
}
});
$params = array(
'client_id' => 1,
'support_helpdesk_id' => 1,
);
$boxEventMock = $this->getMockBuilder('\Box_Event')->disableOriginalConstructor()->getMock();
@@ -288,6 +336,9 @@ class ServiceTest extends \PHPUnit_Framework_TestCase {
$di['db'] = $dbMock;
$paidSupportMock = $this->getMockBuilder('\Box\Mod\Paidsupport\Service')->getMock();
$paidSupportMock->expects($this->atLeastOnce())
->method('hasHelpdeskPaidSupport')
->willReturn(true);
$paidSupportMock->expects($this->atLeastOnce())
->method('enoughInBalanceToOpenTicket')
->with($clientModel);
@@ -307,6 +358,7 @@ class ServiceTest extends \PHPUnit_Framework_TestCase {
$params = array(
'id' => 1,
'support_helpdesk_id' => 1,
);
$boxEventMock = $this->getMockBuilder('\Box_Event')->disableOriginalConstructor()->getMock();
@@ -320,5 +372,145 @@ class ServiceTest extends \PHPUnit_Framework_TestCase {
$result = $this->service->onAfterClientOpenTicket($boxEventMock);
$this->assertTrue($result);
}
public function testonAfterClientOpenTicket_PaidSupportDisabledForHelpdesk()
{
$di = new \Box_Di();
$supportTicketModel = new \Model_SupportTicket();
$supportTicketModel->loadBean(new \RedBeanPHP\OODBBean());
$clientModel = new \Model_Client();
$clientModel->loadBean(new \RedBeanPHP\OODBBean());
$dbMock = $this->getMockBuilder('\Box_Database')->getMock();
$dbMock->expects($this->atLeastOnce())
->method('load')
->withConsecutive(array('SupportTicket'), array('Client'))
->willReturnOnConsecutiveCalls($supportTicketModel, $clientModel);
$di['db'] = $dbMock;
$paidSupportMock = $this->getMockBuilder('\Box\Mod\Paidsupport\Service')->getMock();
$paidSupportMock->expects($this->atLeastOnce())
->method('hasHelpdeskPaidSupport')
->willReturn(false);
$paidSupportMock->expects($this->never())
->method('enoughInBalanceToOpenTicket')
->with($clientModel);
$di['mod_service'] = $di->protect(function ($serviceName, $sub ='') use($paidSupportMock){
if ($serviceName == 'Paidsupport'){
return $paidSupportMock;
}
});
$params = array(
'id' => 1,
'support_helpdesk_id' => 1,
);
$boxEventMock = $this->getMockBuilder('\Box_Event')->disableOriginalConstructor()->getMock();
$boxEventMock->expects($this->atLeastOnce())
->method('getDi')
->willReturn($di);
$boxEventMock->expects($this->atLeastOnce())
->method('getParameters')
->willReturn($params);
$result = $this->service->onAfterClientOpenTicket($boxEventMock);
$this->assertTrue($result);
}
public function testgetPaidHelpdeskConfig()
{
$di = new \Box_Di();
$helpdeskId = 2;
$helpdeskConfig = array(
$helpdeskId => 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->getPaidHelpdeskConfig();
$this->assertInternalType('array', $result);
$this->assertNotEmpty($result);
$this->assertEquals($helpdeskConfig, $result);
}
public function testgetPaidHelpdeskConfig_IsNotSet()
{
$di = new \Box_Di();
$paidSupportConfig = array();
$di['mod_config'] = $di->protect(function($serviceName) use ($paidSupportConfig){
if ($serviceName== 'Paidsupport'){
return $paidSupportConfig;
}
});
$this->service->setDi($di);
$result = $this->service->getPaidHelpdeskConfig();
$this->assertInternalType('array', $result);
$this->assertEmpty($result);
}
public function testhasHelpdeskPaidSupport_turnedOff()
{
$helpdeskId = 1;
$helpdeskConfig = array(
$helpdeskId => 0
);
$paidSupportServiceMock = $this->getMockBuilder('\Box\Mod\Paidsupport\Service')
->setMethods(array('getPaidHelpdeskConfig'))
->getMock();
$paidSupportServiceMock->expects($this->atLeastOnce())
->method('getPaidHelpdeskConfig')
->willReturn($helpdeskConfig);
$result = $paidSupportServiceMock->hasHelpdeskPaidSupport($helpdeskId);
$this->assertFalse($result);
}
public function testhasHelpdeskPaidSupport_turnedOn()
{
$helpdeskId = 1;
$helpdeskConfig = array(
$helpdeskId => 1
);
$paidSupportServiceMock = $this->getMockBuilder('\Box\Mod\Paidsupport\Service')
->setMethods(array('getPaidHelpdeskConfig'))
->getMock();
$paidSupportServiceMock->expects($this->atLeastOnce())
->method('getPaidHelpdeskConfig')
->willReturn($helpdeskConfig);
$result = $paidSupportServiceMock->hasHelpdeskPaidSupport($helpdeskId);
$this->assertTrue($result);
}
public function testhasHelpdeskPaidSupport_ConfigNotConfigured()
{
$helpdeskId = 1;
$helpdeskConfig = array();
$paidSupportServiceMock = $this->getMockBuilder('\Box\Mod\Paidsupport\Service')
->setMethods(array('getPaidHelpdeskConfig'))
->getMock();
$paidSupportServiceMock->expects($this->atLeastOnce())
->method('getPaidHelpdeskConfig')
->willReturn($helpdeskConfig);
$result = $paidSupportServiceMock->hasHelpdeskPaidSupport($helpdeskId);
$this->assertTrue($result);
}
}
@@ -2,13 +2,24 @@
class Box_Mod_Paidsupport_ServiceTest extends ApiTestCase
{
public function testCreatePaidSupportTicket()
public function setup()
{
parent::setUp();
$data = array(
'id' => 'paidsupport',
'type' => 'mod',
);
$this->api_admin->extension_activate($data);
$hookService = $this->di['mod_service']('hook');
$hookService->batchConnect('paidsupport');
}
public function testCreatePaidSupportTicket()
{
$ticketPrice = 5.5;
$balance = $this->api_client->client_balance_get_total();
@@ -18,7 +29,6 @@ class Box_Mod_Paidsupport_ServiceTest extends ApiTestCase
}
$beforeBalance = $this->api_client->client_balance_get_total();
$data = array(
'ext' => 'mod_paidsupport',
'ticket_price' => $ticketPrice,
@@ -46,14 +56,89 @@ class Box_Mod_Paidsupport_ServiceTest extends ApiTestCase
$this->assertEquals(-$ticketPrice, $clientBalanceModel->amount);
}
public function testCreatePaidSupportTicket_HelpdeskhasPaidSupport()
{
$ticketPrice = 5.5;
$balance = $this->api_client->client_balance_get_total();
if ($balance < $ticketPrice){
$this->api_admin->client_balance_add_funds(array('id' => 1, 'amount' => $ticketPrice, 'description' => 'Added from PHPUnit'));
}
$beforeBalance = $this->api_client->client_balance_get_total();
$helpdeskId = 1;
$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' => $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 testCreatePaidSupportTicket_HelpdesHasNotPaidSupport()
{
$ticketPrice = 5.5;
$balance = $this->api_client->client_balance_get_total();
if ($balance <= $ticketPrice){
$this->api_admin->client_balance_add_funds(array('id' => 1, 'amount' => $ticketPrice, 'description' => 'Added from PHPUnit'));
}
$beforeBalance = $this->api_client->client_balance_get_total();
$helpdeskId = 1;
$data = array(
'ext' => 'mod_paidsupport',
'ticket_price' => $ticketPrice,
'error_msg' => 'Insufficient amount in balance',
'helpdesk' => array($helpdeskId => 0),
);
$this->api_admin->extension_config_save($data);
$data = array(
'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 testCreatePaidSupportTicket_insufficientFunds()
{
$data = array(
'id' => 'paidsupport',
'type' => 'mod',
);
$this->api_admin->extension_activate($data);
$balance = $this->api_client->client_balance_get_total();
$ticketPrice = 10 + $balance;