From c6306ea759cca901d5a46d5b469f98c3d0bde167 Mon Sep 17 00:00:00 2001 From: Vaidas Lungis Date: Mon, 23 Feb 2015 10:55:55 +0200 Subject: [PATCH 1/3] helpdesk must be selected to apply paid support. --- src/bb-modules/Paidsupport/Service.php | 4 --- .../html_admin/mod_paidsupport_settings.phtml | 1 - tests/bb-modules/Paidsupport/ServiceTest.php | 26 ++++++++++++++++++- .../mod_paidsupport/ServiceTest.php | 7 ++++- 4 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/bb-modules/Paidsupport/Service.php b/src/bb-modules/Paidsupport/Service.php index e230a9047..71c48a5e4 100644 --- a/src/bb-modules/Paidsupport/Service.php +++ b/src/bb-modules/Paidsupport/Service.php @@ -141,10 +141,6 @@ class Service implements InjectionAwareInterface { $helpdeskConfig = $this->getPaidHelpdeskConfig(); - if (empty ($helpdeskConfig)) { - return true; - } - if (isset($helpdeskConfig[$id]) && $helpdeskConfig[$id] == 1){ return true; } 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..01c6e302f 100644 --- a/src/bb-modules/Paidsupport/html_admin/mod_paidsupport_settings.phtml +++ b/src/bb-modules/Paidsupport/html_admin/mod_paidsupport_settings.phtml @@ -38,7 +38,6 @@
{% trans 'Set paid supoprt for helpdesks: ' %}
-

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

diff --git a/tests/bb-modules/Paidsupport/ServiceTest.php b/tests/bb-modules/Paidsupport/ServiceTest.php index 45ee272dd..803836520 100644 --- a/tests/bb-modules/Paidsupport/ServiceTest.php +++ b/tests/bb-modules/Paidsupport/ServiceTest.php @@ -510,7 +510,31 @@ class ServiceTest extends \PHPUnit_Framework_TestCase { ->willReturn($helpdeskConfig); $result = $paidSupportServiceMock->hasHelpdeskPaidSupport($helpdeskId); - $this->assertTrue($result); + $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); } } \ No newline at end of file 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); From 65698cdb333ad62dafe03bbff86939025f1c8a49 Mon Sep 17 00:00:00 2001 From: Vaidas Lungis Date: Mon, 23 Feb 2015 11:13:54 +0200 Subject: [PATCH 2/3] add uninstall() to remove extension config on uninstall --- src/bb-modules/Paidsupport/Service.php | 10 +++++ tests/bb-modules/Paidsupport/ServiceTest.php | 40 ++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/src/bb-modules/Paidsupport/Service.php b/src/bb-modules/Paidsupport/Service.php index 71c48a5e4..c1c0a3a9e 100644 --- a/src/bb-modules/Paidsupport/Service.php +++ b/src/bb-modules/Paidsupport/Service.php @@ -147,4 +147,14 @@ class Service implements InjectionAwareInterface 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; + } + } \ No newline at end of file diff --git a/tests/bb-modules/Paidsupport/ServiceTest.php b/tests/bb-modules/Paidsupport/ServiceTest.php index 803836520..79a056653 100644 --- a/tests/bb-modules/Paidsupport/ServiceTest.php +++ b/tests/bb-modules/Paidsupport/ServiceTest.php @@ -536,5 +536,45 @@ class ServiceTest extends \PHPUnit_Framework_TestCase { $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); + } } \ No newline at end of file From cfc77a111700cdbacea73bde0b0edd543607816e Mon Sep 17 00:00:00 2001 From: Vaidas Lungis Date: Mon, 23 Feb 2015 11:50:17 +0200 Subject: [PATCH 3/3] ticket price and error message are required fields save default error_msg value on install. fix #271 --- src/bb-modules/Paidsupport/Service.php | 14 ++++++++++++- .../html_admin/mod_paidsupport_settings.phtml | 4 ++-- src/bb-modules/Paidsupport/manifest.json | 2 +- tests/bb-modules/Paidsupport/ServiceTest.php | 20 +++++++++++++++++++ 4 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/bb-modules/Paidsupport/Service.php b/src/bb-modules/Paidsupport/Service.php index c1c0a3a9e..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() @@ -157,4 +158,15 @@ class Service implements InjectionAwareInterface 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 01c6e302f..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,14 +24,14 @@
- +
- +
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 79a056653..3585f36e3 100644 --- a/tests/bb-modules/Paidsupport/ServiceTest.php +++ b/tests/bb-modules/Paidsupport/ServiceTest.php @@ -576,5 +576,25 @@ class ServiceTest extends \PHPUnit_Framework_TestCase { $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); + } } \ No newline at end of file