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
20 namespace api\v
4\Action
;
22 use Civi\Api4\Contact
;
27 class ContactChecksumTest
extends \api\v
4\UnitTestCase
{
29 public function testGetChecksum() {
30 $contact = Contact
::create(FALSE)
31 ->addValue('first_name', 'Check')
32 ->addValue('last_name', 'Sum')
33 ->addChain('cs', Contact
::getChecksum()->setContactId('$id')->setTtl(500), 0)
37 $result = Contact
::validateChecksum()
38 ->setContactId($contact['id'])
39 ->setChecksum($contact['cs']['checksum'])
43 $this->assertTrue($result['valid']);
46 public function testValidateChecksum() {
47 $cid = Contact
::create(FALSE)
48 ->addValue('first_name', 'Checker')
49 ->addValue('last_name', 'Sum')
53 $goodCs = \CRM_Contact_BAO_Contact_Utils
::generateChecksum($cid, NULL, 500);
54 $badCs = \CRM_Contact_BAO_Contact_Utils
::generateChecksum($cid, strtotime('now - 1 week'), 1);
56 $result1 = Contact
::validateChecksum()
58 ->setChecksum($goodCs)
61 $this->assertTrue($result1['valid']);
63 $result2 = Contact
::validateChecksum()
68 $this->assertFalse($result2['valid']);