-
-
Notifications
You must be signed in to change notification settings - Fork 825
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RecurringEdit - Add example. Include test assertions. Fix undeclared/…
…missing properties. This creates a new example of the `RecurringEdit` workflow message. Note that the example is tagged `phpunit` and defines a list of `asserts`. These assertions are evaluated using the default message-template. The test was not passing because some important properties were missing from `RecurringEdit`.
- Loading branch information
Showing
2 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
CRM/Contribute/WorkflowMessage/RecurringEdit/BasicEditExample.ex.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
class CRM_Contribute_WorkflowMessage_RecurringEdit_BasicEditExample extends \Civi\WorkflowMessage\WorkflowMessageExample { | ||
|
||
public function getExamples(): iterable { | ||
yield [ | ||
'name' => "workflow/{$this->wfName}/{$this->exName}", | ||
// This title is not very clear. When we have some more examples to compare against, feel free to change/clarify. | ||
'title' => ts('Recurring Edit: Basic Example'), | ||
'tags' => ['preview', 'phpunit'], | ||
]; | ||
} | ||
|
||
public function build(array &$example): void { | ||
$msg = (new CRM_Contribute_WorkflowMessage_RecurringEdit()) | ||
->setContact(\Civi\Test::example('workflow/generic/Alex')['modelProps']['contact']) | ||
->setContributionRecur(\Civi\Test::example('workflow/generic/ContributionRecurExample')['modelProps']['contributionRecur']); | ||
// FIXME: We should have a better name for entity-examples. It's kind a weird that the two examples above | ||
// are named "workflow/*" and use "modelProps". | ||
$example['data'] = $this->toArray($msg); | ||
|
||
$example['asserts'] = [ | ||
'default' => [ | ||
['for' => 'subject', 'regex' => '/Recurring Contribution Update.*Alex/'], | ||
['for' => 'text', 'regex' => '/Recurring contribution is for.*5,990.99, every 2 year.s. for 24 installments/'], | ||
], | ||
]; | ||
} | ||
|
||
protected function toArray(\Civi\WorkflowMessage\WorkflowMessageInterface $wfMsg) { | ||
return [ | ||
'workflow' => $this->wfName, | ||
'modelProps' => $wfMsg->export('modelProps'), | ||
]; | ||
} | ||
|
||
} |