Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/Controller/FeedController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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');
Expand Down
48 changes: 48 additions & 0 deletions tests/Controller/FeedControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading