diff --git a/lib/Controller/FeedController.php b/lib/Controller/FeedController.php index fbcf6b0c1..4cbf0b38a 100644 --- a/lib/Controller/FeedController.php +++ b/lib/Controller/FeedController.php @@ -46,7 +46,7 @@ public function __construct( #[PublicPage] #[NoCSRFRequired] #[BruteForceProtection('activityRssFeed')] - public function show(): TemplateResponse { + public function show(string $filter = 'all'): TemplateResponse { $response = new TemplateResponse('activity', 'rss', [], ''); try { $user = $this->activityManager->getCurrentUserId(); @@ -56,8 +56,9 @@ public function show(): TemplateResponse { $this->l = $this->l10nFactory->get('activity', $userLang); $this->helper->setL10n($this->l); + $filter = $this->data->validateFilter($filter); $description = $this->l->t('Personal activity feed for %s', $user); - $data = $this->data->get($this->helper, $this->settings, $user, 0, self::DEFAULT_PAGE_SIZE, 'desc', 'all'); + $data = $this->data->get($this->helper, $this->settings, $user, 0, self::DEFAULT_PAGE_SIZE, 'desc', $filter); $activities = $data['data']; } catch (\UnexpectedValueException $e) { $this->l = $this->l10nFactory->get('activity'); diff --git a/tests/Controller/FeedControllerTest.php b/tests/Controller/FeedControllerTest.php index da963ada3..0894eba7a 100644 --- a/tests/Controller/FeedControllerTest.php +++ b/tests/Controller/FeedControllerTest.php @@ -144,6 +144,54 @@ public function testShowNoToken(?string $acceptHeader, string $expectedHeader): $this->assertStringContainsString($description, $renderedResponse); } + public function testShowWithFilter(): void { + $this->mockUserSession('test'); + $this->data + ->method('validateFilter') + ->with('files') + ->willReturn('files'); + $this->data + ->expects($this->once()) + ->method('get') + ->with($this->helper, $this->userSettings, 'test', 0, FeedController::DEFAULT_PAGE_SIZE, 'desc', 'files') + ->willReturn(['data' => []]); + + $templateResponse = $this->controller->show('files'); + $this->assertInstanceOf(TemplateResponse::class, $templateResponse); + } + + public function testShowWithInvalidFilter(): void { + $this->mockUserSession('test'); + $this->data + ->method('validateFilter') + ->with('invalid_filter') + ->willReturn('all'); + $this->data + ->expects($this->once()) + ->method('get') + ->with($this->helper, $this->userSettings, 'test', 0, FeedController::DEFAULT_PAGE_SIZE, 'desc', 'all') + ->willReturn(['data' => []]); + + $templateResponse = $this->controller->show('invalid_filter'); + $this->assertInstanceOf(TemplateResponse::class, $templateResponse); + } + + public function testShowDefaultsToAllFilter(): void { + $this->mockUserSession('test'); + $this->data + ->method('validateFilter') + ->with('all') + ->willReturn('all'); + $this->data + ->expects($this->once()) + ->method('get') + ->with($this->helper, $this->userSettings, 'test', 0, FeedController::DEFAULT_PAGE_SIZE, 'desc', 'all') + ->willReturn(['data' => []]); + + $templateResponse = $this->controller->show(); + $this->assertInstanceOf(TemplateResponse::class, $templateResponse); + } + protected function mockUserSession(string $user): void { $mockUser = $this->createMock(IUser::class); $mockUser