X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=tests%2Ffront%2Fcontroller%2Fvisitor%2FFrontControllerMockHelper.php;h=6c53289bd01c83ba018003e2bf4dc32a27da1139;hb=98e7a59ca21b51cbd86d09cd5d217c0c8bf3db77;hp=bc3266b5ce2409ee80bbc072ef88877e3052d16c;hpb=2899ebb5b5e82890c877151f5c02045266ac9973;p=github%2Fshaarli%2FShaarli.git diff --git a/tests/front/controller/visitor/FrontControllerMockHelper.php b/tests/front/controller/visitor/FrontControllerMockHelper.php index bc3266b5..6c53289b 100644 --- a/tests/front/controller/visitor/FrontControllerMockHelper.php +++ b/tests/front/controller/visitor/FrontControllerMockHelper.php @@ -31,24 +31,18 @@ trait FrontControllerMockHelper protected $container; /** - * Mock the container instance + * Mock the container instance and initialize container's services used by tests */ protected function createContainer(): void { $this->container = $this->createMock(ShaarliTestContainer::class); - } - /** - * Initialize container's services used by tests - */ - protected function createValidContainerMockSet(): void - { $this->container->loginManager = $this->createMock(LoginManager::class); // Config $this->container->conf = $this->createMock(ConfigManager::class); $this->container->conf->method('get')->willReturnCallback(function (string $parameter, $default) { - return $default; + return $default === null ? $parameter : $default; }); // PageBuilder @@ -85,8 +79,12 @@ trait FrontControllerMockHelper $this->container->environment = [ 'SERVER_NAME' => 'shaarli', 'SERVER_PORT' => '80', - 'REQUEST_URI' => '/daily-rss', + 'REQUEST_URI' => '/subfolder/daily-rss', + 'REMOTE_ADDR' => '1.2.3.4', + 'SCRIPT_NAME' => '/subfolder/index.php', ]; + + $this->container->basePath = '/subfolder'; } /** @@ -97,7 +95,6 @@ trait FrontControllerMockHelper protected function assignTemplateVars(array &$variables): void { $this->container->pageBuilder - ->expects(static::atLeastOnce()) ->method('assign') ->willReturnCallback(function ($key, $value) use (&$variables) { $variables[$key] = $value; @@ -107,6 +104,14 @@ trait FrontControllerMockHelper ; } + protected static function generateString(int $length): string + { + // bin2hex(random_bytes) generates string twice as long as given parameter + $length = (int) ceil($length / 2); + + return bin2hex(random_bytes($length)); + } + /** * Force to be used in PHPUnit context. */