Skip to content
Merged
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 @@ -47,7 +47,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 @@ -57,8 +57,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
9 changes: 1 addition & 8 deletions lib/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -615,15 +615,8 @@ public function countDownloads(string $user, int $objectId, ?int $since = null):

/**
* Verify that the filter is valid
*
* @param string $filterValue
* @return string
*/
public function validateFilter($filterValue) {
if (!isset($filterValue)) {
return 'all';
}

public function validateFilter(string $filterValue): string {
switch ($filterValue) {
case 'filter':
return $filterValue;
Expand Down
51 changes: 51 additions & 0 deletions tests/Controller/FeedControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ public function testShow(?string $acceptHeader, string $expectedHeader): void {
$this->data
->method('get')
->willReturn(['data' => []]);
$this->data
->method('validateFilter')
->willReturn('all');
if ($acceptHeader !== null) {
$this->request
->method('getHeader')
Expand Down Expand Up @@ -143,6 +146,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