From bb80d2f93cca41f4ceb725a2302f9c860183626e Mon Sep 17 00:00:00 2001 From: "deb.monish" Date: Mon, 24 Jul 2017 17:39:52 +0530 Subject: [PATCH] additional fix --- CRM/Contribute/BAO/ManagePremiums.php | 15 ++++------ CRM/Contribute/Form/ManagePremiums.php | 8 ++--- tests/phpunit/CRM/Utils/StringTest.php | 41 +++++++------------------- 3 files changed, 18 insertions(+), 46 deletions(-) diff --git a/CRM/Contribute/BAO/ManagePremiums.php b/CRM/Contribute/BAO/ManagePremiums.php index 40de859a9a..4b00a93734 100644 --- a/CRM/Contribute/BAO/ManagePremiums.php +++ b/CRM/Contribute/BAO/ManagePremiums.php @@ -96,19 +96,14 @@ class CRM_Contribute_BAO_ManagePremiums extends CRM_Contribute_DAO_Product { * @return CRM_Contribute_DAO_Product */ public static function add(&$params, &$ids) { - $defaults = array( + $params = array_merge(array( 'id' => CRM_Utils_Array::value('premium', $ids), - 'image' => '', - 'thumbnail' => '', - 'is_active' => FALSE, + 'image' => CRM_Utils_String::simplifyURL(CRM_Utils_Array::value('image', $params, ''), TRUE), + 'thumbnail' => CRM_Utils_String::simplifyURL(CRM_Utils_Array::value('thumbnail', $params, ''), TRUE), + 'is_active' => 0, 'is_deductible' => FALSE, 'currency' => CRM_Core_Config::singleton()->defaultCurrency, - ); - $params = array_merge($defaults, $params); - - // Use local URLs for images when possible - $params['image'] = CRM_Utils_String::simplifyURL($params['image'], TRUE); - $params['thumbnail'] = CRM_Utils_String::simplifyURL($params['thumbnail'], TRUE); + ), $params); // Save and return $premium = new CRM_Contribute_DAO_Product(); diff --git a/CRM/Contribute/Form/ManagePremiums.php b/CRM/Contribute/Form/ManagePremiums.php index 437505d834..2cb9c4fa6c 100644 --- a/CRM/Contribute/Form/ManagePremiums.php +++ b/CRM/Contribute/Form/ManagePremiums.php @@ -209,16 +209,14 @@ class CRM_Contribute_Form_ManagePremiums extends CRM_Contribute_Form { public static function formRule($params, $files) { // If choosing to upload an image, then an image must be provided - if ( - isset($params['imageOption']) && - $params['imageOption'] == 'image' && - empty($files['uploadFile']['name']) + if (CRM_Utils_Array::value('imageOption', $params['imageOption']) == 'image' + && empty($files['uploadFile']['name']) ) { $errors['uploadFile'] = ts('A file must be selected'); } // If choosing to use image URLs, then both URLs must be present - if (isset($params['imageOption']) && $params['imageOption'] == 'thumbnail') { + if (CRM_Utils_Array::value('imageOption', $params['imageOption']) == 'thumbnail') { if (!$params['imageUrl']) { $errors['imageUrl'] = ts('Image URL is Required'); } diff --git a/tests/phpunit/CRM/Utils/StringTest.php b/tests/phpunit/CRM/Utils/StringTest.php index 98a674e7c2..ba04a54f31 100644 --- a/tests/phpunit/CRM/Utils/StringTest.php +++ b/tests/phpunit/CRM/Utils/StringTest.php @@ -250,7 +250,6 @@ class CRM_Utils_StringTest extends CiviUnitTestCase { * @return array */ public function simplifyURLProvider() { - $config = CRM_Core_Config::singleton(); $urlParts = parse_url($config->userFrameworkBaseURL); $localDomain = $urlParts['host']; @@ -262,51 +261,37 @@ class CRM_Utils_StringTest extends CiviUnitTestCase { } return array( - - 'prototypical example' => - array( + 'prototypical example' => array( "https://$localDomain/sites/default/files/coffee-mug.jpg", FALSE, '/sites/default/files/coffee-mug.jpg', ), - - 'external domain with https' => - array( + 'external domain with https' => array( "https://$externalDomain/sites/default/files/coffee-mug.jpg", FALSE, "https://$externalDomain/sites/default/files/coffee-mug.jpg", ), - - 'external domain with http forced to https' => - array( + 'external domain with http forced to https' => array( "http://$externalDomain/sites/default/files/coffee-mug.jpg", TRUE, "https://$externalDomain/sites/default/files/coffee-mug.jpg", ), - - 'external domain with http not forced' => - array( + 'external domain with http not forced' => array( "http://$externalDomain/sites/default/files/coffee-mug.jpg", FALSE, "http://$externalDomain/sites/default/files/coffee-mug.jpg", ), - - 'local URL' => - array( + 'local URL' => array( "/sites/default/files/coffee-mug.jpg", FALSE, "/sites/default/files/coffee-mug.jpg", ), - - 'local URL without a forward slash' => - array( + 'local URL without a forward slash' => array( "sites/default/files/coffee-mug.jpg", FALSE, "/sites/default/files/coffee-mug.jpg", ), - - 'empty input' => - array( + 'empty input' => array( '', FALSE, '', @@ -334,27 +319,21 @@ class CRM_Utils_StringTest extends CiviUnitTestCase { */ public function parseURLProvider() { return array( - - "prototypical example" => - array( + "prototypical example" => array( "https://example.com:8000/foo/bar/?id=1#fragment", array( 'host+port' => "example.com:8000", 'path+query' => "/foo/bar/?id=1", ), ), - - "empty" => - array( + "empty" => array( "", array( 'host+port' => "", 'path+query' => "", ), ), - - "path only" => - array( + "path only" => array( "/foo/bar/image.png", array( 'host+port' => "", -- 2.25.1