‪TYPO3CMS  ‪main
ReportTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use PHPUnit\Framework\Attributes\Test;
21 use Symfony\Component\Uid\UuidV4;
23 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
24 
25 final class ‪ReportTest extends UnitTestCase
26 {
27  #[Test]
29  {
30  $report = ‪Report::fromArray([
31  'scope' => 'backend',
32  'meta' => json_encode([]),
33  'details' => json_encode([
34  'document-uri' => 'https://example.org/',
35  'violated-directive' => 'script-src',
36  ]),
37  'uuid' => $this->‪createUuidString(),
38  ]);
39  self::assertSame('script-src', $report->details['effective-directive']);
40  }
41 
42  #[Test]
43  public function ‪toArrayUsesNativeDetailKeys(): void
44  {
45  ‪$details = [
46  'document-uri' => 'https://example.org/',
47  'effective-directive' => 'script-src',
48  ];
49  $report = ‪Report::fromArray([
50  'scope' => 'backend',
51  'meta' => json_encode([]),
52  'details' => json_encode(‪$details),
53  'uuid' => $this->‪createUuidString(),
54  ]);
55  self::assertSame(‪$details, json_decode($report->toArray()['details'], true));
56  }
57 
58  #[Test]
59  public function ‪jsonEncodeUsesCamelCasedDetailKeys(): void
60  {
61  ‪$details = [
62  'document-uri' => 'https://example.org/',
63  'effective-directive' => 'script-src',
64  ];
65  $report = ‪Report::fromArray([
66  'scope' => 'backend',
67  'meta' => json_encode([]),
68  'details' => json_encode(‪$details),
69  'uuid' => $this->‪createUuidString(),
70  ]);
71  $expectation = [
72  'documentUri' => 'https://example.org/',
73  'effectiveDirective' => 'script-src',
74  ];
75  self::assertSame($expectation, json_decode(json_encode($report), true)['details']);
76  }
77 
78  private function ‪createUuidString(): string
79  {
80  return (string)(new UuidV4());
81  }
82 }
‪TYPO3\CMS\Webhooks\Message\$details
‪identifier readonly UriInterface readonly array $details
Definition: MfaVerificationErrorOccurredMessage.php:37
‪TYPO3\CMS\Core\Tests\Unit\Security\ContentSecurityPolicy\Reporting\ReportTest
Definition: ReportTest.php:26
‪TYPO3\CMS\Core\Tests\Unit\Security\ContentSecurityPolicy\Reporting\ReportTest\toArrayUsesNativeDetailKeys
‪toArrayUsesNativeDetailKeys()
Definition: ReportTest.php:43
‪TYPO3\CMS\Core\Tests\Unit\Security\ContentSecurityPolicy\Reporting\ReportTest\jsonEncodeUsesCamelCasedDetailKeys
‪jsonEncodeUsesCamelCasedDetailKeys()
Definition: ReportTest.php:59
‪TYPO3\CMS\Core\Security\ContentSecurityPolicy\Reporting\Report\fromArray
‪static fromArray(array $array)
Definition: Report.php:32
‪TYPO3\CMS\Core\Security\ContentSecurityPolicy\Reporting\Report
Definition: Report.php:27
‪TYPO3\CMS\Core\Tests\Unit\Security\ContentSecurityPolicy\Reporting\ReportTest\createUuidString
‪createUuidString()
Definition: ReportTest.php:78
‪TYPO3\CMS\Core\Tests\Unit\Security\ContentSecurityPolicy\Reporting
Definition: ReportTest.php:18
‪TYPO3\CMS\Core\Tests\Unit\Security\ContentSecurityPolicy\Reporting\ReportTest\effectiveDirectiveIsTakenFromViolatedDirective
‪effectiveDirectiveIsTakenFromViolatedDirective()
Definition: ReportTest.php:28