4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC. All rights reserved. |
7 | This work is published under the GNU AGPLv3 license with some |
8 | permitted exceptions and without any warranty. For full license |
9 | and copyright information, see https://civicrm.org/licensing |
10 +--------------------------------------------------------------------+
16 * @copyright CiviCRM LLC https://civicrm.org/licensing
22 namespace api\v
4\Action
;
24 use Civi\Api4\Contact
;
29 class ContactChecksumTest
extends \api\v
4\UnitTestCase
{
31 public function testGetChecksum() {
32 $contact = Contact
::create()
33 ->setCheckPermissions(FALSE)
34 ->addValue('first_name', 'Check')
35 ->addValue('last_name', 'Sum')
36 ->addChain('cs', Contact
::getChecksum()->setContactId('$id')->setTtl(500), 0)
40 $result = Contact
::validateChecksum()
41 ->setContactId($contact['id'])
42 ->setChecksum($contact['cs']['checksum'])
46 $this->assertTrue($result['valid']);
49 public function testValidateChecksum() {
50 $cid = Contact
::create()
51 ->setCheckPermissions(FALSE)
52 ->addValue('first_name', 'Checker')
53 ->addValue('last_name', 'Sum')
57 $goodCs = \CRM_Contact_BAO_Contact_Utils
::generateChecksum($cid, NULL, 500);
58 $badCs = \CRM_Contact_BAO_Contact_Utils
::generateChecksum($cid, strtotime('now - 1 week'), 1);
60 $result1 = Contact
::validateChecksum()
62 ->setChecksum($goodCs)
65 $this->assertTrue($result1['valid']);
67 $result2 = Contact
::validateChecksum()
72 $this->assertFalse($result2['valid']);