Skip to content

Commit

Permalink
additional fix
Browse files Browse the repository at this point in the history
  • Loading branch information
monishdeb committed Jul 24, 2017
1 parent e0d4afb commit bb80d2f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 46 deletions.
15 changes: 5 additions & 10 deletions CRM/Contribute/BAO/ManagePremiums.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,14 @@ public static function setIsActive($id, $is_active) {
* @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();
Expand Down
8 changes: 3 additions & 5 deletions CRM/Contribute/Form/ManagePremiums.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,16 +209,14 @@ public function buildQuickForm() {
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');
}
Expand Down
41 changes: 10 additions & 31 deletions tests/phpunit/CRM/Utils/StringTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ public function testSimplifyURL($imageURL, $forceHttps, $expected) {
* @return array
*/
public function simplifyURLProvider() {

$config = CRM_Core_Config::singleton();
$urlParts = parse_url($config->userFrameworkBaseURL);
$localDomain = $urlParts['host'];
Expand All @@ -262,51 +261,37 @@ public function simplifyURLProvider() {
}

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,
'',
Expand Down Expand Up @@ -334,27 +319,21 @@ public function testSimpleParseUrl($url, $expected) {
*/
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' => "",
Expand Down

0 comments on commit bb80d2f

Please sign in to comment.