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\Entity
;
22 use api\v
4\UnitTestCase
;
23 use Civi\Crypto\CryptoTestTrait
;
24 use Psr\Log\LoggerInterface
;
29 class RotateKeyTest
extends UnitTestCase
{
34 * Set up baseline for testing
36 public function setUp() {
38 \CRM_Utils_Hook
::singleton()->setHook('civicrm_crypto', [$this, 'registerExampleKeys']);
39 \CRM_Utils_Hook
::singleton()->setHook('civicrm_cryptoRotateKey', [$this, 'onRotateKey']);
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']);
51 public function onRotateKey(string $tag, LoggerInterface
$log) {
52 $this->assertEquals('UNIT-TEST', $tag);
53 $log->info('Updated field A using {tag}.', [
56 $log->info('Updated field B using {tag}.', [