Skip to content

Commit 0548980

Browse files
committed
[TASK] Make PhpUnit tests happy again
1 parent 079a54d commit 0548980

2 files changed

Lines changed: 27 additions & 44 deletions

File tree

Classes/Utility/IpUtility.php

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,24 @@ class IpUtility
2020
public static function getIpAddress(string $testIp = ''): string
2121
{
2222
$ipAddress = $testIp;
23-
if (empty($ipAddress)) {
23+
if ($ipAddress === '') {
2424
$ipAddress = GeneralUtility::getIndpEnv('REMOTE_ADDR');
25-
if (self::isPrivateOrLocalIp($ipAddress)) {
26-
$ipAddress = getenv('LUX_DEV_IPxxx') ?: self::fetchExternalIp();
25+
if (self::isPrivateOrLocalIp($ipAddress) && self::isTestingContext() === false) {
26+
$ipAddress = getenv('LUX_DEV_IP') ?: self::fetchExternalIp();
2727
}
2828
}
2929
return $ipAddress;
3030
}
3131

32+
public static function getIpAddressAnonymized(string $testIp = ''): string
33+
{
34+
return preg_replace(
35+
['/\.\d*$/', '/[\da-f]*:[\da-f]*$/'],
36+
['.***', '****:****'],
37+
self::getIpAddress($testIp)
38+
);
39+
}
40+
3241
/**
3342
* Fetch external IP address from public API services with fallback options for local dev environment only.
3443
* Tries multiple services for reliability.
@@ -81,12 +90,12 @@ protected static function isPrivateOrLocalIp(string $ip): bool
8190
return GeneralUtility::cmpIP($ip, '127.0.0.0/8, 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, ::1');
8291
}
8392

84-
public static function getIpAddressAnonymized(string $testIp = ''): string
93+
/**
94+
* @return bool
95+
* @SuppressWarnings(PHPMD.Superglobals)
96+
*/
97+
protected static function isTestingContext(): bool
8598
{
86-
return preg_replace(
87-
['/\.\d*$/', '/[\da-f]*:[\da-f]*$/'],
88-
['.***', '****:****'],
89-
self::getIpAddress($testIp)
90-
);
99+
return (bool)($GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['lux']['testingContext'] ?? false);
91100
}
92101
}

Tests/Helper/TestingHelper.php

Lines changed: 9 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,16 @@
22

33
namespace In2code\Lux\Tests\Helper;
44

5-
use TYPO3\CMS\Core\Configuration\ConfigurationManager;
6-
use TYPO3\CMS\Core\TimeTracker\TimeTracker;
7-
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
8-
9-
/**
10-
* Class TestingHelper
11-
*/
125
class TestingHelper
136
{
147
/**
158
* @return void
169
* @SuppressWarnings(PHPMD.Superglobals)
1710
*/
18-
public static function setDefaultConstants()
11+
public static function setDefaultConstants(): void
1912
{
13+
$GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['lux']['testingContext'] = 1;
14+
2015
$GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['lux'] =
2116
'a:11:{s:13:"checkFunction";s:4:"User";s:18:"scoringCalculation";s:96:"' .
2217
'(10 * numberOfSiteVisits) + (1 * numberOfPageVisits) + (20 * downloads) - (1 * lastVisitDaysAgo)";' .
@@ -33,7 +28,6 @@ public static function setDefaultConstants()
3328
$GLOBALS['TYPO3_CONF_VARS']['BE']['lockRootPath'] = '';
3429
$GLOBALS['TYPO3_CONF_VARS']['BE']['cookieName'] = '';
3530
$GLOBALS['TYPO3_CONF_VARS']['BE']['warning_email_addr'] = '';
36-
$GLOBALS['TYPO3_CONF_VARS']['BE']['lockIP'] = '';
3731
$GLOBALS['TYPO3_CONF_VARS']['BE']['sessionTimeout'] = 0;
3832
$GLOBALS['TYPO3_CONF_VARS']['SYS']['requestURIvar'] = false;
3933
$GLOBALS['TYPO3_CONF_VARS']['SYS']['systemLog'] = 'error_log';
@@ -43,46 +37,26 @@ public static function setDefaultConstants()
4337
$GLOBALS['TYPO3_CONF_VARS']['BE']['lockIPv6'] = 0;
4438
// @extensionScannerIgnoreLine
4539
$GLOBALS['TYPO3_CONF_VARS']['SYS']['enable_DLOG'] = false;
46-
if (!defined('TYPO3_OS')) {
40+
if (defined('TYPO3_OS') === false) {
4741
define('TYPO3_OS', 'LINUX');
4842
}
49-
if (!defined('PATH_site')) {
43+
if (defined('PATH_site') === false) {
5044
define('PATH_site', self::getWebRoot());
5145
}
52-
if (!defined('PATH_thisScript')) {
46+
if (defined('PATH_thisScript') === false) {
5347
define('PATH_thisScript', self::getWebRoot() . 'typo3');
5448
}
55-
if (!defined('TYPO3_version')) {
49+
if (defined('TYPO3_version') === false) {
5650
define('TYPO3_version', '8007000');
5751
}
58-
if (!defined('PHP_EXTENSIONS_DEFAULT')) {
52+
if (defined('PHP_EXTENSIONS_DEFAULT') === false) {
5953
define('PHP_EXTENSIONS_DEFAULT', 'php');
6054
}
61-
if (!defined('FILE_DENY_PATTERN_DEFAULT')) {
55+
if (defined('FILE_DENY_PATTERN_DEFAULT') === false) {
6256
define('FILE_DENY_PATTERN_DEFAULT', '');
6357
}
6458
}
6559

66-
/**
67-
* @param int|null pid
68-
* @return void
69-
* @SuppressWarnings(PHPMD.Superglobals)
70-
*/
71-
public static function initializeTsfe($pid = null)
72-
{
73-
$configurationManager = new ConfigurationManager();
74-
$GLOBALS['TYPO3_CONF_VARS'] = $configurationManager->getDefaultConfiguration();
75-
self::setDefaultConstants();
76-
$GLOBALS['TYPO3_CONF_VARS']['SYS']['trustedHostsPattern'] = '.*';
77-
$GLOBALS['TYPO3_CONF_VARS']['FE']['ContentObjects'] = [
78-
'TEXT' => 'TYPO3\CMS\Frontend\ContentObject\TextContentObject',
79-
];
80-
$GLOBALS['TT'] = new TimeTracker();
81-
$GLOBALS['TSFE'] = new TypoScriptFrontendController($GLOBALS['TYPO3_CONF_VARS'], $pid ?: 1, 0, true);
82-
$GLOBALS['TSFE']->tmpl->setup['config.']['sys_language_uid'] = '1';
83-
$GLOBALS['TSFE']->fe_user->user['uid'] = 4784;
84-
}
85-
8660
/**
8761
* @return string
8862
*/

0 commit comments

Comments
 (0)