Skip to content

Commit

Permalink
More search() tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mstilkerich committed Feb 22, 2021
1 parent 2db0568 commit 9106135
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 25 deletions.
143 changes: 128 additions & 15 deletions tests/unit/AddressbookTest.php
Expand Up @@ -281,6 +281,20 @@ public function searchDataProvider(): array
[], [],
1, ["53"]
],
'Single Multivalue DB field search with contains search' => [
['email'], ["north@7kingdoms.com"], rcube_addressbook::SEARCH_ALL, true, false,
'name', 'ASC', 1, 10,
0,
[], [],
2, ["60", "50"]
],
'Single Multivalue DB field search with strict search' => [
['email'], ["north@7kingdoms.com"], rcube_addressbook::SEARCH_STRICT, true, false,
'name', 'ASC', 1, 10,
0,
[], [],
1, ["60"]
],
'Multi DB field search with contains search' => [
['name', 'email'], ["Lannister", "@example"], rcube_addressbook::SEARCH_ALL, true, false,
'name', 'ASC', 1, 10,
Expand Down Expand Up @@ -324,11 +338,107 @@ public function searchDataProvider(): array
[], [],
1, ["60"]
],
'All fields search' => [
'*', 'Birkin',
rcube_addressbook::SEARCH_ALL, true, false,
'name', 'ASC', 1, 10,
0,
[], [],
1, ["60"]
],
'Two fields OR search' => [
['organization', 'name'], 'the',
rcube_addressbook::SEARCH_ALL, true, false,
'name', 'ASC', 1, 10,
0,
[], [],
3, ["50", "53", "54"]
],
'Mixed DB/vcard fields OR search' => [
['notes', 'organization', 'name'], 'the',
rcube_addressbook::SEARCH_ALL, true, false,
'name', 'ASC', 1, 10,
0,
[], [],
4, ["60", "50", "53", "54"]
],
'Results for 2nd page only' => [
'*', 'example',
rcube_addressbook::SEARCH_ALL, true, false,
'name', 'ASC', 2, 2,
0,
[], [],
6, ["50", "52"]
],
'Results for 2nd page only (select only)' => [
'*', 'example',
rcube_addressbook::SEARCH_ALL, true, true,
'name', 'ASC', 2, 2,
0,
[], [],
2, ["50", "52"]
],
'Results for 2nd page only (count only)' => [
'*', 'example',
rcube_addressbook::SEARCH_ALL, false, false,
'name', 'ASC', 2, 2,
0,
[], [],
6, []
],
'With required DB field' => [
'*', 'example',
rcube_addressbook::SEARCH_ALL, true, false,
'name', 'ASC', 1, 10,
0,
[], ['organization'],
3, ["60", "50", "54"]
],
'With required DB field (plus required abook field)' => [
'*', 'example',
rcube_addressbook::SEARCH_ALL, true, false,
'name', 'ASC', 1, 10,
0,
['firstname'], ['organization'],
2, ["50", "54"]
],
'With required VCard field' => [
'*', 'example',
rcube_addressbook::SEARCH_ALL, true, false,
'name', 'ASC', 1, 10,
0,
[], ['jobtitle'],
2, ["60", "50"]
],
'With required VCard field (as string)' => [
'*', 'example',
rcube_addressbook::SEARCH_ALL, true, false,
'name', 'ASC', 1, 10,
0,
[], 'jobtitle',
2, ["60", "50"]
],
'With required VCard field and group filter' => [
'*', 'example',
rcube_addressbook::SEARCH_ALL, true, false,
'name', 'ASC', 1, 10,
"500",
[], 'jobtitle',
1, ["50"]
],
'With required VCard field and group filter for empty group' => [
'*', 'example',
rcube_addressbook::SEARCH_ALL, true, false,
'name', 'ASC', 1, 10,
"504",
[], 'jobtitle',
0, []
],
];
}

/**
* Tests the search() function
* Tests the search() function.
*
* @dataProvider searchDataProvider
* @param string|string[] $fields
Expand Down Expand Up @@ -384,20 +494,23 @@ public function testSearchReturnsExpectedRecords(
} else {
$this->assertSame($expCount, $rset->count);
}
$this->assertCount(count($expRecords), $rset->records);

$lrOrder = array_column($rset->records, 'ID');
$this->assertSame($expRecords, $lrOrder, "Card order mismatch");
for ($i = 0; $i < count($expRecords); ++$i) {
$id = $expRecords[$i];
$fn = "tests/unit/data/addressbookTest/c{$id}.json";
$saveDataExp = Utils::readSaveDataFromJson($fn);
/** @var array $saveDataRc */
$saveDataRc = $rset->records[$i];
Utils::compareSaveData($saveDataExp, $saveDataRc, "Unexpected record data $id");

if (isset($saveDataExp['photo']) && empty($saveDataExp['photo'])) {
$this->assertPhotoDownloadWarning();

if ($run == 0 || $select) { // select=false can only be tested with search() (run 0)
$this->assertCount(count($expRecords), $rset->records);

$lrOrder = array_column($rset->records, 'ID');
$this->assertSame($expRecords, $lrOrder, "Card order mismatch (run $run)");
for ($i = 0; $i < count($expRecords); ++$i) {
$id = $expRecords[$i];
$fn = "tests/unit/data/addressbookTest/c{$id}.json";
$saveDataExp = Utils::readSaveDataFromJson($fn);
/** @var array $saveDataRc */
$saveDataRc = $rset->records[$i];
Utils::compareSaveData($saveDataExp, $saveDataRc, "Unexpected record data $id");

if (isset($saveDataExp['photo']) && empty($saveDataExp['photo'])) {
$this->assertPhotoDownloadWarning();
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/data/addressbookTest/c50.json
Expand Up @@ -7,7 +7,7 @@
"organization": "The North",
"department": "Winterfell",
"email:home": [ "ned@stark.example.com" ],
"email:work": [ "warden_of_the_north@stark.example.com" ],
"email:work": [ "warden_of_the_north@7kingdoms.com" ],
"jobtitle": "Warden of the North",
"photo": "",
"kind": "individual"
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/data/addressbookTest/c60.json
@@ -1,7 +1,6 @@
{
"ID": "60",
"name": "Chairman Wesker",
"firstname": "Albert",
"surname": "Wesker",
"prefix": "Dr.",
"suffix": "MSc",
Expand All @@ -17,10 +16,11 @@
"manager": "No one",
"spouse": "Alice Wesker",
"nickname": "Practical Al",
"notes": "It should be noted that Wesker seems to only have loyalty to himself and William Birkin and seems to be playing all sides to his own advantage.",
"notes": "The note: It should be noted that Wesker seems to only have loyalty to himself and William Birkin and seems to be playing all sides to his own advantage.",
"jobtitle": "CEO",
"email:home": [ "albert@wesker.example.com" ],
"email:work": [ "wesker@umbrella.example.com" ],
"email:other": [ "north@7kingdoms.com" ],
"phone:home": [ "12345" ],
"phone:work": [ "54321" ],
"website:homepage": [ "https://wesker.example.com" ],
Expand Down
5 changes: 3 additions & 2 deletions tests/unit/data/addressbookTest/c60.vcf
Expand Up @@ -3,13 +3,13 @@ VERSION:3.0
PRODID:-//Sabre//Sabre VObject 4.3.1//EN
UID:sabre-vobject-005e805f-0bc1-4333-8be2-97889fb45b7a
REV:2020-08-27T20:38:49Z
N:Wesker;Albert;;Dr.;MSc;Extra-Component-Must-Be-Ignored
N:Wesker;;;Dr.;MSc;Extra-Component-Must-Be-Ignored
X-MAIDENNAME:Born Wesker
ORG:Umbrella Corp;Executive Board
BDAY:1960-07-17
FN:Chairman Wesker
NICKNAME:Practical Al
NOTE:It should be noted that Wesker seems to only have loyalty to himself and William Birkin and seems to be playing all sides to his own advantage.
NOTE:The note: It should be noted that Wesker seems to only have loyalty to himself and William Birkin and seems to be playing all sides to his own advantage.
TITLE:CEO
X-ABSHOWAS:INDIVIDUAL
X-ANNIVERSARY:2009-07-03
Expand All @@ -19,6 +19,7 @@ X-MANAGER:No one
X-SPOUSE:Alice Wesker
EMAIL;TYPE=home:albert@wesker.example.com
EMAIL;TYPE=work:wesker@umbrella.example.com
EMAIL:north@7kingdoms.com
TEL;TYPE=home:12345
TEL;TYPE=work:54321
URL;TYPE=homepage;VALUE=URI:https://wesker.example.com
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/data/addressbookTest/db2.json
Expand Up @@ -34,8 +34,8 @@
"id": 60,
"abook_id": 42,
"name": "Chairman Wesker",
"email": "albert@wesker.example.com, wesker@umbrella.example.com",
"firstname": "Albert",
"email": "albert@wesker.example.com, wesker@umbrella.example.com, north@7kingdoms.com",
"firstname": null,
"surname": "Wesker",
"organization": "Umbrella Corp",
"showas": "",
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/data/syncHandlerTest/increment1/db.json
Expand Up @@ -20,7 +20,7 @@
"id": 50,
"abook_id": 42,
"name": "Eddard Stark",
"email": "ned@stark.example.com, warden_of_the_north@stark.example.com",
"email": "ned@stark.example.com, warden_of_the_north@7kingdoms.com",
"firstname": "Eddard",
"surname": "Stark",
"organization": "The North",
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/data/syncHandlerTest/initial/db.json
Expand Up @@ -20,7 +20,7 @@
"id": 50,
"abook_id": 42,
"name": "Eddard Stark",
"email": "ned@stark.example.com, warden_of_the_north@stark.example.com",
"email": "ned@stark.example.com, warden_of_the_north@7kingdoms.com",
"firstname": "Eddard",
"surname": "Stark",
"organization": "The North",
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/data/syncHandlerTest/initial/nedstark.vcf
Expand Up @@ -7,7 +7,7 @@ N:Stark;Eddard;;;
ORG:The North;Winterfell
ADR;TYPE=HOME:;;;;;;
EMAIL;TYPE=HOME:ned@stark.example.com
EMAIL;TYPE=WORK:warden_of_the_north@stark.example.com
EMAIL;TYPE=WORK:warden_of_the_north@7kingdoms.com
TITLE:Warden of the North
CATEGORIES:House Stark
REV;VALUE=DATE-AND-OR-TIME:20201227T103400Z
Expand Down

0 comments on commit 9106135

Please sign in to comment.