Update App\Router-related tests after constructor signature change
This commit is contained in:
parent
1d0cd7328b
commit
ce04c13ea8
2 changed files with 30 additions and 13 deletions
|
@ -22,6 +22,7 @@
|
|||
namespace Friendica\Test\src\App;
|
||||
|
||||
use Friendica\App;
|
||||
use Friendica\Core\Cache\ICache;
|
||||
use Friendica\Core\Config\IConfig;
|
||||
use Friendica\Core\L10n;
|
||||
use Friendica\LegacyModule;
|
||||
|
@ -175,7 +176,11 @@ class ModuleTest extends DatabaseTest
|
|||
$l10n = \Mockery::mock(L10n::class);
|
||||
$l10n->shouldReceive('t')->andReturnUsing(function ($args) { return $args; });
|
||||
|
||||
$router = (new App\Router([], $l10n))->loadRoutes(include __DIR__ . '/../../../static/routes.config.php');
|
||||
$cache = \Mockery::mock(ICache::class);
|
||||
$cache->shouldReceive('get')->with('routerDispatchData')->andReturn('')->atMost()->once();
|
||||
$cache->shouldReceive('set')->withAnyArgs()->andReturn(false)->atMost()->once();
|
||||
|
||||
$router = (new App\Router([], __DIR__ . '/../../../static/routes.config.php', $l10n, $cache));
|
||||
|
||||
$module = (new App\Module($name))->determineClass(new App\Arguments('', $command), $router, $config);
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
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;
|
||||
|
@ -33,6 +34,10 @@ class RouterTest extends TestCase
|
|||
{
|
||||
/** @var L10n|MockInterface */
|
||||
private $l10n;
|
||||
/**
|
||||
* @var ICache
|
||||
*/
|
||||
private $cache;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
|
@ -40,11 +45,15 @@ class RouterTest extends TestCase
|
|||
|
||||
$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');
|
||||
|
@ -68,7 +77,7 @@ class RouterTest extends TestCase
|
|||
|
||||
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');
|
||||
|
@ -94,7 +103,7 @@ class RouterTest extends TestCase
|
|||
{
|
||||
$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');
|
||||
}
|
||||
|
@ -103,7 +112,7 @@ class RouterTest extends TestCase
|
|||
{
|
||||
$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');
|
||||
|
@ -115,7 +124,7 @@ class RouterTest extends TestCase
|
|||
{
|
||||
$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');
|
||||
|
@ -127,7 +136,7 @@ class RouterTest extends TestCase
|
|||
{
|
||||
$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');
|
||||
|
@ -139,7 +148,7 @@ class RouterTest extends TestCase
|
|||
{
|
||||
$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');
|
||||
|
@ -151,7 +160,7 @@ class RouterTest extends TestCase
|
|||
{
|
||||
$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');
|
||||
|
@ -189,9 +198,12 @@ class RouterTest extends TestCase
|
|||
*/
|
||||
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'));
|
||||
|
@ -206,7 +218,7 @@ class RouterTest extends TestCase
|
|||
{
|
||||
$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'));
|
||||
|
|
Loading…
Reference in a new issue