+
+ /**
+ * Test changeSeparator to '#': redirection + success message.
+ */
+ public function testChangeSeparatorValid(): void
+ {
+ $toSeparator = '#';
+
+ $session = [];
+ $this->assignSessionVars($session);
+
+ $request = $this->createMock(Request::class);
+ $request
+ ->expects(static::atLeastOnce())
+ ->method('getParam')
+ ->willReturnCallback(function (string $key) use ($toSeparator): ?string {
+ return $key === 'separator' ? $toSeparator : $key;
+ })
+ ;
+ $response = new Response();
+
+ $this->container->conf
+ ->expects(static::once())
+ ->method('set')
+ ->with('general.tags_separator', $toSeparator, true, true)
+ ;
+
+ $result = $this->controller->changeSeparator($request, $response);
+
+ static::assertSame(302, $result->getStatusCode());
+ static::assertSame(['/subfolder/admin/tags'], $result->getHeader('location'));
+
+ static::assertArrayNotHasKey(SessionManager::KEY_ERROR_MESSAGES, $session);
+ static::assertArrayNotHasKey(SessionManager::KEY_WARNING_MESSAGES, $session);
+ static::assertArrayHasKey(SessionManager::KEY_SUCCESS_MESSAGES, $session);
+ static::assertSame(
+ ['Your tags separator setting has been updated!'],
+ $session[SessionManager::KEY_SUCCESS_MESSAGES]
+ );
+ }
+
+ /**
+ * Test changeSeparator to '#@' (too long): redirection + error message.
+ */
+ public function testChangeSeparatorInvalidTooLong(): void
+ {
+ $toSeparator = '#@';
+
+ $session = [];
+ $this->assignSessionVars($session);
+
+ $request = $this->createMock(Request::class);
+ $request
+ ->expects(static::atLeastOnce())
+ ->method('getParam')
+ ->willReturnCallback(function (string $key) use ($toSeparator): ?string {
+ return $key === 'separator' ? $toSeparator : $key;
+ })
+ ;
+ $response = new Response();
+
+ $this->container->conf->expects(static::never())->method('set');
+
+ $result = $this->controller->changeSeparator($request, $response);
+
+ static::assertSame(302, $result->getStatusCode());
+ static::assertSame(['/subfolder/admin/tags'], $result->getHeader('location'));
+
+ static::assertArrayNotHasKey(SessionManager::KEY_SUCCESS_MESSAGES, $session);
+ static::assertArrayNotHasKey(SessionManager::KEY_WARNING_MESSAGES, $session);
+ static::assertArrayHasKey(SessionManager::KEY_ERROR_MESSAGES, $session);
+ static::assertSame(
+ ['Tags separator must be a single character.'],
+ $session[SessionManager::KEY_ERROR_MESSAGES]
+ );
+ }
+
+ /**
+ * Test changeSeparator to '#@' (too long): redirection + error message.
+ */
+ public function testChangeSeparatorInvalidReservedCharacter(): void
+ {
+ $toSeparator = '*';
+
+ $session = [];
+ $this->assignSessionVars($session);
+
+ $request = $this->createMock(Request::class);
+ $request
+ ->expects(static::atLeastOnce())
+ ->method('getParam')
+ ->willReturnCallback(function (string $key) use ($toSeparator): ?string {
+ return $key === 'separator' ? $toSeparator : $key;
+ })
+ ;
+ $response = new Response();
+
+ $this->container->conf->expects(static::never())->method('set');
+
+ $result = $this->controller->changeSeparator($request, $response);
+
+ static::assertSame(302, $result->getStatusCode());
+ static::assertSame(['/subfolder/admin/tags'], $result->getHeader('location'));
+
+ static::assertArrayNotHasKey(SessionManager::KEY_SUCCESS_MESSAGES, $session);
+ static::assertArrayNotHasKey(SessionManager::KEY_WARNING_MESSAGES, $session);
+ static::assertArrayHasKey(SessionManager::KEY_ERROR_MESSAGES, $session);
+ static::assertStringStartsWith(
+ 'These characters are reserved and can\'t be used as tags separator',
+ $session[SessionManager::KEY_ERROR_MESSAGES][0]
+ );
+ }