|
24 | 24 |
|
25 | 25 | use OC\Accounts\Account; |
26 | 26 | use OC\Accounts\AccountManager; |
| 27 | +use OCA\Settings\BackgroundJobs\VerifyUserData; |
27 | 28 | use OCP\Accounts\IAccountManager; |
28 | 29 | use OCP\BackgroundJob\IJobList; |
29 | 30 | use OCP\Defaults; |
@@ -770,4 +771,42 @@ public function searchDataProvider(): array { |
770 | 771 | ], |
771 | 772 | ]; |
772 | 773 | } |
| 774 | + |
| 775 | + public function dataCheckEmailVerification(): array { |
| 776 | + return [ |
| 777 | + [ $this-> makeUser( 'steve', 'Steve Smith', '[email protected]'), null], |
| 778 | + [ $this-> makeUser( 'emma', 'Emma Morales', '[email protected]'), '[email protected]'], |
| 779 | + [ $this-> makeUser( '[email protected]', 'Sarah Foster', '[email protected]'), null], |
| 780 | + |
| 781 | + [ $this-> makeUser( '8d29e358-cf69-4849-bbf9-28076c0b908b', 'Alice McPherson', '[email protected]'), '[email protected]'], |
| 782 | + [ $this-> makeUser( '11da2744-3f4d-4c17-8c13-4c057a379237', 'James Loranger', '[email protected]'), ''], |
| 783 | + ]; |
| 784 | + } |
| 785 | + |
| 786 | + /** |
| 787 | + * @dataProvider dataCheckEmailVerification |
| 788 | + */ |
| 789 | + public function testCheckEmailVerification(IUser $user, ?string $newEmail): void { |
| 790 | + $account = $this->accountManager->getAccount($user); |
| 791 | + $emailUpdated = false; |
| 792 | + |
| 793 | + if (!empty($newEmail)) { |
| 794 | + $account->getProperty(IAccountManager::PROPERTY_EMAIL)->setValue($newEmail); |
| 795 | + $emailUpdated = true; |
| 796 | + } |
| 797 | + |
| 798 | + if ($emailUpdated) { |
| 799 | + $this->jobList->expects($this->once()) |
| 800 | + ->method('add') |
| 801 | + ->with(VerifyUserData::class); |
| 802 | + } else { |
| 803 | + $this->jobList->expects($this->never()) |
| 804 | + ->method('add') |
| 805 | + ->with(VerifyUserData::class); |
| 806 | + } |
| 807 | + |
| 808 | + /** @var array $oldData */ |
| 809 | + $oldData = $this->invokePrivate($this->accountManager, 'getUser', [$user, false]); |
| 810 | + $this->invokePrivate($this->accountManager, 'checkEmailVerification', [$account, $oldData]); |
| 811 | + } |
773 | 812 | } |
0 commit comments