Skip to content

Commit

Permalink
Fix __DIR__ use (in 30 out of 120-ish files)
Browse files Browse the repository at this point in the history
  • Loading branch information
Stoyan Stefanov committed Oct 17, 2022
1 parent 255a184 commit f609bb2
Show file tree
Hide file tree
Showing 31 changed files with 190 additions and 193 deletions.
12 changes: 2 additions & 10 deletions tests/Handlers/AccountTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,9 @@ function setcookie($name, $value, $expiration, $path, $domain)
function error_log($str)
{
}
define('VER_TYPOGRAPHY_CSS', "foo.css");
define('VER_LAYOUT_CSS', "layout.css");
define('VER_CSS', "site.css");
define('VER_HEADER_CSS', "header.css");
define('VER_JS', "site.js");
define('VER_BUTTON_CSS', "button.css");
define('VER_ACCOUNT_CSS', "account.css");
define('VER_JS_ACCOUNT', "account.js");
define('VER_JS_ESTIMATE_TAXES', "estimate-taxes.js");

define('FRIENDLY_URLS', true);
define('EMBED', false);


final class AccountTest extends TestCase
{
Expand Down
10 changes: 5 additions & 5 deletions tests/TemplateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ final class TemplateTest extends TestCase
public function testConstructorSetsDefaults(): void
{
$dir = realpath(WWW_PATH . '/templates');
$layout = realpath(__DIR__ . '/../www/templates/layouts/default.php');
$layout = realpath(WWW_PATH . '/templates/layouts/default.php');
$tpl = new Template();
$this->assertEquals($dir, $tpl->getDir());
$this->assertEquals($layout, $tpl->getLayout());
}
public function testConstructorSetsValues(): void
{
$dir = realpath(__DIR__ . '/../www/templates/errors');
$layout = realpath(__DIR__ . '/../www/templates/layouts/default.php');
$dir = realpath(WWW_PATH . '/templates/errors');
$layout = realpath(WWW_PATH . '/templates/layouts/default.php');
$tpl = new Template('errors');
$this->assertEquals($dir, $tpl->getDir());
$this->assertEquals($layout, $tpl->getLayout());
Expand All @@ -27,13 +27,13 @@ public function testSetLayout(): void
{
$tpl = new Template();
$tpl->setLayout('../../../tests/fixtures/layout-1');
$layout = realpath(__DIR__ . '/fixtures/layout-1.php');
$layout = realpath(TESTS_PATH . '/fixtures/layout-1.php');
$this->assertEquals($tpl->getLayout(), $layout);
}

public function testRenderReturnsRenderedString(): void
{
$dir = realpath(__DIR__ . '/fixtures');
$dir = realpath(TESTS_PATH . '/fixtures');
$tpl = new Template('../../tests/fixtures');
$tpl->setLayout('../../../tests/fixtures/layout-1');
$this->assertEquals($dir, $tpl->getDir());
Expand Down
4 changes: 2 additions & 2 deletions tests/UtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ public function testConstructorThrows(): void

public function testGetSetting(): void
{
$override_settings_file = __DIR__ . '/fixtures/settings.ini';
$override_settings_file = TESTS_PATH . '/fixtures/settings.ini';
$value = Util::getSetting('product', false, $override_settings_file);
$this->assertEquals('WebPagetest', $value);
}

public function testGetSettingWithNullDefault(): void
{
$override_settings_file = __DIR__ . '/fixtures/settings.ini';
$override_settings_file = TESTS_PATH . '/fixtures/settings.ini';
$value = Util::getSetting('product', null, $override_settings_file);
$this->assertEquals('WebPagetest', $value);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/WaterfallIncTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

require_once __DIR__ . '/..' . '/www/waterfall.inc';
require_once INCLUDES_PATH . '/waterfall.inc';

use PHPUnit\Framework\TestCase;

Expand Down
10 changes: 5 additions & 5 deletions www/addresses.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
include 'common.inc';

if (isset($_REQUEST['k'])) {
$keys_file = __DIR__ . '/settings/keys.ini';
if (file_exists(__DIR__ . '/settings/common/keys.ini')) {
$keys_file = __DIR__ . '/settings/common/keys.ini';
$keys_file = SETTINGS_PATH . '/keys.ini';
if (file_exists(SETTINGS_PATH . '/common/keys.ini')) {
$keys_file = SETTINGS_PATH . '/common/keys.ini';
}
if (file_exists(__DIR__ . '/settings/server/keys.ini')) {
$keys_file = __DIR__ . '/settings/server/keys.ini';
if (file_exists(SETTINGS_PATH . '/server/keys.ini')) {
$keys_file = SETTINGS_PATH . '/server/keys.ini';
}
$keys = parse_ini_file($keys_file, true);
if (isset($keys['server']['key']) && $_REQUEST['k'] == $keys['server']['key']) {
Expand Down
5 changes: 3 additions & 2 deletions www/aggregate.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
// found in the LICENSE.md file.

include 'common.inc';
require_once('page_data.inc');
require_once('testStatus.inc');
require_once INCLUDES_PATH . '/page_data.inc';
require_once INCLUDES_PATH . '/testStatus.inc';

set_time_limit(3600);

$use_median_run = false;
Expand Down
6 changes: 3 additions & 3 deletions www/archive.inc
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
// Copyright 2020 Catchpoint Systems Inc.
// Use of this source code is governed by the Polyform Shield 1.0.0 license that can be
// found in the LICENSE.md file.
require_once(__DIR__ . '/testStatus.inc');
require_once(__DIR__ . '/logging.inc');
require_once(__DIR__ . '/common_lib.inc');
require_once INCLUDES_PATH . '/testStatus.inc';
require_once INCLUDES_PATH . '/logging.inc';
require_once INCLUDES_PATH . '/common_lib.inc';
/**
* See if the file should be skipped when archiving (usually just cache files)
*
Expand Down
18 changes: 9 additions & 9 deletions www/breakdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
// Use of this source code is governed by the Polyform Shield 1.0.0 license that can be
// found in the LICENSE.md file.
include __DIR__ . '/common.inc';
require_once __DIR__ . '/breakdown.inc';
require_once __DIR__ . '/contentColors.inc';
require_once __DIR__ . '/waterfall.inc';
require_once __DIR__ . '/page_data.inc';
require_once __DIR__ . '/include/TestInfo.php';
require_once __DIR__ . '/include/TestPaths.php';
require_once __DIR__ . '/include/TestRunResults.php';
require_once __DIR__ . '/include/MimetypeBreakdownHtmlSnippet.php';
require_once __DIR__ . '/include/AccordionHtmlHelper.php';
require_once INCLUDES_PATH . '/breakdown.inc';
require_once INCLUDES_PATH . '/contentColors.inc';
require_once INCLUDES_PATH . '/waterfall.inc';
require_once INCLUDES_PATH . '/page_data.inc';
require_once INCLUDES_PATH . '/include/TestInfo.php';
require_once INCLUDES_PATH . '/include/TestPaths.php';
require_once INCLUDES_PATH . '/include/TestRunResults.php';
require_once INCLUDES_PATH . '/include/MimetypeBreakdownHtmlSnippet.php';
require_once INCLUDES_PATH . '/include/AccordionHtmlHelper.php';

$page_keywords = array('Content Breakdown','MIME Types','WebPageTest','Website Speed Test','Page Speed');
$page_description = "Website content breakdown by MIME type$testLabel";
Expand Down
10 changes: 5 additions & 5 deletions www/checkIPs.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@
$keys = array();

// load the API keys
$keys_file = __DIR__ . '/settings/keys.ini';
if (file_exists(__DIR__ . '/settings/common/keys.ini')) {
$keys_file = __DIR__ . '/settings/common/keys.ini';
$keys_file = SETTINGS_PATH . '/keys.ini';
if (file_exists(SETTINGS_PATH . '/common/keys.ini')) {
$keys_file = SETTINGS_PATH . '/common/keys.ini';
}
if (file_exists(__DIR__ . '/settings/server/keys.ini')) {
$keys_file = __DIR__ . '/settings/server/keys.ini';
if (file_exists(SETTINGS_PATH . '/server/keys.ini')) {
$keys_file = SETTINGS_PATH . '/server/keys.ini';
}
$keys = parse_ini_file($keys_file, true);

Expand Down
30 changes: 15 additions & 15 deletions www/common.inc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// found in the LICENSE.md file.

// Load app and composer-based dependencies
require_once(__DIR__ . '/../vendor/autoload.php');
require_once __DIR__ . '/../vendor/autoload.php';

use WebPageTest\Util;
use WebPageTest\User;
Expand Down Expand Up @@ -52,11 +52,11 @@ if (Util::getSetting('cp_auth')) {
}

// Load local deps
require_once(__DIR__ . '/common_lib.inc');
require_once(__DIR__ . '/plugins.php.inc');
require_once(__DIR__ . '/util.inc');
require_once INCLUDES_PATH . '/common_lib.inc';
require_once INCLUDES_PATH . '/plugins.php.inc';
require_once INCLUDES_PATH . '/util.inc';

// constants that require common_lib nand cannot be in constants.inc
// constants that require common_lib and cannot be in constants.inc
if (GetSetting('friendly_urls') || (array_key_exists('HTTP_MOD_REWRITE', $_SERVER) && $_SERVER['HTTP_MOD_REWRITE'] == 'On')) {
define('FRIENDLY_URLS', true);
define('VER_TIMELINE', '28/'); // version of the timeline javascript
Expand Down Expand Up @@ -120,7 +120,7 @@ extract($_POST, EXTR_SKIP | EXTR_PREFIX_ALL | EXTR_REFS, 'req');
extract($_GET, EXTR_SKIP | EXTR_PREFIX_ALL | EXTR_REFS, 'req');

// load dev settings
$dev_settings = __DIR__ . '/dev.php';
$dev_settings = WWW_PATH . '/dev.php';
if (file_exists($dev_settings)) {
require_once $dev_settings;
}
Expand Down Expand Up @@ -322,11 +322,11 @@ if ($supportsSaml && !$supportsCPAuth) {
* Load app specific middleware
*/
if ($supportsCPAuth) {
require_once __DIR__ . '/common/AttachClient.php';
require_once __DIR__ . '/common/AttachUser.php';
require_once __DIR__ . '/common/AttachSignupClient.php';
require_once __DIR__ . '/common/AttachBannerMessageManager.php';
require_once __DIR__ . '/common/CheckCSRF.php';
require_once INCLUDES_PATH . '/common/AttachClient.php';
require_once INCLUDES_PATH . '/common/AttachUser.php';
require_once INCLUDES_PATH . '/common/AttachSignupClient.php';
require_once INCLUDES_PATH . '/common/AttachBannerMessageManager.php';
require_once INCLUDES_PATH . '/common/CheckCSRF.php';
}

// Load the test-specific data
Expand Down Expand Up @@ -457,7 +457,7 @@ if (strlen($id)) {
if ($metaInfo['experiment'] && $metaInfo['experiment']['control'] === false) {
$experiment = true;

require_once __DIR__ . '/include/UrlGenerator.php';
require_once INCLUDES_PATH . '/include/UrlGenerator.php';

$experimentOriginalTestUrlGenerator = UrlGenerator::create(FRIENDLY_URLS, "", $metaInfo['experiment']['source_id'], 0, 0);
$experimentOriginalTestHref = $experimentOriginalTestUrlGenerator->resultSummary();
Expand Down Expand Up @@ -495,8 +495,8 @@ if (array_key_exists('medianMetric', $_REQUEST)) {
$median_metric = htmlspecialchars($_REQUEST['medianMetric']);
}

if (is_file('./settings/custom_common.inc.php')) {
include('./settings/custom_common.inc.php');
if (is_file(SETTINGS_PATH . '/custom_common.inc.php')) {
include(SETTINGS_PATH . '/custom_common.inc.php');
}

require_once __DIR__ . '/experiments/user_access.inc';
require_once INCLUDES_PATH . '/experiments/user_access.inc';
47 changes: 23 additions & 24 deletions www/common_lib.inc
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@

// Load app and composer-based dependencies
require_once(__DIR__ . '/../vendor/autoload.php');
require_once INCLUDES_PATH . '/archive.inc';
require_once INCLUDES_PATH . '/util.inc';
require_once INCLUDES_PATH . '/logging.inc';

require_once(__DIR__ . '/archive.inc');
require_once(__DIR__ . '/util.inc');

require_once(__DIR__ . '/logging.inc');
use WebPageTest\Util;
use WebPageTest\Util\Cache;

Expand Down Expand Up @@ -137,16 +136,16 @@ function GetLocationFallbacks($location)
function LoadLocationsIni()
{
$ec2_allow = GetSetting('ec2_allow');
$locations_file = __DIR__ . '/settings/locations.ini';
if (file_exists(__DIR__ . '/settings/common/locations.ini')) {
$locations_file = __DIR__ . '/settings/common/locations.ini';
$locations_file = SETTINGS_PATH . '/locations.ini';
if (file_exists(SETTINGS_PATH . '/common/locations.ini')) {
$locations_file = SETTINGS_PATH . '/common/locations.ini';
}
if (file_exists(__DIR__ . '/settings/server/locations.ini')) {
$locations_file = __DIR__ . '/settings/server/locations.ini';
if (file_exists(SETTINGS_PATH . '/server/locations.ini')) {
$locations_file = SETTINGS_PATH . '/server/locations.ini';
}
$locations = parse_ini_file($locations_file, true);
if (GetSetting('ec2_locations')) {
$ec2 = parse_ini_file(__DIR__ . '/settings/ec2_locations.ini', true);
$ec2 = parse_ini_file(SETTINGS_PATH . '/ec2_locations.ini', true);
if ($ec2 && is_array($ec2) && isset($ec2['locations'])) {
if ($locations && is_array($locations) && isset($locations['locations'])) {
// Merge the top-level locations
Expand Down Expand Up @@ -598,8 +597,8 @@ function LoadMobileDevices()
if (isset($MOBILE_DEVICES)) {
return $MOBILE_DEVICES;
}
if (is_file(__DIR__ . '/settings/mobile_devices.ini')) {
$MOBILE_DEVICES = parse_ini_file(__DIR__ . '/settings/mobile_devices.ini', true);
if (is_file(SETTINGS_PATH . '/mobile_devices.ini')) {
$MOBILE_DEVICES = parse_ini_file(SETTINGS_PATH . '/mobile_devices.ini', true);
return $MOBILE_DEVICES;
}
}
Expand Down Expand Up @@ -1564,7 +1563,7 @@ function GetDailyTestNum()
$lock = Lock("TestNum");
if ($lock) {
if (!$num) {
$filename = __DIR__ . '/dat/testnum.dat';
$filename = WWW_PATH . '/dat/testnum.dat';
$testData = array('day' => $day, 'num' => 0);
$newData = json_decode(file_get_contents($filename), true);
if (
Expand Down Expand Up @@ -2234,7 +2233,7 @@ function GetTesters($locationId, $includeOffline = false, $include_sensitive = t
}

$location = array();
$dir = __DIR__ . "/tmp/testers-$locationId";
$dir = TEMP_DIR . "/testers-$locationId";
if (is_dir($dir)) {
$now = time();
$elapsed_time = null;
Expand Down Expand Up @@ -2361,7 +2360,7 @@ function GetTesters($locationId, $includeOffline = false, $include_sensitive = t
*/
function UpdateTester($location, $tester, $testerInfo = null, $cpu = null, $error = null, $rebooted = null)
{
$dir = __DIR__ . "/tmp/testers-$location";
$dir = TEMP_DIR . "/testers-$location";
$tester_file = $dir . '/' . sha1($tester) . '.json';
if (!is_dir($dir)) {
mkdir($dir, 0777, true);
Expand Down Expand Up @@ -2458,7 +2457,7 @@ function Lock($name, $blocking = true, $maxLockSeconds = 300)
{
global $RemainingLocks;
$lock = null;
$tmpdir = __DIR__ . '/tmp';
$tmpdir = TEMP_DIR;
if (strlen($name)) {
if (!is_dir($tmpdir)) {
mkdir($tmpdir, 0777, true);
Expand Down Expand Up @@ -3761,12 +3760,12 @@ function GetServerKey()
$key = null;
}
if (!isset($key)) {
$keys_file = __DIR__ . '/settings/keys.ini';
if (file_exists(__DIR__ . '/settings/common/keys.ini')) {
$keys_file = __DIR__ . '/settings/common/keys.ini';
$keys_file = SETTINGS_PATH . '/keys.ini';
if (file_exists(SETTINGS_PATH . '/common/keys.ini')) {
$keys_file = SETTINGS_PATH . '/common/keys.ini';
}
if (file_exists(__DIR__ . '/settings/server/keys.ini')) {
$keys_file = __DIR__ . '/settings/server/keys.ini';
if (file_exists(SETTINGS_PATH . '/server/keys.ini')) {
$keys_file = SETTINGS_PATH . '/server/keys.ini';
}
$keys = parse_ini_file($keys_file, true);
if (isset($keys) && isset($keys['server']['key'])) {
Expand Down Expand Up @@ -3953,14 +3952,14 @@ function GenerateTestID($private = false, $locationShard = null)
}
$today = new DateTime("now", new DateTimeZone('UTC'));
$testId = $today->format('ymd_') . $id;
$path = __DIR__ . '/' . GetTestPath($testId);
$path = WWW_PATH . '/' . GetTestPath($testId);

// make absolutely CERTAIN that this test ID doesn't already exist
while (is_dir($path)) {
// fall back to random ID's
$id = ShardKey($test_num, $locationShard) . md5(uniqid(rand(), true));
$testId = $today->format('ymd_') . $id;
$path = __DIR__ . '/' . GetTestPath($testId);
$path = WWW_PATH . '/' . GetTestPath($testId);
}

return $testId;
Expand All @@ -3985,7 +3984,7 @@ function AddIniLine(&$ini, $key, $value)
function ProcessUploadedTest($id)
{
if (ValidateTestId($id)) {
$testPath = __DIR__ . '/' . GetTestPath($id);
$testPath = WWW_PATH . '/' . GetTestPath($id);
if (gz_is_file("$testPath/job.json")) {
$job = json_decode(gz_file_get_contents("$testPath/job.json"), true);
$test = $job;
Expand Down
2 changes: 1 addition & 1 deletion www/compare_screens.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
header("HTTP/1.0 304 Not Modified");
} else {
include 'common.inc';
$labelFont = __DIR__ . '/video/font/sourcesanspro-semibold.ttf';
$labelFont = WWW_PATH . '/video/font/sourcesanspro-semibold.ttf';
$tests = ParseTests();
if ($tests) {
$width = 0;
Expand Down
Loading

0 comments on commit f609bb2

Please sign in to comment.