Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
CiviCRM Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Development
CiviCRM Core
Commits
70e7eaed
Unverified
Commit
70e7eaed
authored
5 years ago
by
Eileen McNaughton
Committed by
GitHub
5 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #14601 from seamuslee001/dev_core_1067
#1067
Clean Money before creating Campaign record and add test
parents
608a3c7a
484627ca
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
CRM/Campaign/Form/Campaign.php
+28
-24
28 additions, 24 deletions
CRM/Campaign/Form/Campaign.php
tests/phpunit/CRM/Campaign/Form/CampaignTest.php
+63
-0
63 additions, 0 deletions
tests/phpunit/CRM/Campaign/Form/CampaignTest.php
with
91 additions
and
24 deletions
CRM/Campaign/Form/Campaign.php
+
28
−
24
View file @
70e7eaed
...
...
@@ -81,7 +81,7 @@ class CRM_Campaign_Form_Campaign extends CRM_Core_Form {
$this
->
assign
(
'context'
,
$this
->
_context
);
$this
->
_action
=
CRM_Utils_Request
::
retrieve
(
'action'
,
'String'
,
$this
);
$this
->
_campaignId
=
CRM_Utils_Request
::
retrieve
(
'id'
,
'Positive'
,
$this
);
$this
->
_campaignId
=
CRM_Utils_Request
::
retrieve
(
'id'
,
'Positive'
);
$title
=
NULL
;
if
(
$this
->
_action
&
CRM_Core_Action
::
UPDATE
)
{
...
...
@@ -186,6 +186,7 @@ class CRM_Campaign_Form_Campaign extends CRM_Core_Form {
//lets assign custom data type and subtype.
$this
->
assign
(
'customDataType'
,
'Campaign'
);
$this
->
assign
(
'entityID'
,
$this
->
_campaignId
);
$this
->
assign
(
'id'
,
$this
->
_campaignId
);
$this
->
assign
(
'customDataSubType'
,
CRM_Utils_Array
::
value
(
'campaign_type_id'
,
$this
->
_values
));
$attributes
=
CRM_Core_DAO
::
getAttribute
(
'CRM_Campaign_DAO_Campaign'
);
...
...
@@ -288,10 +289,9 @@ class CRM_Campaign_Form_Campaign extends CRM_Core_Form {
*/
public
function
postProcess
()
{
// store the submitted values in an array
$params
=
$this
->
controller
->
exportValues
(
$this
->
_name
);
$session
=
CRM_Core_Session
::
singleton
();
$groups
=
[];
$session
=
CRM_Core_Session
::
singleton
();
$params
=
$this
->
controller
->
exportValues
(
$this
->
_name
);
if
(
isset
(
$this
->
_campaignId
))
{
if
(
$this
->
_action
&
CRM_Core_Action
::
DELETE
)
{
CRM_Campaign_BAO_Campaign
::
del
(
$this
->
_campaignId
);
...
...
@@ -309,7 +309,25 @@ class CRM_Campaign_Form_Campaign extends CRM_Core_Form {
$params
[
'is_active'
]
=
CRM_Utils_Array
::
value
(
'is_active'
,
$params
,
FALSE
);
$params
[
'last_modified_id'
]
=
$session
->
get
(
'userID'
);
$params
[
'last_modified_date'
]
=
date
(
'YmdHis'
);
$result
=
self
::
submit
(
$params
,
$this
);
if
(
!
$result
[
'is_error'
])
{
CRM_Core_Session
::
setStatus
(
ts
(
'Campaign %1 has been saved.'
,
[
1
=>
$result
[
'values'
][
$result
[
'id'
]][
'title'
]]),
ts
(
'Saved'
),
'success'
);
$session
->
pushUserContext
(
CRM_Utils_System
::
url
(
'civicrm/campaign'
,
'reset=1&subPage=campaign'
));
$this
->
ajaxResponse
[
'id'
]
=
$result
[
'id'
];
$this
->
ajaxResponse
[
'label'
]
=
$result
[
'values'
][
$result
[
'id'
]][
'title'
];
}
$buttonName
=
$this
->
controller
->
getButtonName
();
if
(
$buttonName
==
$this
->
getButtonName
(
'upload'
,
'new'
))
{
CRM_Core_Session
::
setStatus
(
ts
(
' You can add another Campaign.'
),
''
,
'info'
);
$session
->
replaceUserContext
(
CRM_Utils_System
::
url
(
'civicrm/campaign/add'
,
'reset=1&action=add'
));
}
else
{
$session
->
replaceUserContext
(
CRM_Utils_System
::
url
(
'civicrm/campaign'
,
'reset=1&subPage=campaign'
));
}
}
public
static
function
submit
(
$params
=
[],
$form
)
{
$groups
=
[];
if
(
is_array
(
$params
[
'includeGroups'
]))
{
foreach
(
$params
[
'includeGroups'
]
as
$key
=>
$id
)
{
if
(
$id
)
{
...
...
@@ -322,7 +340,7 @@ class CRM_Campaign_Form_Campaign extends CRM_Core_Form {
// delete previous includes/excludes, if campaign already existed
$groupTableName
=
CRM_Contact_BAO_Group
::
getTableName
();
$dao
=
new
CRM_Campaign_DAO_CampaignGroup
();
$dao
->
campaign_id
=
$
this
->
_campaignId
;
$dao
->
campaign_id
=
$
form
->
_campaignId
;
$dao
->
entity_table
=
$groupTableName
;
$dao
->
find
();
while
(
$dao
->
fetch
())
{
...
...
@@ -334,27 +352,13 @@ class CRM_Campaign_Form_Campaign extends CRM_Core_Form {
CRM_Utils_Array
::
value
(
'campaign_type_id'
,
$params
)
);
$params
[
'custom'
]
=
CRM_Core_BAO_CustomField
::
postProcess
(
$params
,
$
this
->
_campaignId
,
$
form
->
_campaignId
,
'Campaign'
);
$result
=
CRM_Campaign_BAO_Campaign
::
create
(
$params
);
if
(
$result
)
{
CRM_Core_Session
::
setStatus
(
ts
(
'Campaign %1 has been saved.'
,
[
1
=>
$result
->
title
]),
ts
(
'Saved'
),
'success'
);
$session
->
pushUserContext
(
CRM_Utils_System
::
url
(
'civicrm/campaign'
,
'reset=1&subPage=campaign'
));
$this
->
ajaxResponse
[
'id'
]
=
$result
->
id
;
$this
->
ajaxResponse
[
'label'
]
=
$result
->
title
;
}
$buttonName
=
$this
->
controller
->
getButtonName
();
if
(
$buttonName
==
$this
->
getButtonName
(
'upload'
,
'new'
))
{
CRM_Core_Session
::
setStatus
(
ts
(
' You can add another Campaign.'
),
''
,
'info'
);
$session
->
replaceUserContext
(
CRM_Utils_System
::
url
(
'civicrm/campaign/add'
,
'reset=1&action=add'
));
}
else
{
$session
->
replaceUserContext
(
CRM_Utils_System
::
url
(
'civicrm/campaign'
,
'reset=1&subPage=campaign'
));
}
// dev/core#1067 Clean Money before passing onto BAO to do the create.
$params
[
'goal_revenue'
]
=
CRM_Utils_Rule
::
cleanMoney
(
$params
[
'goal_revenue'
]);
$result
=
civicrm_api3
(
'Campaign'
,
'create'
,
$params
);
return
$result
;
}
}
This diff is collapsed.
Click to expand it.
tests/phpunit/CRM/Campaign/Form/CampaignTest.php
0 → 100644
+
63
−
0
View file @
70e7eaed
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 5 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2019 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
* Test APIv3 civicrm_contribute_* functions
*
* @package CiviCRM_APIv3
* @subpackage API_Contribution
* @group headless
*/
class
CRM_Campaign_Form_CampaignTest
extends
CiviUnitTestCase
{
/**
* Test the submit function on the contribution page.
*
* @param string $thousandSeparator
*
* @dataProvider getThousandSeparators
*/
public
function
testSubmit
(
$thousandSeparator
)
{
$this
->
setCurrencySeparators
(
$thousandSeparator
);
$this
->
createLoggedInUser
();
$form
=
new
CRM_Campaign_Form_Campaign
();
$form
->
_action
=
CRM_Core_Action
::
ADD
;
$result
=
CRM_Campaign_Form_Campaign
::
Submit
([
'goal_revenue'
=>
'$10'
.
$thousandSeparator
.
'000'
,
'is_active'
=>
1
,
'title'
=>
'Test Campaign'
,
'start_date'
=>
date
(
'Y-m-d'
),
'includeGroups'
=>
[],
'custom'
=>
[],
'campaign_type_id'
=>
1
,
],
$form
);
var_dump
(
$form
);
$campaign
=
$this
->
callAPISuccess
(
'campaign'
,
'get'
,
[
'id'
=>
$result
[
'id'
]]);
$this
->
assertEquals
(
'10000'
,
$campaign
[
'values'
][
$campaign
[
'id'
]][
'goal_revenue'
]);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment