/** * Get list of jobs with parameters for current test suit * * @return Job[] */ protected function getJobs() { $jobs = []; $r = new \Nette\Reflection\ClassType(get_class($this)); $methods = array_values(preg_grep(static::METHOD_PATTERN, array_map(function (\ReflectionMethod $rm) { return $rm->getName(); }, $r->getMethods()))); foreach ($methods as $method) { $rm = $r->getMethod($method); $data = NULL; $job = ["name" => $this->getJobName($rm), "callback" => [$this, $method], "params" => [], "skip" => $this->checkSkip($rm), "shouldFail" => $rm->hasAnnotation("fail")]; if ($rm->getNumberOfParameters() and $rm->hasAnnotation("data")) { $data = (array) $rm->getAnnotation("data"); } if (is_array($data)) { foreach ($data as $value) { $job["params"][0] = $value; $jobs[] = new Job($job["name"], $job["callback"], $job["params"], $job["skip"], $job["shouldFail"]); $job["params"] = []; } } else { $jobs[] = new Job($job["name"], $job["callback"], $job["params"], $job["skip"], $job["shouldFail"]); } } return $jobs; }
/** * @param string destination in format "[[module:]presenter:]action" or "signal!" or "this" * @param array|mixed * @return bool */ public function isAuthorized($destination) { if ($destination == 'this') { $class = get_class($this); $action = $this->action; } elseif (substr($destination, -1, 1) == '!') { $class = get_class($this); $action = $this->action; $do = substr($destination, 0, -1); } elseif (ctype_lower(substr($destination, 0, 1))) { $class = get_class($this); $action = $destination; } else { if (substr($destination, 0, 1) === ':') { $link = substr($destination, 1); $link = substr($link, 0, strrpos($link, ':')); $action = substr($destination, strrpos($destination, ':') + 1); } else { $link = substr($this->name, 0, strrpos($this->name, ':')); $link = $link . ($link ? ':' : '') . substr($destination, 0, strrpos($destination, ':')); $action = substr($destination, strrpos($destination, ':') + 1); } $action = $action ?: 'default'; $presenterFactory = $this->getApplication()->getPresenterFactory(); $class = $presenterFactory->getPresenterClass($link); } $schema = $this->controlVerifier->getControlVerifierReader()->getSchema($class); if (isset($schema['action' . ucfirst($action)])) { $classReflection = new \Nette\Reflection\ClassType($class); $method = $classReflection->getMethod('action' . ucfirst($action)); try { $this->controlVerifier->checkRequirements($method); } catch (ForbiddenRequestException $e) { return FALSE; } } if (isset($do) && isset($schema['handle' . ucfirst($do)])) { $classReflection = new \Nette\Reflection\ClassType($class); $method = $classReflection->getMethod('handle' . ucfirst($do)); try { $this->controlVerifier->checkRequirements($method); } catch (ForbiddenRequestException $e) { return FALSE; } } return TRUE; }
private function renderTestResult($testClass, $test_results) { $outputsNumber = 0; // vykreslení tabulky s testy ob_start(); $results = array('Total' => 0, 'Pass' => 0, 'Fail' => 0, 'Error' => 0, 'NRY' => 0, 'Skip' => 0); $classAnnotation = new \Nette\Reflection\ClassType($testClass); ?> <table cellspacing="0" class="test_results" border=1> <thead> <tr><th>Result</th><th>Name</th><th title="count of assertions">Asserts<br>Count</th><th title="msec">Time<br>in ms</th><th>Output</th></tr> </thead> <tbody> <?php foreach ($test_results as $test_result) { if (!is_array($test_result) || !isset($test_result['result'])) { continue; } $result = $test_result['result']; if (!isset($results[$result])) { echo "Unknown result type \"{$result}\", please modify MyTestRunner.php"; $results[$result] = 0; } $results[$result]++; $results['Total']++; ?> <tr> <?php if ($test_result['result'] === 'Fail') { ?> <td class="result test_fail"/><?php echo strtoupper($test_result['result']); ?> </td> <?php } elseif ($test_result['result'] == 'Pass') { ?> <td class="result test_pass"/><?php echo strtoupper($test_result['result']); ?> </td> <?php } else { ?> <td class="result test_other"/><?php echo strtoupper($test_result['result']); ?> </td> <?php } ?> <td style="text-align:left;"><?php $cmethod = $methodName = $test_result['name']; if (strpos($methodName, ' ')) { $cmethod = substr($methodName, 0, strpos($methodName, ' ')); } $method = $classAnnotation->getMethod($cmethod); $editLink = $this->createEditLink($method->fileName, $method->startLine); echo "<a title=\"{$method}\" href=\"{$editLink}\">" . $this->translateTestName($methodName) . "</a>"; ?> <?php if ($test_result['message']) { $message = trim($test_result['message']); $message = $this->enhanceMessageWithLinks($message); $this->displayPreMessage($message); } ?> </td> <td> <?php echo $test_result['assertions']; ?> </td> <td> <?php echo round(1000 * $test_result['time'], 1); ?> </td> <?php if (isset($test_result['output'])) { $output = $test_result['output']; if (!empty($output)) { $outputsNumber++; } } else { $output = ''; } ?> <td class="output"><?php $this->displayPreMessage($output); ?> </td> </tr> <?php } ?> </tbody> </table> <?php $table = ob_get_clean(); //vykreslení hlavičky testu $fileName = $classAnnotation->fileName; $editLink = $this->createEditLink($fileName); if ($results['Total'] !== $results['Pass'] + $results['NRY'] + $results['Skip']) { $errtxt = $results['Fail'] === 0 ? 'ERRORS' : 'FAILED'; $cssClass = "fail"; $cssStyle = "color:red;font-weight:bold;"; $display = "block"; } else { $errtxt = "PASSED"; $cssClass = "passed"; $cssStyle = "color:green;font-weight:bold;"; $display = "none"; } $detail = "{$results['Total']}<span style=\"color:green\"> / {$results['Pass']}<span> / <span style=\"color:red\">{$results['Fail']}</span>"; $detail .= "<span style=\"color:black\">"; if ($results['Skip'] > 0) { $detail .= " Skipped: {$results['Skip']}"; } if ($results['NRY'] > 0) { $detail .= " / {$results['NRY']}"; } $detail .= "</span>"; $htmlClass = str_replace('\\', '-', $testClass); echo "<div class=\"{$cssClass}\">"; //class links $this->renderClassHeader($classAnnotation); //result numbers echo "<span style=\"{$cssStyle}\">  {$errtxt} </span> {$detail} "; if ($outputsNumber > 0) { echo "<span class=\"outputs\">tests with output: <span style=\"color:yellow;\">{$outputsNumber}</span></span>"; //$display =' block'; } //collapsing echo "<a href=\"#\" onClick=\"javascript:return toggle('{$htmlClass}');\">►</a>"; echo "</div>"; echo "<div style=\"display:{$display}\"id=\"{$htmlClass}\">{$table}</div>"; return $results; }