namespace Friendica\Test\src\App;
use Friendica\App\Router;
+use Friendica\Core\Cache\ICache;
use Friendica\Core\L10n;
use Friendica\Module;
use Friendica\Network\HTTPException\MethodNotAllowedException;
{
/** @var L10n|MockInterface */
private $l10n;
+ /**
+ * @var ICache
+ */
+ private $cache;
protected function setUp()
{
$this->l10n = \Mockery::mock(L10n::class);
$this->l10n->shouldReceive('t')->andReturnUsing(function ($args) { return $args; });
+
+ $this->cache = \Mockery::mock(ICache::class);
+ $this->cache->shouldReceive('get')->andReturn(null);
+ $this->cache->shouldReceive('set')->andReturn(false);
}
public function testGetModuleClass()
{
- $router = new Router(['REQUEST_METHOD' => Router::GET], $this->l10n);
+ $router = new Router(['REQUEST_METHOD' => Router::GET], '', $this->l10n, $this->cache);
$routeCollector = $router->getRouteCollector();
$routeCollector->addRoute([Router::GET], '/', 'IndexModuleClassName');
public function testPostModuleClass()
{
- $router = new Router(['REQUEST_METHOD' => Router::POST], $this->l10n);
+ $router = new Router(['REQUEST_METHOD' => Router::POST], '', $this->l10n, $this->cache);
$routeCollector = $router->getRouteCollector();
$routeCollector->addRoute([Router::POST], '/', 'IndexModuleClassName');
{
$this->expectException(NotFoundException::class);
- $router = new Router(['REQUEST_METHOD' => Router::GET], $this->l10n);
+ $router = new Router(['REQUEST_METHOD' => Router::GET], '', $this->l10n, $this->cache);
$router->getModuleClass('/unsupported');
}
{
$this->expectException(NotFoundException::class);
- $router = new Router(['REQUEST_METHOD' => Router::GET], $this->l10n);
+ $router = new Router(['REQUEST_METHOD' => Router::GET], '', $this->l10n, $this->cache);
$routeCollector = $router->getRouteCollector();
$routeCollector->addRoute([Router::GET], '/test', 'TestModuleClassName');
{
$this->expectException(NotFoundException::class);
- $router = new Router(['REQUEST_METHOD' => Router::GET], $this->l10n);
+ $router = new Router(['REQUEST_METHOD' => Router::GET], '', $this->l10n, $this->cache);
$routeCollector = $router->getRouteCollector();
$routeCollector->addRoute([Router::GET], '/optional[/option]', 'OptionalModuleClassName');
{
$this->expectException(NotFoundException::class);
- $router = new Router(['REQUEST_METHOD' => Router::GET], $this->l10n);
+ $router = new Router(['REQUEST_METHOD' => Router::GET], '', $this->l10n, $this->cache);
$routeCollector = $router->getRouteCollector();
$routeCollector->addRoute([Router::GET], '/variable/{var}', 'VariableModuleClassName');
{
$this->expectException(MethodNotAllowedException::class);
- $router = new Router(['REQUEST_METHOD' => Router::POST], $this->l10n);
+ $router = new Router(['REQUEST_METHOD' => Router::POST], '', $this->l10n, $this->cache);
$routeCollector = $router->getRouteCollector();
$routeCollector->addRoute([Router::GET], '/test', 'TestModuleClassName');
{
$this->expectException(MethodNotAllowedException::class);
- $router = new Router(['REQUEST_METHOD' => Router::GET], $this->l10n);
+ $router = new Router(['REQUEST_METHOD' => Router::GET], '', $this->l10n, $this->cache);
$routeCollector = $router->getRouteCollector();
$routeCollector->addRoute([Router::POST], '/test', 'TestModuleClassName');
*/
public function testGetRoutes(array $routes)
{
- $router = (new Router([
- 'REQUEST_METHOD' => Router::GET
- ], $this->l10n))->loadRoutes($routes);
+ $router = (new Router(
+ ['REQUEST_METHOD' => Router::GET],
+ '',
+ $this->l10n,
+ $this->cache
+ ))->loadRoutes($routes);
$this->assertEquals(Module\Home::class, $router->getModuleClass('/'));
$this->assertEquals(Module\Friendica::class, $router->getModuleClass('/group/route'));
{
$router = (new Router([
'REQUEST_METHOD' => Router::POST
- ], $this->l10n))->loadRoutes($routes);
+ ], '', $this->l10n, $this->cache))->loadRoutes($routes);
// Don't find GET
$this->assertEquals(Module\NodeInfo::class, $router->getModuleClass('/post/it'));