Commit | Line | Data |
---|---|---|
19b53e5b C |
1 | <?php |
2 | ||
380f3545 TO |
3 | /* |
4 | +--------------------------------------------------------------------+ | |
7d61e75f | 5 | | Copyright CiviCRM LLC. All rights reserved. | |
380f3545 | 6 | | | |
7d61e75f TO |
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 | | |
380f3545 TO |
10 | +--------------------------------------------------------------------+ |
11 | */ | |
12 | ||
13 | /** | |
14 | * | |
15 | * @package CRM | |
ca5cec67 | 16 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
380f3545 TO |
17 | * $Id$ |
18 | * | |
19 | */ | |
20 | ||
21 | ||
19b53e5b C |
22 | namespace api\v4\Action; |
23 | ||
24 | use Civi\Api4\Contact; | |
25 | ||
26 | /** | |
27 | * @group headless | |
28 | */ | |
29 | class ContactChecksumTest extends \api\v4\UnitTestCase { | |
30 | ||
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) | |
37 | ->execute() | |
38 | ->first(); | |
39 | ||
40 | $result = Contact::validateChecksum() | |
41 | ->setContactId($contact['id']) | |
42 | ->setChecksum($contact['cs']['checksum']) | |
43 | ->execute() | |
44 | ->first(); | |
45 | ||
46 | $this->assertTrue($result['valid']); | |
47 | } | |
48 | ||
49 | public function testValidateChecksum() { | |
50 | $cid = Contact::create() | |
51 | ->setCheckPermissions(FALSE) | |
52 | ->addValue('first_name', 'Checker') | |
53 | ->addValue('last_name', 'Sum') | |
54 | ->execute() | |
55 | ->first()['id']; | |
56 | ||
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); | |
59 | ||
60 | $result1 = Contact::validateChecksum() | |
61 | ->setContactId($cid) | |
62 | ->setChecksum($goodCs) | |
63 | ->execute() | |
64 | ->first(); | |
65 | $this->assertTrue($result1['valid']); | |
66 | ||
67 | $result2 = Contact::validateChecksum() | |
68 | ->setContactId($cid) | |
69 | ->setChecksum($badCs) | |
70 | ->execute() | |
71 | ->first(); | |
72 | $this->assertFalse($result2['valid']); | |
73 | } | |
74 | ||
75 | } |