[!!!][TASK] Extract testing framework for TYPO3
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Crypto / RandomTest.php
1 <?php
2 declare(strict_types=1);
3 namespace TYPO3\CMS\Core\Tests\Unit\Crypto;
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
18 use TYPO3\CMS\Core\Crypto\Random;
19
20 /**
21 * Test case
22 */
23 class RandomTest extends \TYPO3\CMS\Components\TestingFramework\Core\UnitTestCase
24 {
25 /**
26 * @test
27 */
28 public function generateRandomBytesReturnsExpectedAmountOfBytes()
29 {
30 $subject = new Random();
31 $this->assertEquals(4, strlen($subject->generateRandomBytes(4)));
32 }
33
34 /**
35 * Data provider for generateRandomHexStringReturnsExpectedAmountOfChars
36 *
37 * @return array
38 */
39 public function generateRandomHexStringReturnsExpectedAmountOfCharsDataProvider()
40 {
41 return [
42 [1],
43 [2],
44 [3],
45 [4],
46 [7],
47 [8],
48 [31],
49 [32],
50 [100],
51 [102],
52 [4000],
53 [4095],
54 [4096],
55 [4097],
56 [8000]
57 ];
58 }
59
60 /**
61 * @test
62 * @dataProvider generateRandomHexStringReturnsExpectedAmountOfCharsDataProvider
63 * @param int $numberOfChars Number of Chars to generate
64 */
65 public function generateRandomHexStringReturnsExpectedAmountOfChars($numberOfChars)
66 {
67 $subject = new Random();
68 $this->assertEquals($numberOfChars, strlen($subject->generateRandomHexString($numberOfChars)));
69 }
70 }