Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
our_own_cloud_project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
die_coolen_jungs
our_own_cloud_project
Commits
f99497a0
Commit
f99497a0
authored
12 years ago
by
Thomas Müller
Browse files
Options
Downloads
Patches
Plain Diff
test for search and unregister added
parent
2d597c22
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/public/contacts.php
+2
-2
2 additions, 2 deletions
lib/public/contacts.php
tests/lib/public/contacts.php
+51
-6
51 additions, 6 deletions
tests/lib/public/contacts.php
with
53 additions
and
8 deletions
lib/public/contacts.php
+
2
−
2
View file @
f99497a0
...
...
@@ -108,10 +108,10 @@ namespace OCP {
* @return array of contacts which are arrays of key-value-pairs
*/
public
static
function
search
(
$pattern
,
$searchProperties
=
array
(),
$options
=
array
())
{
$result
=
array
();
foreach
(
self
::
$address_books
as
$address_book
)
{
$result
=
$result
+
$address_book
->
search
(
$pattern
,
$searchProperties
,
$options
);
$r
=
$address_book
->
search
(
$pattern
,
$searchProperties
,
$options
);
$result
=
array_merge
(
$result
,
$r
);
}
return
$result
;
...
...
This diff is collapsed.
Click to expand it.
tests/lib/public/contacts.php
+
51
−
6
View file @
f99497a0
...
...
@@ -41,8 +41,10 @@ class Test_Contacts extends PHPUnit_Framework_TestCase
// create mock for the addressbook
$stub
=
$this
->
getMock
(
"SimpleAddressBook"
,
array
(
'getKey'
));
// we expect getKey to be called once
$stub
->
expects
(
$this
->
once
())
// we expect getKey to be called twice:
// first time on register
// second time on un-register
$stub
->
expects
(
$this
->
exactly
(
2
))
->
method
(
'getKey'
);
// not enabled before register
...
...
@@ -53,11 +55,13 @@ class Test_Contacts extends PHPUnit_Framework_TestCase
// contacts api shall be enabled
$this
->
assertTrue
(
OCP\Contacts
::
isEnabled
());
}
//
// TODO: test unregister
//
// unregister the address book
OCP\Contacts
::
unregisterAddressBook
(
$stub
);
// not enabled after register
$this
->
assertFalse
(
OCP\Contacts
::
isEnabled
());
}
public
function
testAddressBookEnumeration
()
{
// create mock for the addressbook
...
...
@@ -76,5 +80,46 @@ class Test_Contacts extends PHPUnit_Framework_TestCase
$all_books
=
OCP\Contacts
::
getAddressBooks
();
$this
->
assertEquals
(
1
,
count
(
$all_books
));
$this
->
assertEquals
(
'A very simple Addressbook'
,
$all_books
[
'SIMPLE_ADDRESS_BOOK'
]);
}
public
function
testSearchInAddressBook
()
{
// create mock for the addressbook
$stub1
=
$this
->
getMock
(
"SimpleAddressBook1"
,
array
(
'getKey'
,
'getDisplayName'
,
'search'
));
$stub2
=
$this
->
getMock
(
"SimpleAddressBook2"
,
array
(
'getKey'
,
'getDisplayName'
,
'search'
));
$searchResult1
=
array
(
array
(
'id'
=>
0
,
'FN'
=>
'Frank Karlitschek'
,
'EMAIL'
=>
'a@b.c'
,
'GEO'
=>
'37.386013;-122.082932'
),
array
(
'id'
=>
5
,
'FN'
=>
'Klaas Freitag'
,
'EMAIL'
=>
array
(
'd@e.f'
,
'g@h.i'
)),
);
$searchResult2
=
array
(
array
(
'id'
=>
0
,
'FN'
=>
'Thomas Müller'
,
'EMAIL'
=>
'a@b.c'
),
array
(
'id'
=>
5
,
'FN'
=>
'Thomas Tanghus'
,
'EMAIL'
=>
array
(
'd@e.f'
,
'g@h.i'
)),
);
// setup return for method calls for $stub1
$stub1
->
expects
(
$this
->
any
())
->
method
(
'getKey'
)
->
will
(
$this
->
returnValue
(
'SIMPLE_ADDRESS_BOOK1'
));
$stub1
->
expects
(
$this
->
any
())
->
method
(
'getDisplayName'
)
->
will
(
$this
->
returnValue
(
'Address book ownCloud Inc'
));
$stub1
->
expects
(
$this
->
any
())
->
method
(
'search'
)
->
will
(
$this
->
returnValue
(
$searchResult1
));
// setup return for method calls for $stub2
$stub2
->
expects
(
$this
->
any
())
->
method
(
'getKey'
)
->
will
(
$this
->
returnValue
(
'SIMPLE_ADDRESS_BOOK2'
));
$stub2
->
expects
(
$this
->
any
())
->
method
(
'getDisplayName'
)
->
will
(
$this
->
returnValue
(
'Address book ownCloud Community'
));
$stub2
->
expects
(
$this
->
any
())
->
method
(
'search'
)
->
will
(
$this
->
returnValue
(
$searchResult2
));
// register the address books
OCP\Contacts
::
registerAddressBook
(
$stub1
);
OCP\Contacts
::
registerAddressBook
(
$stub2
);
$all_books
=
OCP\Contacts
::
getAddressBooks
();
// assert the count - doesn't hurt
$this
->
assertEquals
(
2
,
count
(
$all_books
));
// perform the search
$result
=
OCP\Contacts
::
search
(
'x'
,
array
());
// we expect 4 hits
$this
->
assertEquals
(
4
,
count
(
$result
));
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment