APIv4 - Reorganize test classes, don't use transactions for custom value tests
[civicrm-core.git] / tests / phpunit / api / v4 / Entity / SystemRotateKeyTest.php
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\Api4TestBase;
23 use Civi\Crypto\CryptoTestTrait;
24 use Civi\Test\TransactionalInterface;
25 use Psr\Log\LoggerInterface;
26
27 /**
28 * @group headless
29 */
30 class RotateKeyTest extends Api4TestBase implements TransactionalInterface {
31
32 use CryptoTestTrait;
33
34 /**
35 * Set up baseline for testing
36 */
37 public function setUp(): void {
38 parent::setUp();
39 \CRM_Utils_Hook::singleton()->setHook('civicrm_crypto', [$this, 'registerExampleKeys']);
40 \CRM_Utils_Hook::singleton()->setHook('civicrm_cryptoRotateKey', [$this, 'onRotateKey']);
41 }
42
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']);
50 }
51
52 public function onRotateKey(string $tag, LoggerInterface $log) {
53 $this->assertEquals('UNIT-TEST', $tag);
54 $log->info('Updated field A using {tag}.', [
55 'tag' => $tag,
56 ]);
57 $log->info('Updated field B using {tag}.', [
58 'tag' => $tag,
59 ]);
60 }
61
62 }