localadressbook.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. use OC\Contacts\LocalAddressBook;
  3. /**
  4. * ownCloud
  5. *
  6. * @author Thomas Müller
  7. * @copyright 2014 Thomas Müller thomas.mueller@tmit.eu
  8. *
  9. * You should have received a copy of the GNU Affero General Public
  10. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  11. */
  12. class Test_LocalAddressBook extends \Test\TestCase
  13. {
  14. public function testSearchFN() {
  15. $stub = $this->getMockForAbstractClass('\OCP\IUserManager', array('searchDisplayName'));
  16. $stub->expects($this->any())->method('searchDisplayName')->will($this->returnValue(array(
  17. new SimpleUserForTesting('tom', 'Thomas'),
  18. new SimpleUserForTesting('tomtom', 'Thomas T.'),
  19. )));
  20. $localAddressBook = new LocalAddressBook($stub);
  21. $result = $localAddressBook->search('tom', array('FN'), array());
  22. $this->assertEquals(2, count($result));
  23. }
  24. public function testSearchId() {
  25. $stub = $this->getMockForAbstractClass('\OCP\IUserManager', array('searchDisplayName'));
  26. $stub->expects($this->any())->method('search')->will($this->returnValue(array(
  27. new SimpleUserForTesting('tom', 'Thomas'),
  28. new SimpleUserForTesting('tomtom', 'Thomas T.'),
  29. )));
  30. $localAddressBook = new LocalAddressBook($stub);
  31. $result = $localAddressBook->search('tom', array('id'), array());
  32. $this->assertEquals(2, count($result));
  33. }
  34. }
  35. class SimpleUserForTesting implements \OCP\IUser {
  36. public function __construct($uid, $displayName) {
  37. $this->uid = $uid;
  38. $this->displayName = $displayName;
  39. }
  40. public function getUID() {
  41. return $this->uid;
  42. }
  43. public function getDisplayName() {
  44. return $this->displayName;
  45. }
  46. public function setDisplayName($displayName) {
  47. }
  48. public function getLastLogin() {
  49. }
  50. public function updateLastLoginTimestamp() {
  51. }
  52. public function delete() {
  53. }
  54. public function setPassword($password, $recoveryPassword = null) {
  55. }
  56. public function getHome() {
  57. }
  58. public function getBackendClassName() {
  59. }
  60. public function canChangeAvatar() {
  61. }
  62. public function canChangePassword() {
  63. }
  64. public function canChangeDisplayName() {
  65. }
  66. public function isEnabled() {
  67. }
  68. public function setEnabled($enabled) {
  69. }
  70. }