Exemple #1
0
function routeIn(Nette\Application\IRouter $route, $url, $expectedPresenter = NULL, $expectedParams = NULL, $expectedUrl = NULL, $scriptPath = NULL)
{
    $url = new Nette\Http\UrlScript("http://example.com{$url}");
    if ($scriptPath) {
        $url->setScriptPath($scriptPath);
    }
    if ($url->getQueryParameter('presenter') === NULL) {
        $url->setQueryParameter('presenter', 'querypresenter');
    }
    $url->appendQuery(['test' => 'testvalue']);
    $httpRequest = new Nette\Http\Request($url);
    $request = $route->match($httpRequest);
    if ($request) {
        // matched
        $params = $request->getParameters();
        asort($params);
        asort($expectedParams);
        Assert::same($expectedPresenter, $request->getPresenterName());
        Assert::same($expectedParams, $params);
        $result = $route->constructUrl($request, $url);
        Assert::same($expectedUrl, $result);
    } else {
        // not matched
        Assert::null($expectedPresenter);
    }
}
Exemple #2
0
 /**
  * @return \TestPresenter
  */
 private function createPresenter()
 {
     $url = new \Nette\Http\UrlScript('http://localhost/');
     $url->setScriptPath('/');
     $configurator = new \Nette\Config\Configurator();
     $configurator->addConfig(__DIR__ . '/config.neon');
     \Nella\Doctrine\Config\Extension::register($configurator);
     $container = $configurator->setTempDirectory(TEMP_DIR)->createContainer();
     $container->removeService('httpRequest');
     $container->addService('httpRequest', new \Nette\Http\Request($url));
     $application = $container->getService('application');
     $application->router[] = new \Nette\Application\Routers\SimpleRouter();
     $presenter = new TestPresenter($container);
     $presenter->invalidLinkMode = $presenter::INVALID_LINK_WARNING;
     $presenter->autoCanonicalize = FALSE;
     return $presenter;
 }
Exemple #3
0
 /**
  * @return \TestPresenter
  */
 private function createPresenter()
 {
     $url = new \Nette\Http\UrlScript('http://localhost/');
     $url->setScriptPath('/');
     $configurator = new \Nette\Configurator();
     $configurator->addConfig(__DIR__ . '/config.neon');
     \Kdyby\Events\DI\EventsExtension::register($configurator);
     \Kdyby\Annotations\DI\AnnotationsExtension::register($configurator);
     \Kdyby\Doctrine\DI\OrmExtension::register($configurator);
     $container = $configurator->setTempDirectory(TEMP_DIR)->createContainer();
     $container->removeService('httpRequest');
     $container->addService('httpRequest', new \Nette\Http\Request($url));
     $router = $container->getByType(\Nette\Application\IRouter::class);
     $router[] = new \Nette\Application\Routers\Route('<presenter>/<action>[/<id>]', 'Dashboard:default');
     $presenter = new TestPresenter($container);
     $container->callInjects($presenter);
     $presenter->invalidLinkMode = $presenter::INVALID_LINK_WARNING;
     $presenter->autoCanonicalize = FALSE;
     return $presenter;
 }