Skip to content

Commit

Permalink
dev/core#3981 Fix Examples to use 0 rather than a possibly-real conta…
Browse files Browse the repository at this point in the history
…ct_id

Overview
==================================================
dev/core#3981 Fix Examples to use 0 rather than a possibly-real contact_id

https://lab.civicrm.org/dev/core/-/issues/3981

Before
==============================================
When using the Message Admin UI and trying out tokens those that are not
explicitly defined in the sample data are fetched from the database from
the contact whose id has been arbitrarily used.

After
=======================================================================
The contact_id is set to 0. As a result nothing is retrievable from the databse.

Technical Details
=======================================================================
I suspect this was not possible when the example was first written (the
token code has matured a bit) & a stand in number seemed intuitive - but
I think that is arguable even when there are no negative side
effects (for example if a url were in the letter then linking to
a random contact from it is kinda confusing) - but really loses it's potency
as an argument when there ARE negative side effects

Comments
============================================================================
I'm pretty sure there are some tests I need to adjust for this....
  • Loading branch information
eileenmcnaughton committed Nov 10, 2022
1 parent 01ac740 commit 98e528a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
6 changes: 4 additions & 2 deletions Civi/Test/ExampleData/Contact/Alex.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Civi\Test\ExampleData\Contact;

class Alex extends \Civi\Test\EntityExample {
use Civi\Test\EntityExample;

class Alex extends EntityExample {

public function getExamples(): iterable {
yield [
Expand All @@ -12,7 +14,7 @@ public function getExamples(): iterable {

public function build(array &$example): void {
$example['data'] = [
'id' => '100',
'id' => 0,
'first_name' => 'Alex',
'middle_name' => '',
'last_name' => 'D\u00edaz',
Expand Down
6 changes: 4 additions & 2 deletions Civi/Test/ExampleData/Contact/Barb.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Civi\Test\ExampleData\Contact;

class Barb extends \Civi\Test\EntityExample {
use Civi\Test\EntityExample;

class Barb extends EntityExample {

public function getExamples(): iterable {
yield [
Expand All @@ -12,7 +14,7 @@ public function getExamples(): iterable {

public function build(array &$example): void {
$example['data'] = [
'contact_id' => '100',
'contact_id' => 0,
'contact_type' => 'Individual',
'contact_sub_type' => NULL,
'sort_name' => 'Johnson, Barbara',
Expand Down
2 changes: 1 addition & 1 deletion Civi/Test/ExampleData/Contact/TheDailyBugle.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function getExamples(): iterable {

public function build(array &$example): void {
$example['data'] = [
'contact_id' => 102,
'contact_id' => 0,
'contact_type' => 'Organization',
'organization_name' => 'The Daily Bugle',
'sort_name' => 'Daily Bugle',
Expand Down

0 comments on commit 98e528a

Please sign in to comment.