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\Api4TestBase
;
23 use Civi\Crypto\CryptoTestTrait
;
24 use Civi\Test\TransactionalInterface
;
25 use Psr\Log\LoggerInterface
;
30 class RotateKeyTest
extends Api4TestBase
implements TransactionalInterface
{
35 * Set up baseline for testing
37 public function setUp(): void
{
39 \CRM_Utils_Hook
::singleton()->setHook('civicrm_crypto', [$this, 'registerExampleKeys']);
40 \CRM_Utils_Hook
::singleton()->setHook('civicrm_cryptoRotateKey', [$this, 'onRotateKey']);
43 public function testRekey() {
44 $result = \Civi\Api4\System
::rotateKey(0)->setTag('UNIT-TEST')->execute();
45 $this->assertEquals(2, count($result));
46 $this->assertEquals('Updated field A using UNIT-TEST.', $result[0]['message']);
47 $this->assertEquals('info', $result[0]['level']);
48 $this->assertEquals('Updated field B using UNIT-TEST.', $result[1]['message']);
49 $this->assertEquals('info', $result[1]['level']);
52 public function onRotateKey(string $tag, LoggerInterface
$log) {
53 $this->assertEquals('UNIT-TEST', $tag);
54 $log->info('Updated field A using {tag}.', [
57 $log->info('Updated field B using {tag}.', [