[FOLLOWUP][BUGFIX] Fix parse time calculation
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / TimeTracker / TimeTrackerTest.php
1 <?php
2 declare(strict_types=1);
3 namespace TYPO3\CMS\Core\Tests\Unit\TimeTracker;
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\TimeTracker\TimeTracker;
19 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
20
21 /**
22 * Class TimeTrackerTest
23 */
24 class TimeTrackerTest extends UnitTestCase
25 {
26 /**
27 * @test
28 */
29 public function getParseTimeReturnsZeroIfNoValuesAreSet()
30 {
31 unset(
32 $GLOBALS['TYPO3_MISC']['microtime_end'],
33 $GLOBALS['TYPO3_MISC']['microtime_start'],
34 $GLOBALS['TYPO3_MISC']['microtime_BE_USER_start'],
35 $GLOBALS['TYPO3_MISC']['microtime_BE_USER_end']
36 );
37 $parseTime = (new TimeTracker())->getParseTime();
38 self::assertSame(0, $parseTime);
39 }
40
41 /**
42 * @test
43 */
44 public function getParseTimeReturnsTotalParseTimeInMillisecondsWithoutBeUserInitialization()
45 {
46 $baseValue = time();
47 $GLOBALS['TYPO3_MISC']['microtime_start'] = $baseValue;
48 $GLOBALS['TYPO3_MISC']['microtime_end'] = $baseValue + 10;
49 $GLOBALS['TYPO3_MISC']['microtime_BE_USER_start'] = $baseValue + 1;
50 $GLOBALS['TYPO3_MISC']['microtime_BE_USER_end'] = $baseValue + 3;
51 $parseTime = (new TimeTracker())->getParseTime();
52 self::assertSame(8000, $parseTime);
53 }
54
55 /**
56 * @test
57 */
58 public function getParseTimeReturnsParseTimeIfOnlyOneBeUserTimeWasSet()
59 {
60 $baseValue = time();
61 $GLOBALS['TYPO3_MISC']['microtime_start'] = $baseValue;
62 $GLOBALS['TYPO3_MISC']['microtime_end'] = $baseValue + 10;
63 $GLOBALS['TYPO3_MISC']['microtime_BE_USER_start'] = $baseValue + 1;
64 $GLOBALS['TYPO3_MISC']['microtime_BE_USER_end'] = 0;
65 $parseTime = (new TimeTracker())->getParseTime();
66 self::assertSame(10000, $parseTime);
67 }
68
69 /**
70 * @test
71 */
72 public function getParseTimeReturnsParseTimeIfNoBeUserTimeWasSet()
73 {
74 $baseValue = time();
75 $GLOBALS['TYPO3_MISC']['microtime_start'] = $baseValue;
76 $GLOBALS['TYPO3_MISC']['microtime_end'] = $baseValue + 10;
77 $GLOBALS['TYPO3_MISC']['microtime_BE_USER_start'] = 0;
78 $GLOBALS['TYPO3_MISC']['microtime_BE_USER_end'] = 0;
79 $parseTime = (new TimeTracker())->getParseTime();
80 self::assertSame(10000, $parseTime);
81 }
82 }