/** @test */
 public function action_name_calls_action_method()
 {
     $routeMock = Mockery::mock(Route::class);
     $routeMock->shouldReceive('action')->once()->with('foo')->andReturn('bar');
     App::shouldReceive('make')->once()->with(Route::class)->andReturn($routeMock);
     $result = action_name('foo');
     $this->assertEquals('bar', $result);
 }
Beispiel #2
0
function show_view($view)
{
    if ($view->end_time) {
        $d = $view->end_time - $view->start_time;
        $dur = "{$d} seconds";
    } else {
        $dur = "---";
    }
    if ($view->result_id) {
        $result = BoltResult::lookup_id($view->result_id);
        $qs = str_replace("action=answer", "action=answer_page", $result->response);
        $score = number_format($result->score * 100);
        $x = "<br>Score: {$score}%\n\t\t\t<br><a href=bolt_sched.php?{$qs}>Answer page</a>";
    }
    echo "<tr>\n\t\t<td valign=top>{$view->id}</td>\n\t\t<td valign=top>" . time_str($view->start_time) . "</td>\n\t\t<td valign=top>{$dur}</td>\n\t\t<td valign=top>{$view->item_name}</td>\n\t\t<td valign=top>" . mode_name($view->mode) . " {$x}</td>\n\t";
    //<td valign=top>".phase_name($view->phase)."</td>
    echo "\n\t\t<td valign=top>" . action_name($view->action) . "</td>\n\t\t</tr>\n\t";
}
Beispiel #3
0
 function match($url)
 {
     # add defaults
     $out = $this->defaults;
     # grab out the query string if there is one
     if (strpos($url, '?') !== false) {
         $query = explode('?', $url);
         $url = $query[0];
         $query = $query[1];
         $qparams = array();
         parse_str($query, $qparams);
         foreach ($qparams as $k => $v) {
             $out[$k] = $v;
         }
     }
     # make sure they match
     $urlparts = array();
     if (!preg_match($this->regex, $url, $urlparts)) {
         return false;
     }
     # if we're at / return defaults
     // if ($url == '/') {
     // 	if (!array_key_exists('controller', $out)) $out['controller'] = 'index';
     // 	return $out;
     // }
     # moved this up
     # add defaults
     #$out = $this->defaults;
     # map it
     $parts = explode('/', $this->usermap);
     array_shift($parts);
     array_shift($urlparts);
     foreach ($parts as $k => $v) {
         # if it's a placeholder
         if (empty($v)) {
             continue;
         }
         if ($v[0] == ':' || $v[0] == '*') {
             $name = substr($v, 1);
             # get the value
             if (array_key_exists($k, $urlparts) && $urlparts[$k] != '') {
                 $out[$name] = $urlparts[$k];
             }
             # handle controller a little different
             if ($name == 'controller') {
                 # can't be NULL
                 if (is_null($out[$name])) {
                     return false;
                 }
                 # if the requirement hasn't been overridden, make sure the
                 # class is available
                 if (array_key_exists($name, $this->requirements)) {
                     if (function_exists($this->requirements[$name])) {
                         if (!$this->requirements[$name]($out[$name])) {
                             return false;
                         }
                     } else {
                         if (!preg_match($this->requirements[$name], $out[$name])) {
                             return false;
                         }
                     }
                 }
             } else {
                 # if there is a requirement for this,
                 # and it isn't NULL
                 if (array_key_exists($name, $this->requirements) && !is_null($out[$name])) {
                     # if the req is a function, call it and pass the value,
                     # otherwise assume it's a regex
                     if (function_exists($this->requirements[$name])) {
                         if (!$this->requirements[$name]($out[$name])) {
                             return false;
                         }
                     } else {
                         if (!preg_match($this->requirements[$name], $out[$name])) {
                             return false;
                         }
                     }
                 }
             }
             # clear nulls
             if (is_null($out[$name])) {
                 unset($out[$name]);
             }
         }
     }
     # if no action is set, set it to the default
     if (!array_key_exists('action', $out)) {
         $out['action'] = $this->defaults['action'];
     }
     $out['action'] = action_name($out['action']);
     return $out;
 }