Skip to content

Commit

Permalink
Add test for API4 failing to decode strings stored as HTML
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich Lott / Artful Robot committed Sep 20, 2021
1 parent c6fdb63 commit 2dda69c
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tests/phpunit/api/v4/Action/ResultTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,37 @@ public function testJsonSerialize() {
$this->assertTrue(is_array(json_decode($json)));
}

/**
* Knowing that the db layer HTML-encodes strings, we want to test
* that this ugliness is hidden from us as users of the API.
*
* @see https://issues.civicrm.org/jira/browse/CRM-11532
* @see https://lab.civicrm.org/dev/core/-/issues/1328
*/
public function testNoDataCorruptionThroughEncoding() {

$original = 'hello < you';
$result = Contact::create(FALSE)
->setValues(['display_name' => $original])
->execute()->first();
$this->assertEquals($original, $result['display_name'],
"The value returned from Contact.create is different to the value sent."
);

$result = Contact::update(FALSE)
->addWhere('id', '=', $result['id'])
->setValues(['display_name' => $original])
->execute()->first();
$this->assertEquals($original, $result['display_name'],
"The value returned from Contact.update is different to the value sent."
);

$result = Contact::get(FALSE)
->addWhere('id', '=', $result['id'])
->execute()->first();
$this->assertEquals($original, $result['display_name'],
"The value returned from Contact.get is different to the value sent."
);
}

}

0 comments on commit 2dda69c

Please sign in to comment.