Blame view

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