Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Extensions
mosaicomsgtpl
Commits
c56a062b
Commit
c56a062b
authored
Sep 24, 2018
by
Rich
Browse files
fix and add tests
parent
a93ac9c0
Changes
2
Hide whitespace changes
Inline
Side-by-side
api/v3/Job/MosaicoMsgSync.php
View file @
c56a062b
...
...
@@ -51,15 +51,11 @@ function civicrm_api3_job_mosaico_msg_sync($params) {
// cool feature ("Initial welcome email").
//
// We allow the Mosaico title to include a subject following the | symbol.
list
(
$title
,
$subject
)
=
preg_split
(
'/\s*[|]\s*/'
,
$existingMosTpl
[
'title'
]);
if
(
empty
(
$subject
))
{
// Default to old behaviour.
$subject
=
$title
;
}
preg_match
(
'/^(.+?)\s*[|]\s*(.+)$/'
,
$existingMosTpl
[
'title'
],
$_
);
$createParams
=
[
'msg_html'
=>
_civicrm_api3_job_mosaico_msg_filter
(
$existingMosTpl
[
'html'
]),
'msg_title'
=>
$title
,
'msg_subject'
=>
$subject
,
'msg_title'
=>
empty
(
$_
[
1
])
?
$existingMosTpl
[
'title'
]
:
$_
[
1
]
,
'msg_subject'
=>
empty
(
$_
[
2
])
?
$existingMosTpl
[
'title'
]
:
$_
[
2
],
// default to title, as before.
];
// When a template is created from a Mosaico Base Template, it will not have a msg_tpl_id.
...
...
tests/phpunit/api/v3/Job/MosaicoMsgSyncTest.php
View file @
c56a062b
...
...
@@ -88,6 +88,57 @@ class api_v3_Job_MosaicoMsgSyncTest extends \PHPUnit_Framework_TestCase implemen
$this
->
assertEquals
(
1
+
$oldCount
,
$newCount
);
}
/**
* Test clones work.
*/
public
function
testClone
()
{
$this
->
assertEquals
(
'MosaicoTemplate'
,
CRM_Core_DAO_AllCoreTables
::
getBriefName
(
'CRM_Mosaico_DAO_MosaicoTemplate'
));
// Create the first template and run the sync.
$first
=
$this
->
createMosaicoTemplate
(
array
(
'title'
=>
'First example'
));
$result
=
civicrm_api3
(
'Job'
,
'mosaico_msg_sync'
,
[
'id'
=>
$first
[
'id'
]]);
$oldCount
=
CRM_Core_DAO
::
singleValueQuery
(
'SELECT count(*) FROM civicrm_msg_template'
);
// Create the clone and run the sync on it passing is_new (which is what the post hook does).
$second
=
civicrm_api3
(
'MosaicoTemplate'
,
'clone'
,
[
'id'
=>
$first
[
'id'
],
'title'
=>
'clone'
]);
$result
=
civicrm_api3
(
'Job'
,
'mosaico_msg_sync'
,
[
'id'
=>
$second
[
'id'
],
'is_new'
=>
TRUE
]);
// Count templates - should be one more.
$newCount
=
CRM_Core_DAO
::
singleValueQuery
(
'SELECT count(*) FROM civicrm_msg_template'
);
$this
->
assertEquals
(
1
+
$oldCount
,
$newCount
);
}
/**
* Test title/subject parsing.
*
* @dataProvider titleSubjectParsingProvider
*/
public
function
testTitleSubjectParsing
(
$input
,
$title
,
$subject
)
{
$this
->
assertEquals
(
'MosaicoTemplate'
,
CRM_Core_DAO_AllCoreTables
::
getBriefName
(
'CRM_Mosaico_DAO_MosaicoTemplate'
));
$first
=
$this
->
createMosaicoTemplate
(
array
(
'title'
=>
$input
));
civicrm_api3
(
'Job'
,
'mosaico_msg_sync'
,
[
'id'
=>
$first
[
'id'
]]);
// Reload to get the msg_tpl_id.
$first
=
civicrm_api3
(
'MosaicoTemplate'
,
'getsingle'
,
[
'id'
=>
$first
[
'id'
]]);
$this
->
assertGreaterThan
(
0
,
(
int
)
$first
[
'msg_tpl_id'
]);
$tpl
=
civicrm_api3
(
'MessageTemplate'
,
'getsingle'
,
[
'id'
=>
$first
[
'msg_tpl_id'
]]);
$this
->
assertEquals
(
$title
,
$tpl
[
'msg_title'
]);
$this
->
assertEquals
(
$subject
,
$tpl
[
'msg_subject'
]);
}
/**
* Data provider
*/
public
function
titleSubjectParsingProvider
()
{
return
[
[
'input'
=>
'A simple subject'
,
'title'
=>
'A simple subject'
,
'subject'
=>
'A simple subject'
],
[
'input'
=>
'internal title|public subject'
,
'title'
=>
'internal title'
,
'subject'
=>
'public subject'
],
[
'input'
=>
'internal title | public subject'
,
'title'
=>
'internal title'
,
'subject'
=>
'public subject'
],
[
'input'
=>
'internal title | public subject | with pipe'
,
'title'
=>
'internal title'
,
'subject'
=>
'public subject | with pipe'
],
];
}
protected
function
createMosaicoTemplate
(
$params
=
array
())
{
$defaults
=
array
(
'title'
=>
'The Title'
,
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment