diff --git a/src/bb-modules/Paidsupport/Service.php b/src/bb-modules/Paidsupport/Service.php index e230a9047..9c745c4a2 100644 --- a/src/bb-modules/Paidsupport/Service.php +++ b/src/bb-modules/Paidsupport/Service.php @@ -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; + } + } \ No newline at end of file diff --git a/src/bb-modules/Paidsupport/html_admin/mod_paidsupport_settings.phtml b/src/bb-modules/Paidsupport/html_admin/mod_paidsupport_settings.phtml index 186d0e66d..bf72c228f 100644 --- a/src/bb-modules/Paidsupport/html_admin/mod_paidsupport_settings.phtml +++ b/src/bb-modules/Paidsupport/html_admin/mod_paidsupport_settings.phtml @@ -24,21 +24,20 @@
- +
- +
{% trans 'Set paid supoprt for helpdesks: ' %}
-

{% trans 'Paid support applied for all of them if nothing is selected' %}

diff --git a/src/bb-modules/Paidsupport/manifest.json b/src/bb-modules/Paidsupport/manifest.json index d743d3069..461aa79ae 100644 --- a/src/bb-modules/Paidsupport/manifest.json +++ b/src/bb-modules/Paidsupport/manifest.json @@ -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" } \ No newline at end of file diff --git a/tests/bb-modules/Paidsupport/ServiceTest.php b/tests/bb-modules/Paidsupport/ServiceTest.php index 45ee272dd..3585f36e3 100644 --- a/tests/bb-modules/Paidsupport/ServiceTest.php +++ b/tests/bb-modules/Paidsupport/ServiceTest.php @@ -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); } } diff --git a/tests/integration/bb-modules/mod_paidsupport/ServiceTest.php b/tests/integration/bb-modules/mod_paidsupport/ServiceTest.php index 95a6e1dd1..668084582 100644 --- a/tests/integration/bb-modules/mod_paidsupport/ServiceTest.php +++ b/tests/integration/bb-modules/mod_paidsupport/ServiceTest.php @@ -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);