UserTest.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731
  1. <?php
  2. /**
  3. * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com>
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. namespace Test\User;
  9. use OC\Hooks\PublicEmitter;
  10. use OC\User\User;
  11. use OCP\Comments\ICommentsManager;
  12. use OCP\IConfig;
  13. use OCP\IUser;
  14. use OCP\Notification\IManager as INotificationManager;
  15. use OCP\Notification\INotification;
  16. use Test\TestCase;
  17. /**
  18. * Class UserTest
  19. *
  20. * @group DB
  21. *
  22. * @package Test\User
  23. */
  24. class UserTest extends TestCase {
  25. public function testDisplayName() {
  26. /**
  27. * @var \OC\User\Backend | \PHPUnit_Framework_MockObject_MockObject $backend
  28. */
  29. $backend = $this->createMock(\OC\User\Backend::class);
  30. $backend->expects($this->once())
  31. ->method('getDisplayName')
  32. ->with($this->equalTo('foo'))
  33. ->will($this->returnValue('Foo'));
  34. $backend->expects($this->any())
  35. ->method('implementsActions')
  36. ->with($this->equalTo(\OC\User\Backend::GET_DISPLAYNAME))
  37. ->will($this->returnValue(true));
  38. $user = new User('foo', $backend);
  39. $this->assertEquals('Foo', $user->getDisplayName());
  40. }
  41. /**
  42. * if the display name contain whitespaces only, we expect the uid as result
  43. */
  44. public function testDisplayNameEmpty() {
  45. /**
  46. * @var \OC\User\Backend | \PHPUnit_Framework_MockObject_MockObject $backend
  47. */
  48. $backend = $this->createMock(\OC\User\Backend::class);
  49. $backend->expects($this->once())
  50. ->method('getDisplayName')
  51. ->with($this->equalTo('foo'))
  52. ->will($this->returnValue(' '));
  53. $backend->expects($this->any())
  54. ->method('implementsActions')
  55. ->with($this->equalTo(\OC\User\Backend::GET_DISPLAYNAME))
  56. ->will($this->returnValue(true));
  57. $user = new User('foo', $backend);
  58. $this->assertEquals('foo', $user->getDisplayName());
  59. }
  60. public function testDisplayNameNotSupported() {
  61. /**
  62. * @var \OC\User\Backend | \PHPUnit_Framework_MockObject_MockObject $backend
  63. */
  64. $backend = $this->createMock(\OC\User\Backend::class);
  65. $backend->expects($this->never())
  66. ->method('getDisplayName');
  67. $backend->expects($this->any())
  68. ->method('implementsActions')
  69. ->with($this->equalTo(\OC\User\Backend::GET_DISPLAYNAME))
  70. ->will($this->returnValue(false));
  71. $user = new User('foo', $backend);
  72. $this->assertEquals('foo', $user->getDisplayName());
  73. }
  74. public function testSetPassword() {
  75. /**
  76. * @var Backend | \PHPUnit_Framework_MockObject_MockObject $backend
  77. */
  78. $backend = $this->createMock(\Test\Util\User\Dummy::class);
  79. $backend->expects($this->once())
  80. ->method('setPassword')
  81. ->with($this->equalTo('foo'), $this->equalTo('bar'));
  82. $backend->expects($this->any())
  83. ->method('implementsActions')
  84. ->will($this->returnCallback(function ($actions) {
  85. if ($actions === \OC\User\Backend::SET_PASSWORD) {
  86. return true;
  87. } else {
  88. return false;
  89. }
  90. }));
  91. $user = new User('foo', $backend);
  92. $this->assertTrue($user->setPassword('bar',''));
  93. }
  94. public function testSetPasswordNotSupported() {
  95. /**
  96. * @var Backend | \PHPUnit_Framework_MockObject_MockObject $backend
  97. */
  98. $backend = $this->createMock(\Test\Util\User\Dummy::class);
  99. $backend->expects($this->never())
  100. ->method('setPassword');
  101. $backend->expects($this->any())
  102. ->method('implementsActions')
  103. ->will($this->returnValue(false));
  104. $user = new User('foo', $backend);
  105. $this->assertFalse($user->setPassword('bar',''));
  106. }
  107. public function testChangeAvatarSupportedYes() {
  108. /**
  109. * @var Backend | \PHPUnit_Framework_MockObject_MockObject $backend
  110. */
  111. $backend = $this->createMock(AvatarUserDummy::class);
  112. $backend->expects($this->once())
  113. ->method('canChangeAvatar')
  114. ->with($this->equalTo('foo'))
  115. ->will($this->returnValue(true));
  116. $backend->expects($this->any())
  117. ->method('implementsActions')
  118. ->will($this->returnCallback(function ($actions) {
  119. if ($actions === \OC\User\Backend::PROVIDE_AVATAR) {
  120. return true;
  121. } else {
  122. return false;
  123. }
  124. }));
  125. $user = new User('foo', $backend);
  126. $this->assertTrue($user->canChangeAvatar());
  127. }
  128. public function testChangeAvatarSupportedNo() {
  129. /**
  130. * @var Backend | \PHPUnit_Framework_MockObject_MockObject $backend
  131. */
  132. $backend = $this->createMock(AvatarUserDummy::class);
  133. $backend->expects($this->once())
  134. ->method('canChangeAvatar')
  135. ->with($this->equalTo('foo'))
  136. ->will($this->returnValue(false));
  137. $backend->expects($this->any())
  138. ->method('implementsActions')
  139. ->will($this->returnCallback(function ($actions) {
  140. if ($actions === \OC\User\Backend::PROVIDE_AVATAR) {
  141. return true;
  142. } else {
  143. return false;
  144. }
  145. }));
  146. $user = new User('foo', $backend);
  147. $this->assertFalse($user->canChangeAvatar());
  148. }
  149. public function testChangeAvatarNotSupported() {
  150. /**
  151. * @var Backend | \PHPUnit_Framework_MockObject_MockObject $backend
  152. */
  153. $backend = $this->createMock(AvatarUserDummy::class);
  154. $backend->expects($this->never())
  155. ->method('canChangeAvatar');
  156. $backend->expects($this->any())
  157. ->method('implementsActions')
  158. ->willReturn(false);
  159. $user = new User('foo', $backend);
  160. $this->assertTrue($user->canChangeAvatar());
  161. }
  162. public function testDelete() {
  163. /**
  164. * @var Backend | \PHPUnit_Framework_MockObject_MockObject $backend
  165. */
  166. $backend = $this->createMock(\Test\Util\User\Dummy::class);
  167. $backend->expects($this->once())
  168. ->method('deleteUser')
  169. ->with($this->equalTo('foo'));
  170. $user = new User('foo', $backend);
  171. $this->assertTrue($user->delete());
  172. }
  173. public function testDeleteWithDifferentHome() {
  174. /**
  175. * @var Backend | \PHPUnit_Framework_MockObject_MockObject $backend
  176. */
  177. $backend = $this->createMock(Dummy::class);
  178. $backend->expects($this->at(0))
  179. ->method('implementsActions')
  180. ->will($this->returnCallback(function ($actions) {
  181. if ($actions === Backend::GET_HOME) {
  182. return true;
  183. } else {
  184. return false;
  185. }
  186. }));
  187. // important: getHome MUST be called before deleteUser because
  188. // once the user is deleted, getHome implementations might not
  189. // return anything
  190. $backend->expects($this->at(1))
  191. ->method('getHome')
  192. ->with($this->equalTo('foo'))
  193. ->will($this->returnValue('/home/foo'));
  194. $backend->expects($this->at(2))
  195. ->method('deleteUser')
  196. ->with($this->equalTo('foo'));
  197. $user = new User('foo', $backend);
  198. $this->assertTrue($user->delete());
  199. }
  200. public function testGetHome() {
  201. /**
  202. * @var Backend | \PHPUnit_Framework_MockObject_MockObject $backend
  203. */
  204. $backend = $this->createMock(\Test\Util\User\Dummy::class);
  205. $backend->expects($this->once())
  206. ->method('getHome')
  207. ->with($this->equalTo('foo'))
  208. ->will($this->returnValue('/home/foo'));
  209. $backend->expects($this->any())
  210. ->method('implementsActions')
  211. ->will($this->returnCallback(function ($actions) {
  212. if ($actions === \OC\User\Backend::GET_HOME) {
  213. return true;
  214. } else {
  215. return false;
  216. }
  217. }));
  218. $user = new User('foo', $backend);
  219. $this->assertEquals('/home/foo', $user->getHome());
  220. }
  221. public function testGetBackendClassName() {
  222. $user = new User('foo', new \Test\Util\User\Dummy());
  223. $this->assertEquals('Dummy', $user->getBackendClassName());
  224. $user = new User('foo', new \OC\User\Database());
  225. $this->assertEquals('Database', $user->getBackendClassName());
  226. }
  227. public function testGetHomeNotSupported() {
  228. /**
  229. * @var Backend | \PHPUnit_Framework_MockObject_MockObject $backend
  230. */
  231. $backend = $this->createMock(\Test\Util\User\Dummy::class);
  232. $backend->expects($this->never())
  233. ->method('getHome');
  234. $backend->expects($this->any())
  235. ->method('implementsActions')
  236. ->will($this->returnValue(false));
  237. $allConfig = $this->getMockBuilder('\OCP\IConfig')
  238. ->disableOriginalConstructor()
  239. ->getMock();
  240. $allConfig->expects($this->any())
  241. ->method('getUserValue')
  242. ->will($this->returnValue(true));
  243. $allConfig->expects($this->any())
  244. ->method('getSystemValue')
  245. ->with($this->equalTo('datadirectory'))
  246. ->will($this->returnValue('arbitrary/path'));
  247. $user = new User('foo', $backend, null, $allConfig);
  248. $this->assertEquals('arbitrary/path/foo', $user->getHome());
  249. }
  250. public function testCanChangePassword() {
  251. /**
  252. * @var Backend | \PHPUnit_Framework_MockObject_MockObject $backend
  253. */
  254. $backend = $this->createMock(\Test\Util\User\Dummy::class);
  255. $backend->expects($this->any())
  256. ->method('implementsActions')
  257. ->will($this->returnCallback(function ($actions) {
  258. if ($actions === \OC\User\Backend::SET_PASSWORD) {
  259. return true;
  260. } else {
  261. return false;
  262. }
  263. }));
  264. $user = new User('foo', $backend);
  265. $this->assertTrue($user->canChangePassword());
  266. }
  267. public function testCanChangePasswordNotSupported() {
  268. /**
  269. * @var Backend | \PHPUnit_Framework_MockObject_MockObject $backend
  270. */
  271. $backend = $this->createMock(\Test\Util\User\Dummy::class);
  272. $backend->expects($this->any())
  273. ->method('implementsActions')
  274. ->will($this->returnValue(false));
  275. $user = new User('foo', $backend);
  276. $this->assertFalse($user->canChangePassword());
  277. }
  278. public function testCanChangeDisplayName() {
  279. /**
  280. * @var Backend | \PHPUnit_Framework_MockObject_MockObject $backend
  281. */
  282. $backend = $this->createMock(\Test\Util\User\Dummy::class);
  283. $backend->expects($this->any())
  284. ->method('implementsActions')
  285. ->will($this->returnCallback(function ($actions) {
  286. if ($actions === \OC\User\Backend::SET_DISPLAYNAME) {
  287. return true;
  288. } else {
  289. return false;
  290. }
  291. }));
  292. $user = new User('foo', $backend);
  293. $this->assertTrue($user->canChangeDisplayName());
  294. }
  295. public function testCanChangeDisplayNameNotSupported() {
  296. /**
  297. * @var Backend | \PHPUnit_Framework_MockObject_MockObject $backend
  298. */
  299. $backend = $this->createMock(\Test\Util\User\Dummy::class);
  300. $backend->expects($this->any())
  301. ->method('implementsActions')
  302. ->will($this->returnValue(false));
  303. $user = new User('foo', $backend);
  304. $this->assertFalse($user->canChangeDisplayName());
  305. }
  306. public function testSetDisplayNameSupported() {
  307. /**
  308. * @var Backend | \PHPUnit_Framework_MockObject_MockObject $backend
  309. */
  310. $backend = $this->createMock(\OC\User\Database::class);
  311. $backend->expects($this->any())
  312. ->method('implementsActions')
  313. ->will($this->returnCallback(function ($actions) {
  314. if ($actions === \OC\User\Backend::SET_DISPLAYNAME) {
  315. return true;
  316. } else {
  317. return false;
  318. }
  319. }));
  320. $backend->expects($this->once())
  321. ->method('setDisplayName')
  322. ->with('foo','Foo')
  323. ->willReturn(true);
  324. $user = new User('foo', $backend);
  325. $this->assertTrue($user->setDisplayName('Foo'));
  326. $this->assertEquals('Foo',$user->getDisplayName());
  327. }
  328. /**
  329. * don't allow display names containing whitespaces only
  330. */
  331. public function testSetDisplayNameEmpty() {
  332. /**
  333. * @var Backend | \PHPUnit_Framework_MockObject_MockObject $backend
  334. */
  335. $backend = $this->createMock(\OC\User\Database::class);
  336. $backend->expects($this->any())
  337. ->method('implementsActions')
  338. ->will($this->returnCallback(function ($actions) {
  339. if ($actions === \OC\User\Backend::SET_DISPLAYNAME) {
  340. return true;
  341. } else {
  342. return false;
  343. }
  344. }));
  345. $user = new User('foo', $backend);
  346. $this->assertFalse($user->setDisplayName(' '));
  347. $this->assertEquals('foo',$user->getDisplayName());
  348. }
  349. public function testSetDisplayNameNotSupported() {
  350. /**
  351. * @var Backend | \PHPUnit_Framework_MockObject_MockObject $backend
  352. */
  353. $backend = $this->createMock(\OC\User\Database::class);
  354. $backend->expects($this->any())
  355. ->method('implementsActions')
  356. ->willReturn(false);
  357. $backend->expects($this->never())
  358. ->method('setDisplayName');
  359. $user = new User('foo', $backend);
  360. $this->assertFalse($user->setDisplayName('Foo'));
  361. $this->assertEquals('foo',$user->getDisplayName());
  362. }
  363. public function testSetPasswordHooks() {
  364. $hooksCalled = 0;
  365. $test = $this;
  366. /**
  367. * @var Backend | \PHPUnit_Framework_MockObject_MockObject $backend
  368. */
  369. $backend = $this->createMock(\Test\Util\User\Dummy::class);
  370. $backend->expects($this->once())
  371. ->method('setPassword');
  372. /**
  373. * @param User $user
  374. * @param string $password
  375. */
  376. $hook = function ($user, $password) use ($test, &$hooksCalled) {
  377. $hooksCalled++;
  378. $test->assertEquals('foo', $user->getUID());
  379. $test->assertEquals('bar', $password);
  380. };
  381. $emitter = new PublicEmitter();
  382. $emitter->listen('\OC\User', 'preSetPassword', $hook);
  383. $emitter->listen('\OC\User', 'postSetPassword', $hook);
  384. $backend->expects($this->any())
  385. ->method('implementsActions')
  386. ->will($this->returnCallback(function ($actions) {
  387. if ($actions === \OC\User\Backend::SET_PASSWORD) {
  388. return true;
  389. } else {
  390. return false;
  391. }
  392. }));
  393. $user = new User('foo', $backend, $emitter);
  394. $user->setPassword('bar','');
  395. $this->assertEquals(2, $hooksCalled);
  396. }
  397. public function dataDeleteHooks() {
  398. return [
  399. [true, 2],
  400. [false, 1],
  401. ];
  402. }
  403. /**
  404. * @dataProvider dataDeleteHooks
  405. * @param bool $result
  406. * @param int $expectedHooks
  407. */
  408. public function testDeleteHooks($result, $expectedHooks) {
  409. $hooksCalled = 0;
  410. $test = $this;
  411. /**
  412. * @var Backend | \PHPUnit_Framework_MockObject_MockObject $backend
  413. */
  414. $backend = $this->createMock(\Test\Util\User\Dummy::class);
  415. $backend->expects($this->once())
  416. ->method('deleteUser')
  417. ->willReturn($result);
  418. $emitter = new PublicEmitter();
  419. $user = new User('foo', $backend, $emitter);
  420. /**
  421. * @param User $user
  422. */
  423. $hook = function ($user) use ($test, &$hooksCalled) {
  424. $hooksCalled++;
  425. $test->assertEquals('foo', $user->getUID());
  426. };
  427. $emitter->listen('\OC\User', 'preDelete', $hook);
  428. $emitter->listen('\OC\User', 'postDelete', $hook);
  429. $config = $this->createMock(IConfig::class);
  430. $commentsManager = $this->createMock(ICommentsManager::class);
  431. $notificationManager = $this->createMock(INotificationManager::class);
  432. if ($result) {
  433. $config->expects($this->once())
  434. ->method('deleteAllUserValues')
  435. ->with('foo');
  436. $commentsManager->expects($this->once())
  437. ->method('deleteReferencesOfActor')
  438. ->with('users', 'foo');
  439. $commentsManager->expects($this->once())
  440. ->method('deleteReadMarksFromUser')
  441. ->with($user);
  442. $notification = $this->createMock(INotification::class);
  443. $notification->expects($this->once())
  444. ->method('setUser')
  445. ->with('foo');
  446. $notificationManager->expects($this->once())
  447. ->method('createNotification')
  448. ->willReturn($notification);
  449. $notificationManager->expects($this->once())
  450. ->method('markProcessed')
  451. ->with($notification);
  452. } else {
  453. $config->expects($this->never())
  454. ->method('deleteAllUserValues');
  455. $commentsManager->expects($this->never())
  456. ->method('deleteReferencesOfActor');
  457. $commentsManager->expects($this->never())
  458. ->method('deleteReadMarksFromUser');
  459. $notificationManager->expects($this->never())
  460. ->method('createNotification');
  461. $notificationManager->expects($this->never())
  462. ->method('markProcessed');
  463. }
  464. $this->overwriteService('NotificationManager', $notificationManager);
  465. $this->overwriteService('CommentsManager', $commentsManager);
  466. $this->overwriteService('AllConfig', $config);
  467. $this->assertSame($result, $user->delete());
  468. $this->restoreService('AllConfig');
  469. $this->restoreService('CommentsManager');
  470. $this->restoreService('NotificationManager');
  471. $this->assertEquals($expectedHooks, $hooksCalled);
  472. }
  473. public function testGetCloudId() {
  474. /**
  475. * @var Backend | \PHPUnit_Framework_MockObject_MockObject $backend
  476. */
  477. $backend = $this->createMock(\Test\Util\User\Dummy::class);
  478. $urlGenerator = $this->getMockBuilder('\OC\URLGenerator')
  479. ->setMethods(['getAbsoluteURL'])
  480. ->disableOriginalConstructor()->getMock();
  481. $urlGenerator
  482. ->expects($this->any())
  483. ->method('getAbsoluteURL')
  484. ->withAnyParameters()
  485. ->willReturn('http://localhost:8888/owncloud');
  486. $user = new User('foo', $backend, null, null, $urlGenerator);
  487. $this->assertEquals('foo@localhost:8888/owncloud', $user->getCloudId());
  488. }
  489. public function testSetEMailAddressEmpty() {
  490. /**
  491. * @var Backend | \PHPUnit_Framework_MockObject_MockObject $backend
  492. */
  493. $backend = $this->createMock(\Test\Util\User\Dummy::class);
  494. $test = $this;
  495. $hooksCalled = 0;
  496. /**
  497. * @param IUser $user
  498. * @param string $feature
  499. * @param string $value
  500. */
  501. $hook = function (IUser $user, $feature, $value) use ($test, &$hooksCalled) {
  502. $hooksCalled++;
  503. $test->assertEquals('eMailAddress', $feature);
  504. $test->assertEquals('', $value);
  505. };
  506. $emitter = new PublicEmitter();
  507. $emitter->listen('\OC\User', 'changeUser', $hook);
  508. $config = $this->createMock(IConfig::class);
  509. $config->expects($this->once())
  510. ->method('deleteUserValue')
  511. ->with(
  512. 'foo',
  513. 'settings',
  514. 'email'
  515. );
  516. $user = new User('foo', $backend, $emitter, $config);
  517. $user->setEMailAddress('');
  518. }
  519. public function testSetEMailAddress() {
  520. /**
  521. * @var Backend | \PHPUnit_Framework_MockObject_MockObject $backend
  522. */
  523. $backend = $this->createMock(\Test\Util\User\Dummy::class);
  524. $test = $this;
  525. $hooksCalled = 0;
  526. /**
  527. * @param IUser $user
  528. * @param string $feature
  529. * @param string $value
  530. */
  531. $hook = function (IUser $user, $feature, $value) use ($test, &$hooksCalled) {
  532. $hooksCalled++;
  533. $test->assertEquals('eMailAddress', $feature);
  534. $test->assertEquals('foo@bar.com', $value);
  535. };
  536. $emitter = new PublicEmitter();
  537. $emitter->listen('\OC\User', 'changeUser', $hook);
  538. $config = $this->createMock(IConfig::class);
  539. $config->expects($this->once())
  540. ->method('setUserValue')
  541. ->with(
  542. 'foo',
  543. 'settings',
  544. 'email',
  545. 'foo@bar.com'
  546. );
  547. $user = new User('foo', $backend, $emitter, $config);
  548. $user->setEMailAddress('foo@bar.com');
  549. }
  550. public function testGetLastLogin() {
  551. /**
  552. * @var Backend | \PHPUnit_Framework_MockObject_MockObject $backend
  553. */
  554. $backend = $this->createMock(\Test\Util\User\Dummy::class);
  555. $config = $this->createMock(IConfig::class);
  556. $config->method('getUserValue')
  557. ->will($this->returnCallback(function ($uid, $app, $key, $default) {
  558. if ($uid === 'foo' && $app === 'login' && $key === 'lastLogin') {
  559. return 42;
  560. } else {
  561. return $default;
  562. }
  563. }));
  564. $user = new User('foo', $backend, null, $config);
  565. $this->assertSame(42, $user->getLastLogin());
  566. }
  567. public function testSetEnabled() {
  568. /**
  569. * @var Backend | \PHPUnit_Framework_MockObject_MockObject $backend
  570. */
  571. $backend = $this->createMock(\Test\Util\User\Dummy::class);
  572. $config = $this->createMock(IConfig::class);
  573. $config->expects($this->once())
  574. ->method('setUserValue')
  575. ->with(
  576. $this->equalTo('foo'),
  577. $this->equalTo('core'),
  578. $this->equalTo('enabled'),
  579. 'true'
  580. );
  581. $user = new User('foo', $backend, null, $config);
  582. $user->setEnabled(true);
  583. }
  584. public function testSetDisabled() {
  585. /**
  586. * @var Backend | \PHPUnit_Framework_MockObject_MockObject $backend
  587. */
  588. $backend = $this->createMock(\Test\Util\User\Dummy::class);
  589. $config = $this->createMock(IConfig::class);
  590. $config->expects($this->once())
  591. ->method('setUserValue')
  592. ->with(
  593. $this->equalTo('foo'),
  594. $this->equalTo('core'),
  595. $this->equalTo('enabled'),
  596. 'false'
  597. );
  598. $user = new User('foo', $backend, null, $config);
  599. $user->setEnabled(false);
  600. }
  601. public function testGetEMailAddress() {
  602. /**
  603. * @var Backend | \PHPUnit_Framework_MockObject_MockObject $backend
  604. */
  605. $backend = $this->createMock(\Test\Util\User\Dummy::class);
  606. $config = $this->createMock(IConfig::class);
  607. $config->method('getUserValue')
  608. ->will($this->returnCallback(function ($uid, $app, $key, $default) {
  609. if ($uid === 'foo' && $app === 'settings' && $key === 'email') {
  610. return 'foo@bar.com';
  611. } else {
  612. return $default;
  613. }
  614. }));
  615. $user = new User('foo', $backend, null, $config);
  616. $this->assertSame('foo@bar.com', $user->getEMailAddress());
  617. }
  618. }