Skip to content

Commit c5746e9

Browse files
committed
fix: corrected URL schemes
1 parent a938b6d commit c5746e9

22 files changed

+138
-212
lines changed

phpmyfaq/assets/templates/default/open-questions.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121
</td>
2222
{% if isCloseQuestionEnabled and question.answerId > 0 %}
2323
<td class="text-end">
24-
<a class="btn btn-primary" href="?action=faq&cat={{ question.categoryId }}&id={{ question.answerId }}">
24+
<a class="btn btn-primary" href="./content/{{ question.categoryId }}/{{ question.answerId }}/{{ question.lang }}/{{ question.slug }}.html">
2525
{{ msg2answerFAQ }}
2626
</a>
2727
</td>
2828
{% elseif userHasPermissionToAnswer %}
2929
<td class="text-end">
30-
<a class="btn btn-primary" href="?action=add&question={{ question.id }}&cat={{ question.categoryId }}">
30+
<a class="btn btn-primary" href="./add-faq.html?question={{ question.id }}&cat={{ question.categoryId }}">
3131
{{ msg2answer }}
3232
</a>
3333
</td>

phpmyfaq/src/phpMyFAQ/Controller/Administration/FaqController.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
use phpMyFAQ\Filter;
3434
use phpMyFAQ\Helper\LanguageHelper;
3535
use phpMyFAQ\Link;
36+
use phpMyFAQ\Link\Util\TitleSlugifier;
3637
use phpMyFAQ\Question;
3738
use phpMyFAQ\Session\Token;
3839
use phpMyFAQ\Translation;
@@ -284,16 +285,14 @@ public function edit(Request $request): Response
284285
$revisions = $faqRevision->get($faqId, $faqLanguage, $faqData['author']);
285286

286287
$faqUrl = sprintf(
287-
'%sindex.php?action=faq&cat=%s&id=%d&artlang=%s',
288+
'%scontent/%d/%d/%s/%s.html',
288289
$this->configuration->getDefaultUrl(),
289290
$category->getCategoryIdFromFaq($faqId),
290291
$faqId,
291292
$faqLanguage,
293+
TitleSlugifier::slug($faqData['title']),
292294
);
293295

294-
$link = new Link($faqUrl, $this->configuration);
295-
$link->setTitle($faqData['title']);
296-
297296
// User permissions
298297
$userPermission = $this->container->get(id: 'phpmyfaq.faq.permission')->get(Permission::USER, $faqId);
299298
if (count($userPermission) === 0 || $userPermission[0] === -1) {
@@ -334,7 +333,7 @@ public function edit(Request $request): Response
334333
'selectedRevisionId' => $selectedRevisionId ?? $faqData['revision_id'],
335334
'faqRevisionId' => $faqData['revision_id'],
336335
'faqData' => $faqData,
337-
'faqUrl' => $link->toString(),
336+
'faqUrl' => $faqUrl,
338337
'openQuestionId' => 0,
339338
'notifyUser' => '',
340339
'notifyEmail' => '',

phpmyfaq/src/phpMyFAQ/Helper/FaqHelper.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
use phpMyFAQ\Faq;
3131
use phpMyFAQ\Language\LanguageCodes;
3232
use phpMyFAQ\Link;
33+
use phpMyFAQ\Link\Util\TitleSlugifier;
3334
use phpMyFAQ\Utils;
3435
use Symfony\Component\HtmlSanitizer\HtmlSanitizer;
3536
use Symfony\Component\HtmlSanitizer\HtmlSanitizerConfig;
@@ -105,11 +106,12 @@ public function createOverview(Category $category, Faq $faq, string $language =
105106
public function createFaqUrl(FaqEntity $faqEntity, int $categoryId): string
106107
{
107108
return sprintf(
108-
'%s?action=faq&cat=%d&id=%d&artlang=%s',
109-
$this->configuration->getDefaultUrl() . 'index.php',
109+
'%scontent/%d/%d/%s/%s.html',
110+
$this->configuration->getDefaultUrl(),
110111
$categoryId,
111112
$faqEntity->getId(),
112113
$faqEntity->getLanguage(),
114+
TitleSlugifier::slug($faqEntity->getQuestion()),
113115
);
114116
}
115117

phpmyfaq/src/phpMyFAQ/Helper/QuestionHelper.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use phpMyFAQ\Date;
2525
use phpMyFAQ\Language\Plurals;
2626
use phpMyFAQ\Link;
27+
use phpMyFAQ\Link\Util\TitleSlugifier;
2728
use phpMyFAQ\Mail;
2829
use phpMyFAQ\Search\SearchResultSet;
2930
use phpMyFAQ\Utils;
@@ -100,13 +101,15 @@ public function getOpenQuestions(): stdClass
100101
while ($row = $this->configuration->getDb()->fetchObject($result)) {
101102
$question = new stdClass();
102103
$question->id = $row->id;
104+
$question->lang = $row->lang;
103105
$question->date = $date->format(Date::createIsoDate($row->created));
104106
$question->email = $mail->safeEmail($row->email);
105107
$question->userName = $row->username;
106108
$question->categoryId = $row->category_id;
107109
$question->categoryName = $this->getCategory()->getCategoryName((int) $row->category_id);
108110
$question->question = $row->question;
109111
$question->answerId = $row->answer_id;
112+
$question->slug = TitleSlugifier::slug($question->question);
110113

111114
$openQuestions->questions[] = $question;
112115
}

tests/phpMyFAQ/ApplicationTest.php

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,7 @@ public function testHandleRequestResourceNotFoundException(): void
185185
public function testHandleRequestUnauthorizedHttpExceptionForApi(): void
186186
{
187187
$configuration = $this->createMock(Configuration::class);
188-
$configuration
189-
->method('getDefaultUrl')
190-
->willReturn('https://localhost');
188+
$configuration->method('getDefaultUrl')->willReturn('https://localhost');
191189

192190
$this->container
193191
->method('get')
@@ -374,7 +372,7 @@ public function testCreateProblemDetailsResponseFor404(): void
374372
$request,
375373
Response::HTTP_NOT_FOUND,
376374
$exception,
377-
'The requested resource was not found.'
375+
'The requested resource was not found.',
378376
);
379377

380378
$this->assertInstanceOf(Response::class, $response);
@@ -412,7 +410,7 @@ public function testCreateProblemDetailsResponseFor400(): void
412410
$request,
413411
Response::HTTP_BAD_REQUEST,
414412
$exception,
415-
'Bad request.'
413+
'Bad request.',
416414
);
417415

418416
$content = json_decode($response->getContent(), true);
@@ -445,7 +443,7 @@ public function testCreateProblemDetailsResponseFor401(): void
445443
$request,
446444
Response::HTTP_UNAUTHORIZED,
447445
$exception,
448-
'Unauthorized.'
446+
'Unauthorized.',
449447
);
450448

451449
$content = json_decode($response->getContent(), true);
@@ -473,13 +471,7 @@ public function testCreateProblemDetailsResponseFor403(): void
473471
$reflection = new ReflectionClass(Application::class);
474472
$method = $reflection->getMethod('createProblemDetailsResponse');
475473

476-
$response = $method->invoke(
477-
$this->application,
478-
$request,
479-
Response::HTTP_FORBIDDEN,
480-
$exception,
481-
'Forbidden.'
482-
);
474+
$response = $method->invoke($this->application, $request, Response::HTTP_FORBIDDEN, $exception, 'Forbidden.');
483475

484476
$content = json_decode($response->getContent(), true);
485477
$this->assertEquals('https://localhost/problems/forbidden', $content['type']);
@@ -511,7 +503,7 @@ public function testCreateProblemDetailsResponseFor500(): void
511503
$request,
512504
Response::HTTP_INTERNAL_SERVER_ERROR,
513505
$exception,
514-
'Internal server error.'
506+
'Internal server error.',
515507
);
516508

517509
$content = json_decode($response->getContent(), true);

tests/phpMyFAQ/Controller/Api/GlossaryControllerTest.php

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,18 @@ protected function setUp(): void
2626

2727
public function testListReturnsGlossaryItems(): void
2828
{
29-
3029
$glossaryController = new GlossaryController();
3130

32-
$request = Request::create('/api/v3.2/glossary', 'GET', [], [], [], [
33-
'HTTP_ACCEPT_LANGUAGE' => 'en',
34-
]);
31+
$request = Request::create(
32+
'/api/v3.2/glossary',
33+
'GET',
34+
[],
35+
[],
36+
[],
37+
[
38+
'HTTP_ACCEPT_LANGUAGE' => 'en',
39+
],
40+
);
3541

3642
$response = $glossaryController->list($request);
3743

@@ -49,9 +55,16 @@ public function testListHandlesAcceptLanguageHeader(): void
4955
$glossaryController = new GlossaryController();
5056

5157
// Test with complex Accept-Language header
52-
$request = Request::create('/api/v3.2/glossary', 'GET', [], [], [], [
53-
'HTTP_ACCEPT_LANGUAGE' => 'de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7',
54-
]);
58+
$request = Request::create(
59+
'/api/v3.2/glossary',
60+
'GET',
61+
[],
62+
[],
63+
[],
64+
[
65+
'HTTP_ACCEPT_LANGUAGE' => 'de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7',
66+
],
67+
);
5568

5669
$response = $glossaryController->list($request);
5770

tests/phpMyFAQ/Faq/FaqCreationServiceTest.php

Lines changed: 13 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,7 @@ protected function setUp(): void
5353

5454
// Create mock current user
5555
$this->currentUser = $this->createMock(CurrentUser::class);
56-
$this->currentUser
57-
->method('getUserId')
58-
->willReturn(1);
56+
$this->currentUser->method('getUserId')->willReturn(1);
5957

6058
$this->currentGroups = [1];
6159

@@ -142,9 +140,7 @@ public function testCanUserAddFaqForGuest(): void
142140
{
143141
// Mock guest user (user ID = -1)
144142
$guestUser = $this->createMock(CurrentUser::class);
145-
$guestUser
146-
->method('getUserId')
147-
->willReturn(-1);
143+
$guestUser->method('getUserId')->willReturn(-1);
148144

149145
$service = new FaqCreationService($this->configuration, $guestUser, $this->currentGroups);
150146

@@ -161,9 +157,7 @@ public function testCanUserAddFaqForGuestWhenDisabled(): void
161157

162158
// Mock guest user (user ID = -1)
163159
$guestUser = $this->createMock(CurrentUser::class);
164-
$guestUser
165-
->method('getUserId')
166-
->willReturn(-1);
160+
$guestUser->method('getUserId')->willReturn(-1);
167161

168162
$service = new FaqCreationService($this->configuration, $guestUser, $this->currentGroups);
169163

@@ -177,9 +171,7 @@ public function testCanUserAddFaqForLoggedInUserWithPermission(): void
177171
{
178172
// Create a user mock with permission
179173
$userWithPerm = $this->createMock(CurrentUser::class);
180-
$userWithPerm
181-
->method('getUserId')
182-
->willReturn(1);
174+
$userWithPerm->method('getUserId')->willReturn(1);
183175

184176
$permMock = $this->createMock(\phpMyFAQ\Permission\PermissionInterface::class);
185177
$permMock
@@ -202,9 +194,7 @@ public function testCanUserAddFaqForLoggedInUserWithoutPermission(): void
202194
{
203195
// Create a user mock without permission
204196
$userWithoutPerm = $this->createMock(CurrentUser::class);
205-
$userWithoutPerm
206-
->method('getUserId')
207-
->willReturn(1);
197+
$userWithoutPerm->method('getUserId')->willReturn(1);
208198

209199
$permMock = $this->createMock(\phpMyFAQ\Permission\PermissionInterface::class);
210200
$permMock
@@ -241,9 +231,7 @@ public function testGetDefaultUserEmailForLoggedInUser(): void
241231
public function testGetDefaultUserEmailForGuest(): void
242232
{
243233
$guestUser = $this->createMock(CurrentUser::class);
244-
$guestUser
245-
->method('getUserId')
246-
->willReturn(-1);
234+
$guestUser->method('getUserId')->willReturn(-1);
247235

248236
$service = new FaqCreationService($this->configuration, $guestUser, $this->currentGroups);
249237

@@ -273,9 +261,7 @@ public function testGetDefaultUserNameForLoggedInUser(): void
273261
public function testGetDefaultUserNameForGuest(): void
274262
{
275263
$guestUser = $this->createMock(CurrentUser::class);
276-
$guestUser
277-
->method('getUserId')
278-
->willReturn(-1);
264+
$guestUser->method('getUserId')->willReturn(-1);
279265

280266
$service = new FaqCreationService($this->configuration, $guestUser, $this->currentGroups);
281267

@@ -335,14 +321,10 @@ public function testCanUserAddFaqReturnsBooleanValue(): void
335321
{
336322
// Create a user mock with permission
337323
$userWithPerm = $this->createMock(CurrentUser::class);
338-
$userWithPerm
339-
->method('getUserId')
340-
->willReturn(1);
324+
$userWithPerm->method('getUserId')->willReturn(1);
341325

342326
$permMock = $this->createMock(\phpMyFAQ\Permission\PermissionInterface::class);
343-
$permMock
344-
->method('hasPermission')
345-
->willReturn(true);
327+
$permMock->method('hasPermission')->willReturn(true);
346328

347329
$userWithPerm->perm = $permMock;
348330

@@ -359,13 +341,8 @@ public function testCanUserAddFaqReturnsBooleanValue(): void
359341
public function testGetDefaultUserEmailReturnsString(): void
360342
{
361343
$userMock = $this->createMock(CurrentUser::class);
362-
$userMock
363-
->method('getUserId')
364-
->willReturn(1);
365-
$userMock
366-
->method('getUserData')
367-
->with('email')
368-
->willReturn('[email protected]');
344+
$userMock->method('getUserId')->willReturn(1);
345+
$userMock->method('getUserData')->with('email')->willReturn('[email protected]');
369346

370347
$service = new FaqCreationService($this->configuration, $userMock, $this->currentGroups);
371348

@@ -380,13 +357,8 @@ public function testGetDefaultUserEmailReturnsString(): void
380357
public function testGetDefaultUserNameReturnsString(): void
381358
{
382359
$userMock = $this->createMock(CurrentUser::class);
383-
$userMock
384-
->method('getUserId')
385-
->willReturn(1);
386-
$userMock
387-
->method('getUserData')
388-
->with('display_name')
389-
->willReturn('John Doe');
360+
$userMock->method('getUserId')->willReturn(1);
361+
$userMock->method('getUserData')->with('display_name')->willReturn('John Doe');
390362

391363
$service = new FaqCreationService($this->configuration, $userMock, $this->currentGroups);
392364

0 commit comments

Comments
 (0)