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
14 changes: 12 additions & 2 deletions apps/dav/lib/CardDAV/CardDavBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -1246,13 +1246,16 @@ public function searchPrincipalUri(string $principalUri,
* } $options
* @return array
*/
private function searchByAddressBookIds(array $addressBookIds,
private function searchByAddressBookIds(
array $addressBookIds,
string $pattern,
array $searchProperties,
array $options = []): array {
array $options = [],
): array {
if (empty($addressBookIds)) {
return [];
}

$escapePattern = !\array_key_exists('escape_like_param', $options) || $options['escape_like_param'] !== false;
$useWildcards = !\array_key_exists('wildcard', $options) || $options['wildcard'] !== false;

Expand Down Expand Up @@ -1293,6 +1296,9 @@ private function searchByAddressBookIds(array $addressBookIds,
$query2->andWhere($query2->expr()->ilike('cp.value', $query2->createNamedParameter('%' . $this->db->escapeLikeParameter($pattern) . '%')));
}
}
if (isset($options['limit']) || isset($options['offset'])) {
$query2->orderBy('cp.cardid', 'ASC');
}
if (isset($options['limit'])) {
$query2->setMaxResults($options['limit']);
}
Expand Down Expand Up @@ -1339,6 +1345,10 @@ private function searchByAddressBookIds(array $addressBookIds,
->from($this->dbCardsTable, 'c')
->where($query->expr()->in('c.id', $query->createParameter('matches')));

if (isset($options['limit']) || isset($options['offset'])) {
$query->orderBy('c.id', 'ASC');
}

foreach (array_chunk($matches, IQueryBuilder::MAX_IN_PARAMETERS) as $matchesChunk) {
$query->setParameter('matches', $matchesChunk, IQueryBuilder::PARAM_INT_ARRAY);
$result = $query->executeQuery();
Expand Down
102 changes: 61 additions & 41 deletions apps/dav/tests/unit/CardDAV/CardDavBackendTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,52 @@ public function testGetCardIdFailed(): void {

#[\PHPUnit\Framework\Attributes\DataProvider(methodName: 'dataTestSearch')]
public function testSearch(string $pattern, array $properties, array $options, array $expectedUris, array $expectedNeedles): void {
$this->seedSearchCards();

$result = $this->backend->search(0, $pattern, $properties, $options);

$this->assertCount(count($expectedUris), $result);

$actualUris = array_map(static fn (array $row): string => $row['uri'], $result);
sort($actualUris);
$expectedSortedUris = $expectedUris;
sort($expectedSortedUris);

$this->assertSame($expectedSortedUris, $actualUris, 'Search returned unexpected URIs');

$expectedByUri = array_combine($expectedUris, $expectedNeedles);
$this->assertIsArray($expectedByUri);

foreach ($result as $row) {
$this->assertArrayHasKey($row['uri'], $expectedByUri, 'Unexpected URI in search result');
$this->assertNotFalse(
strpos($row['carddata'], $expectedByUri[$row['uri']]),
'Returned carddata does not contain expected fragment for ' . $row['uri']
);
}
}

public function testSearchPaginationUsesCardIdOrder(): void {
$this->seedSearchCards();

$firstPage = $this->backend->search(0, 'john', ['FN'], [
'limit' => 1,
'offset' => 0,
]);
$secondPage = $this->backend->search(0, 'john', ['FN'], [
'limit' => 1,
'offset' => 1,
]);
$twoResults = $this->backend->search(0, 'john', ['FN'], [
'limit' => 2,
]);

self::assertSame(['uri0'], array_column($firstPage, 'uri'));
self::assertSame(['uri1'], array_column($secondPage, 'uri'));
self::assertSame(['uri0', 'uri1'], array_column($twoResults, 'uri'));
}

private function seedSearchCards(): void {
$vCards = [];

$vCards[0] = new VCard();
Expand All @@ -931,16 +977,14 @@ public function testSearch(string $pattern, array $properties, array $options, a
$query = $this->db->getQueryBuilder();
for ($i = 0; $i < 3; $i++) {
$query->insert($this->dbCardsTable)
->values(
[
'addressbookid' => $query->createNamedParameter(0),
'carddata' => $query->createNamedParameter($vCards[$i]->serialize(), IQueryBuilder::PARAM_LOB),
'uri' => $query->createNamedParameter('uri' . $i),
'lastmodified' => $query->createNamedParameter(time()),
'etag' => $query->createNamedParameter('etag' . $i),
'size' => $query->createNamedParameter(120),
]
);
->values([
'addressbookid' => $query->createNamedParameter(0),
'carddata' => $query->createNamedParameter($vCards[$i]->serialize(), IQueryBuilder::PARAM_LOB),
'uri' => $query->createNamedParameter('uri' . $i),
'lastmodified' => $query->createNamedParameter(time()),
'etag' => $query->createNamedParameter('etag' . $i),
'size' => $query->createNamedParameter(120),
]);
$query->executeStatement();
$vCardIds[] = $query->getLastInsertId();
}
Expand All @@ -956,39 +1000,15 @@ public function testSearch(string $pattern, array $properties, array $options, a
foreach ($propertyRows as [$cardId, $name, $value]) {
$query = $this->db->getQueryBuilder();
$query->insert($this->dbCardsPropertiesTable)
->values(
[
'addressbookid' => $query->createNamedParameter(0),
'cardid' => $query->createNamedParameter($cardId),
'name' => $query->createNamedParameter($name),
'value' => $query->createNamedParameter($value),
'preferred' => $query->createNamedParameter(0),
]
);
->values([
'addressbookid' => $query->createNamedParameter(0),
'cardid' => $query->createNamedParameter($cardId),
'name' => $query->createNamedParameter($name),
'value' => $query->createNamedParameter($value),
'preferred' => $query->createNamedParameter(0),
]);
$query->executeStatement();
}

$result = $this->backend->search(0, $pattern, $properties, $options);

$this->assertCount(count($expectedUris), $result);

$actualUris = array_map(static fn (array $row): string => $row['uri'], $result);
sort($actualUris);
$expectedSortedUris = $expectedUris;
sort($expectedSortedUris);

$this->assertSame($expectedSortedUris, $actualUris, 'Search returned unexpected URIs');

$expectedByUri = array_combine($expectedUris, $expectedNeedles);
$this->assertIsArray($expectedByUri);

foreach ($result as $row) {
$this->assertArrayHasKey($row['uri'], $expectedByUri, 'Unexpected URI in search result');
$this->assertNotFalse(
strpos($row['carddata'], $expectedByUri[$row['uri']]),
'Returned carddata does not contain expected fragment for ' . $row['uri']
);
}
}

public static function dataTestSearch(): array {
Expand Down
4 changes: 4 additions & 0 deletions tests/Core/Sharing/Recipient/UserShareRecipientTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use OC\User\Database;
use OCA\DAV\CardDAV\CardDavBackend;
use OCA\DAV\CardDAV\ContactsManager;
use OCA\DAV\CardDAV\SyncService;
use OCP\Contacts\IManager;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IDBConnection;
Expand Down Expand Up @@ -77,6 +78,9 @@ public function setUp(): void {
$this->user3 = $this->createUser($userManager, 'user3', 'password');
$this->user4 = $this->createUser($userManager, 'user4', 'password');

// Remove system address book cards of users from other tests, they would fill up the paginated contact searches
Server::get(SyncService::class)->syncInstance();

$this->recipientType = new UserShareRecipientType(Server::get(IEventDispatcher::class), $this->dbConnection, $userManager, $this->manager);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/playwright/e2e/login/webauth.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ test.describe('Login: WebAuthn', () => {
const passwordlessForm = page.getByRole('form', { name: /Log in with a device/i })
await expect(passwordlessForm).toBeVisible()

await passwordlessForm.getByLabel('Login or email').fill(user.userId)
await passwordlessForm.getByLabel('Login name or email').fill(user.userId)

const webauthnLogin = page.waitForResponse((r) => r.url().includes('/login/webauthn/start') && r.request().method() === 'POST')
await page.getByRole('button', { name: 'Log in' }).click()
Expand Down
2 changes: 1 addition & 1 deletion tests/playwright/e2e/settings/personal-info.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ test.describe('Settings: Change personal information', () => {

// Language change triggers a full page reload; wait for the Dutch UI
await expect(page.getByRole('combobox', { name: 'Taal' })).toBeVisible({ timeout: 15_000 })
await expect(page.getByText('Help met vertalen')).toBeVisible()
await expect(page.locator('html')).toHaveAttribute('lang', 'nl')
})

test('can change locale', async ({ page, languageLocalePage }) => {
Expand Down
Loading