-
-
Notifications
You must be signed in to change notification settings - Fork 824
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Ref] intial testing on case tokens, make knownTokens optional #21289
Merged
+155
−2
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,150 @@ | ||
<?php | ||
/* | ||
+--------------------------------------------------------------------+ | ||
| Copyright CiviCRM LLC. All rights reserved. | | ||
| | | ||
| This work is published under the GNU AGPLv3 license with some | | ||
| permitted exceptions and without any warranty. For full license | | ||
| and copyright information, see https://civicrm.org/licensing | | ||
+--------------------------------------------------------------------+ | ||
*/ | ||
|
||
/** | ||
* CRM_Utils_TokenConsistencyTest | ||
* | ||
* Class for ensuring tokens have internal consistency. | ||
* | ||
* @group Tokens | ||
* | ||
* @group headless | ||
*/ | ||
class CRM_Utils_TokenConsistencyTest extends CiviUnitTestCase { | ||
|
||
use CRMTraits_Custom_CustomDataTrait; | ||
|
||
/** | ||
* Created case. | ||
* | ||
* @var array | ||
*/ | ||
protected $case; | ||
|
||
/** | ||
* Post test cleanup. | ||
* | ||
* @throws \API_Exception | ||
* @throws \CRM_Core_Exception | ||
*/ | ||
public function tearDown(): void { | ||
$this->quickCleanup(['civicrm_case', 'civicrm_case_type']); | ||
parent::tearDown(); | ||
} | ||
|
||
/** | ||
* Test that case tokens are consistently rendered. | ||
* | ||
* @throws \API_Exception | ||
* @throws \CiviCRM_API3_Exception | ||
*/ | ||
public function testCaseTokenConsistency(): void { | ||
$this->createLoggedInUser(); | ||
CRM_Core_BAO_ConfigSetting::enableComponent('CiviCase'); | ||
$this->createCustomGroupWithFieldOfType(['extends' => 'Case']); | ||
$tokens = CRM_Core_SelectValues::caseTokens(); | ||
$this->assertEquals($this->getCaseTokens(), $tokens); | ||
$caseID = $this->getCaseID(); | ||
$tokenHtml = CRM_Utils_Token::replaceCaseTokens($caseID, implode("\n", array_keys($this->getCaseTokens())), ['case' => $this->getCaseTokenKeys()]); | ||
$this->assertEquals($this->getExpectedCaseTokenOutput(), $tokenHtml); | ||
// Now do the same without passing in 'knownTokens' | ||
$tokenHtml = CRM_Utils_Token::replaceCaseTokens($caseID, implode("\n", array_keys($this->getCaseTokens()))); | ||
$this->assertEquals($this->getExpectedCaseTokenOutput(), $tokenHtml); | ||
} | ||
|
||
/** | ||
* Get expected output from token parsing. | ||
* | ||
* @return string | ||
*/ | ||
protected function getExpectedCaseTokenOutput(): string { | ||
return '1 | ||
Housing Support | ||
Case Subject | ||
July 23rd, 2021 | ||
July 26th, 2021 | ||
case details | ||
Ongoing | ||
No | ||
' . $this->case['modified_date'] . ' | ||
' . $this->case['created_date'] . ' | ||
'; | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
protected function getContactID(): int { | ||
if (!isset($this->ids['Contact'][0])) { | ||
$this->ids['Contact'][0] = $this->individualCreate(); | ||
} | ||
return $this->ids['Contact'][0]; | ||
} | ||
|
||
/** | ||
* Get the keys for the case tokens. | ||
* | ||
* @return array | ||
*/ | ||
public function getCaseTokenKeys(): array { | ||
$return = []; | ||
foreach (array_keys($this->getCaseTokens()) as $key) { | ||
$return[] = substr($key, 6, -1); | ||
} | ||
return $return; | ||
} | ||
|
||
/** | ||
* Get declared tokens. | ||
* | ||
* @return string[] | ||
*/ | ||
public function getCaseTokens(): array { | ||
return [ | ||
'{case.id}' => 'Case ID', | ||
'{case.case_type_id}' => 'Case Type ID', | ||
'{case.subject}' => 'Case Subject', | ||
'{case.start_date}' => 'Case Start Date', | ||
'{case.end_date}' => 'Case End Date', | ||
'{case.details}' => 'Details', | ||
'{case.status_id}' => 'Case Status', | ||
'{case.is_deleted}' => 'Case is in the Trash', | ||
'{case.created_date}' => 'Created Date', | ||
'{case.modified_date}' => 'Modified Date', | ||
'{case.custom_1}' => 'Enter text here :: Group with field text', | ||
]; | ||
} | ||
|
||
/** | ||
* Get case ID. | ||
* | ||
* @return int | ||
*/ | ||
protected function getCaseID(): int { | ||
if (!isset($this->case)) { | ||
$this->case = $this->callAPISuccess('Case', 'create', [ | ||
'case_type_id' => 'housing_support', | ||
'activity_subject' => 'Case Subject', | ||
'client_id' => $this->getContactID(), | ||
'status_id' => 1, | ||
'subject' => 'Case Subject', | ||
'start_date' => '2021-07-23 15:39:20', | ||
'end_date' => '2021-07-26 18:07:20', | ||
'medium_id' => 2, | ||
'details' => 'case details', | ||
'activity_details' => 'blah blah', | ||
'sequential' => 1, | ||
])['values'][0]; | ||
} | ||
return $this->case['id']; | ||
} | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Case status "ongoing" when it has an end date is a little bit unrealistic, but technically possible. Otherwise I think this PR is ok.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@demeritcowboy I just 'grabbed'
'status_id' => 1,
- should it change or should we merge this & ignoreThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test seems unlikely to be used in a way that would enforce that cases with status ongoing should have an end date (or vice-versa). So I'd say it's inconsistent but not "dangerous".
Also noticing that case.contact_id and case.client_id are valid tokens although don't seem to appear in the dropdown on a form. I'm not sure where the dropdown list comes from but I guess that dropdown would be the authority.