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 (array_key_exists('batch', $test['test']) && $test['test']['batch']) { $_REQUEST['f'] = 'json'; include 'resultBatch.inc'; } else { $ret = array('data' => GetTestStatus($id)); $ret['statusCode'] = $ret['data']['statusCode']; $ret['statusText'] = $ret['data']['statusText']; 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();
public function testRunDataArraySinglestepForceMultistep() { $run = $this->getTestRunResults(1); $jsonGenerator = new JsonResultGenerator($this->testInfo, "", new FileHandler(), array(), false); $jsonGenerator->forceMultistepFormat(true); $result = $jsonGenerator->runDataArray($run); $this->assertFalse(array_key_exists("TTFB", $result)); $this->assertFalse(array_key_exists("loadTime", $result)); $this->assertFalse(array_key_exists("domains", $result)); $this->assertFalse(array_key_exists("pages", $result)); $this->assertFalse(array_key_exists("rawData", $result)); $this->assertEquals("1", $result["numSteps"]); $this->assertTrue(array_key_exists(0, $result["steps"])); $this->assertEquals("1", $result["steps"][0]["id"]); $this->assertTrue(array_key_exists("eventName", $result["steps"][0])); $this->assertEquals("", $result["steps"][0]["eventName"]); $this->assertEquals("300", $result["steps"][0]["TTFB"]); $this->assertEquals("6000", $result["steps"][0]["loadTime"]); $this->assertEquals("lorem", $result["steps"][0]["foo"]); $this->assertTrue(array_key_exists("domains", $result["steps"][0])); $this->assertEquals("/screen_shot.php?test=160628_AB_C&run=2&cached=1", $result["steps"][0]["pages"]["screenShot"]); $this->assertFalse(array_key_exists(1, $result["steps"])); }