[BUGFIX] Fix minor ux issues in EXT:recycler
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / TimeTracker / TimeTrackerTest.php
1 <?php
2 declare(strict_types=1);
3
4 namespace TimeTracker;
5
6 /*
7 * This file is part of the TYPO3 CMS project.
8 *
9 * It is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License, either version 2
11 * of the License, or any later version.
12 *
13 * For the full copyright and license information, please read the
14 * LICENSE.txt file that was distributed with this source code.
15 *
16 * The TYPO3 project - inspiring people to share!
17 */
18
19 use TYPO3\CMS\Core\TimeTracker\TimeTracker;
20
21 /**
22 * Class TimeTrackerTest
23 */
24 class TimeTrackerTest extends \PHPUnit_Framework_TestCase
25 {
26 /**
27 * @var bool
28 */
29 protected $backupGlobals = true;
30
31 /**
32 * @var TimeTracker
33 */
34 protected $timeTracker;
35
36 protected function setUp()
37 {
38 $this->timeTracker = new TimeTracker();
39 }
40
41 /**
42 * @test
43 */
44 public function getParseTimeReturnsZeroIfNoValuesAreSet()
45 {
46 unset(
47 $GLOBALS['TYPO3_MISC']['microtime_end'],
48 $GLOBALS['TYPO3_MISC']['microtime_start'],
49 $GLOBALS['TYPO3_MISC']['microtime_BE_USER_start'],
50 $GLOBALS['TYPO3_MISC']['microtime_BE_USER_end']
51 );
52 $parseTime = $this->timeTracker->getParseTime();
53 self::assertSame(0, $parseTime);
54 }
55
56 /**
57 * @test
58 */
59 public function getParseTimeReturnsTotalParseTimeInMillisecondsWithoutBeUserInitialization()
60 {
61 $baseValue = time();
62 $GLOBALS['TYPO3_MISC']['microtime_start'] = $baseValue;
63 $GLOBALS['TYPO3_MISC']['microtime_end'] = $baseValue + 10;
64 $GLOBALS['TYPO3_MISC']['microtime_BE_USER_start'] = $baseValue + 1;
65 $GLOBALS['TYPO3_MISC']['microtime_BE_USER_end'] = $baseValue + 3;
66 $parseTime = $this->timeTracker->getParseTime();
67 self::assertSame(8000, $parseTime);
68 }
69
70 /**
71 * @test
72 */
73 public function getParseTimeReturnsParseTimeIfOnlyOneBeUserTimeWasSet()
74 {
75 $baseValue = time();
76 $GLOBALS['TYPO3_MISC']['microtime_start'] = $baseValue;
77 $GLOBALS['TYPO3_MISC']['microtime_end'] = $baseValue + 10;
78 $GLOBALS['TYPO3_MISC']['microtime_BE_USER_start'] = $baseValue + 1;
79 $GLOBALS['TYPO3_MISC']['microtime_BE_USER_end'] = 0;
80 $parseTime = $this->timeTracker->getParseTime();
81 self::assertSame(10000, $parseTime);
82 }
83
84 /**
85 * @test
86 */
87 public function getParseTimeReturnsParseTimeIfNoBeUserTimeWasSet()
88 {
89 $baseValue = time();
90 $GLOBALS['TYPO3_MISC']['microtime_start'] = $baseValue;
91 $GLOBALS['TYPO3_MISC']['microtime_end'] = $baseValue + 10;
92 $GLOBALS['TYPO3_MISC']['microtime_BE_USER_start'] = 0;
93 $GLOBALS['TYPO3_MISC']['microtime_BE_USER_end'] = 0;
94 $parseTime = $this->timeTracker->getParseTime();
95 self::assertSame(10000, $parseTime);
96 }
97 }