From 06c9be35158a4d2fd5d03f0c7a157c76f85f2f67 Mon Sep 17 00:00:00 2001 From: Lauren Schaefer Date: Mon, 2 Jul 2018 17:43:46 -0400 Subject: [PATCH] Fixes #65: Add custom endpoint to get Online Applications Campaign Remove entrypoint code and add tests Update Application Form to use REST endpoint --- .../Ext/EntryPointRegistry/getCampaign.php | 6 - .../base/api/OnlineApplicationsAPI.php | 87 +++++ .../help/GetOnlineApplicationsCampaignId.html | 35 ++ .../online_application_form/ApplyOnline.html | 366 +++++++++--------- .../ApplicationCampaignManager.php | 63 --- .../GetCampaignEntrypoint.php | 9 - .../base/api/OnlineApplicationsAPITest.php} | 18 +- 7 files changed, 316 insertions(+), 268 deletions(-) delete mode 100644 package/src/custom/Extension/application/Ext/EntryPointRegistry/getCampaign.php create mode 100644 package/src/custom/modules/Campaigns/clients/base/api/OnlineApplicationsAPI.php create mode 100644 package/src/custom/modules/Campaigns/clients/base/api/help/GetOnlineApplicationsCampaignId.html delete mode 100644 package/src/custom/src/application_campaign/ApplicationCampaignManager.php delete mode 100644 package/src/custom/src/application_campaign/GetCampaignEntrypoint.php rename package/src/custom/tests/School/unit-php/{src/application_campaign/ApplicationCampaignManagerTest.php => modules/Campaigns/clients/base/api/OnlineApplicationsAPITest.php} (77%) diff --git a/package/src/custom/Extension/application/Ext/EntryPointRegistry/getCampaign.php b/package/src/custom/Extension/application/Ext/EntryPointRegistry/getCampaign.php deleted file mode 100644 index d255696c..00000000 --- a/package/src/custom/Extension/application/Ext/EntryPointRegistry/getCampaign.php +++ /dev/null @@ -1,6 +0,0 @@ - 'custom/src/application_campaign/GetCampaignEntrypoint.php', - 'auth' => false -); diff --git a/package/src/custom/modules/Campaigns/clients/base/api/OnlineApplicationsAPI.php b/package/src/custom/modules/Campaigns/clients/base/api/OnlineApplicationsAPI.php new file mode 100644 index 00000000..e1e4a2be --- /dev/null +++ b/package/src/custom/modules/Campaigns/clients/base/api/OnlineApplicationsAPI.php @@ -0,0 +1,87 @@ + array( + + //request type + 'reqType' => 'GET', + + //set authentication + 'noLoginRequired' => true, + + //endpoint path + 'path' => array('Campaigns', 'getOnlineApplicationsCampaignId'), + + //method to call + 'method' => 'getOnlineApplicationsCampaignId', + + //short help string to be displayed in the help documentation + 'shortHelp' => 'Get the ID of the most recently updated Campaign with the name \'Online Applications\'', + + //long help to be displayed in the help documentation + 'longHelp' => 'custom/modules/Campaigns/clients/base/api/help/GetOnlineApplicationsCampaignId.html', + ), + ); + } + + /** + * Get the ID of the most recently updated Campaign with the name 'Online Applications' + * + * @return an array containing the ID of the most recently updated Campaign with the name 'Online Applications' + */ + public function getOnlineApplicationsCampaignId() + { + // Get the most recently updated Campaign with the name 'Online Applications' + $q = $this->getSugarQuery(); + $q->select(array('id', 'name')); + $q->from($this->getNewCampaignBean(), array('team_security' => false)); + $q->where()->equals('name', 'Online Applications'); + $q->orderBy('date_modified', 'desc'); + $q->limit(1); + + $results = $q->execute(); + + if(sizeof($results) != 1 || !$results[0]['id']){ + throw new \Exception("Unable to find ID for the Campaign named Online Applications"); + } + + return array('id' => $results[0]['id']); + } + + /** + * Get Sugar Query. + * This function exists so we can mock the SugarQuery in automated tests. + * + * @return \SugarQuery + */ + protected function getSugarQuery() + { + return new \SugarQuery(); + } + + /** + * Get a new Campaign Bean. + * This function exists so we can mock the Campaigns Bean in automated tests. + * + * @return null|\SugarBean + */ + protected function getNewCampaignBean() + { + return \BeanFactory::newBean('Campaigns'); + } + +} + +?> \ No newline at end of file diff --git a/package/src/custom/modules/Campaigns/clients/base/api/help/GetOnlineApplicationsCampaignId.html b/package/src/custom/modules/Campaigns/clients/base/api/help/GetOnlineApplicationsCampaignId.html new file mode 100644 index 00000000..339d3b39 --- /dev/null +++ b/package/src/custom/modules/Campaigns/clients/base/api/help/GetOnlineApplicationsCampaignId.html @@ -0,0 +1,35 @@ +

Overview

+ + A custom GET endpoint. Returns the ID of the most recently updated Campaign with the name 'Online Applications'. + + +

Result

+ + + + + + + + + + + + + + + +
NameTypeDescription
+ id + + String + + The ID of the most recently updated Campaign with the name 'Online Applications'. +
+ +

Output Example

+
+{
+    "id": "f56b6d18-52e1-11e8-a080-34363bc46900"
+}
+
diff --git a/package/src/custom/online_application_form/ApplyOnline.html b/package/src/custom/online_application_form/ApplyOnline.html index 118bbf1a..0ef7d092 100644 --- a/package/src/custom/online_application_form/ApplyOnline.html +++ b/package/src/custom/online_application_form/ApplyOnline.html @@ -52,223 +52,227 @@

-

-
- - -
- Professor M's School for Gifted Coders Logo -

Application for Admission

-
- -
-
-
-
- -
-
- -
+

+ + + +
+ Professor M's School for Gifted Coders Logo +

Application for Admission

+
+ +
+
+
+
+ +
+
+
+
-
-
-
- -
-
- -
+
+
+
+ +
+
+
-
-
-
-
-
- -
-
- -
+
+ +
+
+
+
+ +
+
+
+
-
-
-
-
- -
-
- -
+
+
+
+
+ +
+
+
+
-
-
-
-
- -
-
- -
+
+
+
+
+ +
+
+
+
-
-
-
- -
-
- -
+
+
+
+ +
+
+
+
-
-
-
- -
-
- -
+
+
+
+ +
+
+
+
-
-
-
- -
-
- -
+
+
+
+ +
+
+
-
-
-
-
-
- -
-
- -
+
+ +
+
+
+
+ +
+
+
+
-
-
-
- -
-
- -
+
+
+
+ +
+
+
+
-
-
-
- -
-
- -
+
+
+
+ +
+
+
-
-
-
-
-
- -
-
- -
+
+ +
+
+
+
+ +
+
+
-
-
- -
+
- - - - - - - -

+

+ +
+ + + + + + + + +

-

+ alert('Not a valid email address'); + } + } + if(document.getElementById('email2') && document.getElementById('email2').value.length >0) { + if(document.getElementById('email2').value.match(/^\w+(['\.\-\+]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/) == null){ + alert('Not a valid email address'); + } + } + } + // ]]> +

diff --git a/package/src/custom/src/application_campaign/ApplicationCampaignManager.php b/package/src/custom/src/application_campaign/ApplicationCampaignManager.php deleted file mode 100644 index cca759fd..00000000 --- a/package/src/custom/src/application_campaign/ApplicationCampaignManager.php +++ /dev/null @@ -1,63 +0,0 @@ -getSugarQuery(); - $q->select(array('id', 'name')); - $q->from($this->getNewCampaignBean(), array('team_security' => false)); - $q->where()->equals('name', 'Online Applications'); - $q->orderBy('date_modified', 'desc'); - $q->limit(1); - - $results = $q->execute(); - - if(sizeof($results) != 1 || !$results[0]['id']){ - throw new \Exception("Unable to find ID for the Campaign named Online Applications"); - } - return $results[0]['id']; - } - - /** - * Get Sugar Query. - * This function exists so we can mock the SugarQuery in automated tests. - * - * @return \SugarQuery - */ - protected function getSugarQuery() - { - return new \SugarQuery(); - } - - /** - * Get a new Campaign Bean. - * This function exists so we can mock the Campaigns Bean in automated tests. - * - * @return null|\SugarBean - */ - protected function getNewCampaignBean() - { - return \BeanFactory::newBean('Campaigns'); - } - -} diff --git a/package/src/custom/src/application_campaign/GetCampaignEntrypoint.php b/package/src/custom/src/application_campaign/GetCampaignEntrypoint.php deleted file mode 100644 index 121f1d62..00000000 --- a/package/src/custom/src/application_campaign/GetCampaignEntrypoint.php +++ /dev/null @@ -1,9 +0,0 @@ -getOnlineApplicationsCampaignId(); diff --git a/package/src/custom/tests/School/unit-php/src/application_campaign/ApplicationCampaignManagerTest.php b/package/src/custom/tests/School/unit-php/modules/Campaigns/clients/base/api/OnlineApplicationsAPITest.php similarity index 77% rename from package/src/custom/tests/School/unit-php/src/application_campaign/ApplicationCampaignManagerTest.php rename to package/src/custom/tests/School/unit-php/modules/Campaigns/clients/base/api/OnlineApplicationsAPITest.php index af6e5ce3..94e8be6a 100644 --- a/package/src/custom/tests/School/unit-php/src/application_campaign/ApplicationCampaignManagerTest.php +++ b/package/src/custom/tests/School/unit-php/modules/Campaigns/clients/base/api/OnlineApplicationsAPITest.php @@ -3,15 +3,15 @@ use Sugarcrm\SugarcrmTestsUnit\TestMockHelper; /** - * @coversDefaultClass \ApplicationCampaignManager + * @coversDefaultClass \OnlineApplicationsAPI */ -class ApplicationCampaignManagerTest extends \PHPUnit\Framework\TestCase +class OnlineApplicationsAPI extends \PHPUnit\Framework\TestCase { /** - * A partial mock of ApplicationCampaignManager + * A partial mock of OnlineApplicationsAPI */ - private $acm; + private $api; /** * @var a partial mock of a SugarQuery @@ -28,11 +28,11 @@ protected function setUp() $this->campaignBean = $this->createMock('SugarBean'); - $this->acm = TestMockHelper::createPartialMock($this, + $this->api = TestMockHelper::createPartialMock($this, '\\Sugarcrm\\Sugarcrm\\custom\\application_campaign\\ApplicationCampaignManager', ['getSugarQuery', 'getNewCampaignBean']); - $this->acm->method('getSugarQuery')->willReturn($this->sugarQuery); - $this->acm->method('getNewCampaignBean')->willReturn($this->campaignBean); + $this->api->method('getSugarQuery')->willReturn($this->sugarQuery); + $this->api->method('getNewCampaignBean')->willReturn($this->campaignBean); } /** @@ -51,7 +51,7 @@ public function testGetOnlineApplicationsCampaignIdWithResults() $this->sugarQuery->method('execute')->willReturn($this->queryResults); $this->sugarQuery->expects($this->once())->method('execute'); - $this->assertEquals($this->campaignId, $this->acm->getOnlineApplicationsCampaignId()); + $this->assertEquals($this->campaignId, $this->api->getOnlineApplicationsCampaignId()); } /** @@ -64,7 +64,7 @@ public function testGetOnlineApplicationsCampaignIdWithNoResults() $this->sugarQuery->expects($this->once())->method('execute'); $this->expectException(Exception::class, "Unable to find ID for the Campaign named Online Applications"); - $this->acm->getOnlineApplicationsCampaignId(); + $this->api->getOnlineApplicationsCampaignId(); } }