public static function getLogoutFormFieldsHtml(TestSwarmContext $context) { $db = $context->getDB(); $request = $context->getRequest(); $userName = $request->getSessionData('username'); $userAuthToken = $db->getOne(str_queryf('SELECT auth FROM users WHERE name = %s', $userName)); return '<input type="hidden" name="authUsername" value="' . htmlspecialchars($userName) . '">' . '<input type="hidden" name="authToken" value="' . htmlspecialchars($userAuthToken) . '">'; }
/** * Creates a Database object, opens the connection and returns the instance. * * @param context TestSwarmContext * @param $connType int: [optional] */ public static function newFromContext(TestSwarmContext $context, $connType = SWARM_DBCON_DEFAULT) { $dbConf = $context->getConf()->database; $db = new self(); $db->context = $context; $db->host = $dbConf->host; $db->username = $dbConf->username; $db->password = $dbConf->password; $db->dbname = $dbConf->database; $db->open($connType); return $db; }
$swarmConfig->storage->cacheDir = str_replace("\$1", $swarmInstallDir, $swarmConfig->storage->cacheDir); // Caching directory must exist and be writable if (!is_dir($swarmConfig->storage->cacheDir) || !is_writable($swarmConfig->storage->cacheDir)) { echo "<b>TestSwarm Fatal</b>: Caching directory must exist and be writable by the script!\n"; exit; } // Refresh control // The value in settings file is for changes by the local administrator. // this one is for internal changes, e.g. to be increased when for example // ./js/run.js changes significantly. $refresh_control = 3; // 2012-05-07 $swarmConfig->client->refresh_control += $refresh_control; /**@}*/ /** * Context * @{ */ $swarmContext = new TestSwarmContext($swarmConfig); /**@}*/ /** * Custom settings * @{ */ if ($swarmContext->getConf()->debug->phpErrorReporting) { error_reporting(E_ALL); ini_set("display_errors", 1); } // Increase the session timeout to two weeks (3600 * 24 * 14) ini_set('session.gc_maxlifetime', '1209600'); /**@}*/
public static final function newFromContext(TestSwarmContext $context) { // self refers to the origin class (abstract Page) // static refers to the current class (FoobarPage) $page = new static(); $page->context = $context; $versionInfo = $context->getVersionInfo(); $page->metaTags[] = array("name" => "generator", "content" => $versionInfo['TestSwarm']); return $page; }
public static function validateRunToken(TestSwarmContext $context, $runToken) { $conf = $context->getConf(); if (!$conf->client->requireRunToken) { return true; } $cacheFile = $conf->storage->cacheDir . "/run_token_hash.cache"; if (!is_readable($cacheFile)) { throw new SwarmException("Configuration requires a runToken but none has been configured."); } $runTokenHash = trim(file_get_contents($cacheFile)); if ($runTokenHash === sha1($runToken)) { return true; } throw new SwarmException("This TestSwarm requires a run token. Either none was entered or it is invalid."); }
/** * Iterate over all run rows and aggregate the runs and user agents. * @return Array List of runs and userAgents. */ public static function getDataFromRunRows(TestSwarmContext $context, $runRows) { $db = $context->getDB(); $userAgentIDs = array(); $runs = array(); foreach ($runRows as $runRow) { $runInfo = array('id' => $runRow->id, 'name' => $runRow->name, 'url' => $runRow->url); $runUaRuns = array(); // Get list of useragents that this run is scheduled for $runUaRows = $db->getRows(str_queryf('SELECT status, useragent_id, results_id FROM run_useragent WHERE run_useragent.run_id = %u;', $runRow->id)); if ($runUaRows) { foreach ($runUaRows as $runUaRow) { // Add UA ID to the list. After we've collected // all the UA IDs we'll perform one query for all of them // to gather the info from the useragents table $userAgentIDs[] = $runUaRow->useragent_id; if (!$runUaRow->results_id) { $runUaRuns[$runUaRow->useragent_id] = array('runStatus' => 'new'); } else { $runresultsRow = $db->getRow(str_queryf('SELECT id, client_id, status, total, fail, error FROM runresults WHERE id = %u;', $runUaRow->results_id)); if (!$runresultsRow) { $this->setError('data-corrupt'); return; } $runUaRuns[$runUaRow->useragent_id] = array('useragentID' => $runUaRow->useragent_id, 'clientID' => $runresultsRow->client_id, 'failedTests' => $runresultsRow->fail, 'totalTests' => $runresultsRow->total, 'errors' => $runresultsRow->error, 'runStatus' => self::getRunresultsStatus($runresultsRow), 'runResultsUrl' => swarmpath('result/' . $runUaRow->results_id), 'runResultsLabel' => $runresultsRow->status != ResultAction::$STATE_FINISHED ? '' : ($runresultsRow->error > 0 ? $runresultsRow->error : ($runresultsRow->fail > 0 ? $runresultsRow->fail : $runresultsRow->total))); } } uksort($runUaRuns, array($context->getBrowserInfo(), 'sortUaId')); $runs[] = array('info' => $runInfo, 'uaRuns' => $runUaRuns); } } // Get information for all encounted useragents $browserIndex = BrowserInfo::getBrowserIndex(); $userAgents = array(); foreach ($userAgentIDs as $uaID) { if (!isset($browserIndex->{$uaID})) { // If it isn't in the index anymore, it means it has been removed from the browserSets // configuration. Use a generic fallback object; $userAgents[$uaID] = BrowserInfo::makeGenericUaData($uaID); } else { $userAgents[$uaID] = (array) $browserIndex->{$uaID}; } } uasort($userAgents, 'BrowserInfo::sortUaData'); return array('runs' => $runs, 'userAgents' => $userAgents); }
public static function getMaxAge(TestSwarmContext $context) { $conf = $context->getConf(); return time() - ($conf->client->pingTime + $conf->client->pingTimeMargin); }