Skip to content

Commit

Permalink
fix: cominbation of small fixes
Browse files Browse the repository at this point in the history
- possible null return
- parameter name mismatch in implementation
- incomplete unit test

Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
  • Loading branch information
blizzz committed Jun 21, 2023
1 parent 9c1daec commit bca6d7f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
6 changes: 3 additions & 3 deletions apps/dav/lib/Connector/Sabre/FilesReportPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,9 @@ private function getFilesBaseUri(string $uri, string $subPath): string {
* @param array $filterRules
* @return array array of unique file id results
*/
protected function processFilterRulesForFileIDs($filterRules) {
protected function processFilterRulesForFileIDs(array $filterRules): array {
$ns = '{' . $this::NS_OWNCLOUD . '}';
$resultFileIds = null;
$resultFileIds = [];
$circlesIds = [];
$favoriteFilter = null;
foreach ($filterRules as $filterRule) {
Expand Down Expand Up @@ -416,7 +416,7 @@ public function prepareResponses($filesUri, $requestedProps, $nodes) {
* @param array $fileIds file ids
* @return Node[] array of Sabre nodes
*/
public function findNodesByFileIds($rootNode, $fileIds): array {
public function findNodesByFileIds(Node $rootNode, array $fileIds): array {
if (empty($fileIds)) {
return [];
}
Expand Down
23 changes: 20 additions & 3 deletions apps/dav/tests/unit/Connector/Sabre/FilesReportPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -889,30 +889,47 @@ public function testProcessFilterRulesVisibleTagAsUser(): void {
->willReturn([$tag1, $tag2]);

$filesNode1 = $this->createMock(File::class);
$filesNode1->expects($this->any())
->method('getId')
->willReturn(111);
$filesNode1->expects($this->any())
->method('getSize')
->willReturn(12);
$filesNode2 = $this->createMock(Folder::class);
$filesNode2->expects($this->any())
->method('getId')
->willReturn(222);
$filesNode2->expects($this->any())
->method('getSize')
->willReturn(10);
$filesNode3 = $this->createMock(Folder::class);
$filesNode3->expects($this->any())
->method('getId')
->willReturn(333);
$filesNode3->expects($this->any())
->method('getSize')
->willReturn(33);

$this->tagManager->expects($this->once())
->method('getTagsByIds')
->with(['123', '456'])
->willReturn([$tag1, $tag2]);

// main assertion: only user visible tags are being passed through.
$this->userFolder->expects($this->exactly(1))
$this->userFolder->expects($this->exactly(2))
->method('searchBySystemTag')
->with('FourFiveSix', $this->anything(), $this->anything(), $this->anything());
->withConsecutive(['OneTwoThree'], ['FourFiveSix'])
->willReturnOnConsecutiveCalls(
[$filesNode1, $filesNode2],
[$filesNode2, $filesNode3],
);

$rules = [
['name' => '{http://owncloud.org/ns}systemtag', 'value' => '123'],
['name' => '{http://owncloud.org/ns}systemtag', 'value' => '456'],
];

$this->invokePrivate($this->plugin, 'processFilterRulesForFileNodes', [$rules, null, null]);
$this->assertEquals([$filesNode2], array_values($this->invokePrivate($this->plugin, 'processFilterRulesForFileNodes', [$rules, null, null])));
}

public function testProcessFavoriteFilter(): void {
Expand Down
4 changes: 2 additions & 2 deletions lib/private/Files/Node/Folder.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,8 @@ public function searchByTag($tag, $userId) {
return $this->search($query);
}

public function searchBySystemTag(string $tag, string $userId, int $limit = 0, int $offset = 0): array {
$query = $this->queryFromOperator(new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'systemtag', $tag), $userId, $limit, $offset);
public function searchBySystemTag(string $tagName, string $userId, int $limit = 0, int $offset = 0): array {
$query = $this->queryFromOperator(new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'systemtag', $tagName), $userId, $limit, $offset);
return $this->search($query);
}

Expand Down

0 comments on commit bca6d7f

Please sign in to comment.