public function testJsonResultArrayGeneration() { global $SINGLESTEP_JSON_RESULT_ARRAY; $this->tempDir = TestUtil::extractToTemp(__DIR__ . '/data/singlestepResults.zip'); $testInfo = TestInfo::fromFiles($this->tempDir . '/singlestepResults'); $imitatedPath = $this->imitatedResultPath($testInfo->getId()); // we need to move the results to a directory structure that equal to the real one. // Then, we can go into the parent directory, so the relatece "testRoot" is the same as it would be in production // This is important, as during XML generation, some URLs contain the test path mkdir($this->tempDir . $imitatedPath, 0777, true); rename($this->tempDir . '/singlestepResults', $this->tempDir . $imitatedPath); $this->orgDir = getcwd(); chdir($this->tempDir); $testRoot = "." . $imitatedPath; $testInfo = TestInfo::fromFiles($testRoot); $testResults = TestResults::fromFiles($testInfo); $jsonGenerator = new JsonResultGenerator($testInfo, "http://wpt-test-vm", new FileHandler()); $resultArray = $jsonGenerator->resultDataArray($testResults, "loadTime"); $this->assertThat($resultArray, new IsArraySubsetConstraint($SINGLESTEP_JSON_RESULT_ARRAY)); }
if ($ret['statusCode'] == 200) { $protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' || isset($_SERVER['HTTP_SSL']) && $_SERVER['HTTP_SSL'] == 'On' ? 'https' : 'http'; $host = $_SERVER['HTTP_HOST']; $uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\'); $urlStart = "{$protocol}://{$host}{$uri}"; $testInfo = TestInfo::fromValues($id, $testPath, $test); $testResults = TestResults::fromFiles($testInfo); $infoFlags = getRequestInfoFlags(); $jsonResultGenerator = new JsonResultGenerator($testInfo, $urlStart, new FileHandler(), $infoFlags, FRIENDLY_URLS); if (!empty($_REQUEST["multistepFormat"])) { $jsonResultGenerator->forceMultistepFormat(true); } if (defined("VER_WEBPAGETEST")) { $ret["webPagetestVersion"] = VER_WEBPAGETEST; } $ret['data'] = $jsonResultGenerator->resultDataArray($testResults, $median_metric); ArchiveApi($id); } json_response($ret); } function getRequestInfoFlags() { $getFlags = array("average" => JsonResultGenerator::WITHOUT_AVERAGE, "standard" => JsonResultGenerator::WITHOUT_STDDEV, "median" => JsonResultGenerator::WITHOUT_MEDIAN, "runs" => JsonResultGenerator::WITHOUT_RUNS, "requests" => JsonResultGenerator::WITHOUT_REQUESTS, "console" => JsonResultGenerator::WITHOUT_CONSOLE); $infoFlags = array(); foreach ($getFlags as $key => $flag) { if (isset($_GET[$key]) && $_GET[$key] == 0) { $infoFlags[] = $flag; } } if (!empty($_REQUEST["basic"])) { $infoFlags[] = JsonResultGenerator::BASIC_INFO_ONLY;