Commit | Line | Data |
---|---|---|
b124f74b TO |
1 | <?php |
2 | ||
3 | /* | |
4 | +--------------------------------------------------------------------+ | |
5 | | Copyright CiviCRM LLC. All rights reserved. | | |
6 | | | | |
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 | +--------------------------------------------------------------------+ | |
11 | */ | |
12 | ||
13 | /** | |
14 | * | |
15 | * @package CRM | |
16 | * @copyright CiviCRM LLC https://civicrm.org/licensing | |
17 | */ | |
18 | ||
19 | ||
20 | namespace api\v4\Entity; | |
21 | ||
22 | use api\v4\UnitTestCase; | |
23 | use Civi\Crypto\CryptoTestTrait; | |
24 | use Psr\Log\LoggerInterface; | |
25 | ||
26 | /** | |
27 | * @group headless | |
28 | */ | |
29 | class RotateKeyTest extends UnitTestCase { | |
30 | ||
31 | use CryptoTestTrait; | |
32 | ||
33 | /** | |
34 | * Set up baseline for testing | |
35 | */ | |
36 | public function setUp() { | |
37 | parent::setUp(); | |
38 | \CRM_Utils_Hook::singleton()->setHook('civicrm_crypto', [$this, 'registerExampleKeys']); | |
39 | \CRM_Utils_Hook::singleton()->setHook('civicrm_cryptoRotateKey', [$this, 'onRotateKey']); | |
40 | } | |
41 | ||
42 | public function testRekey() { | |
43 | $result = \Civi\Api4\System::rotateKey(0)->setTag('UNIT-TEST')->execute(); | |
44 | $this->assertEquals(2, count($result)); | |
45 | $this->assertEquals('Updated field A using UNIT-TEST.', $result[0]['message']); | |
46 | $this->assertEquals('info', $result[0]['level']); | |
47 | $this->assertEquals('Updated field B using UNIT-TEST.', $result[1]['message']); | |
48 | $this->assertEquals('info', $result[1]['level']); | |
49 | } | |
50 | ||
51 | public function onRotateKey(string $tag, LoggerInterface $log) { | |
52 | $this->assertEquals('UNIT-TEST', $tag); | |
53 | $log->info('Updated field A using {tag}.', [ | |
54 | 'tag' => $tag, | |
55 | ]); | |
56 | $log->info('Updated field B using {tag}.', [ | |
57 | 'tag' => $tag, | |
58 | ]); | |
59 | } | |
60 | ||
61 | } |