ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
ProfileChangeMailTokenDBRepositoryTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
24 {
26  {
27  $old_email = 'oldemail@ilias.de';
28  $our_token = hash('md5', '5' . '-' . $old_email);
29  $new_email = 'newemail@ilias.de';
30  $db_mock = $this->createMock(ilDBInterface::class);
31  $db_mock->expects($this->once())->method('replace')->willReturn(1);
32 
33  $user_mock = $this->createMock(\ilObjUser::class);
34  $user_mock->expects($this->once())->method('getId')->willReturn(5);
35  $user_mock->expects($this->once())->method('getEmail')->willReturn($old_email);
36 
37  $repository = new ProfileChangeMailTokenDBRepository($db_mock);
38 
39  $returned_token = $repository->getNewTokenForUser($user_mock, $new_email);
40 
41  $this->assertEquals($returned_token, $our_token);
42  }
43 
44  public function testGetNewEmailForUserReturnsEmail() : void
45  {
46  $old_email = 'oldemail@ilias.de';
47  $our_token = hash('md5', '5' . '-' . $old_email);
48  $new_email = 'newemail@ilias.de';
49  $db_mock = $this->createMock(ilDBInterface::class);
50  $db_mock->expects($this->once())->method('fetchObject')->willReturn((object) ['new_email' => $new_email]);
51 
52  $user_mock = $this->createMock(\ilObjUser::class);
53  $user_mock->expects($this->once())->method('getId')->willReturn(5);
54  $user_mock->expects($this->once())->method('getEmail')->willReturn($old_email);
55 
56  $repository = new ProfileChangeMailTokenDBRepository($db_mock);
57 
58  $returned_email = $repository->getNewEmailForUser($user_mock, $our_token);
59 
60  $this->assertEquals($returned_email, $new_email);
61  }
62 
64  {
65  $old_email = 'oldemail@ilias.de';
66  $our_token = hash('md5', '5' . '-' . $old_email);
67 
68  $db_mock = $this->createMock(ilDBInterface::class);
69  $db_mock->expects($this->never())->method('fetchObject');
70 
71  $user_mock = $this->createMock(\ilObjUser::class);
72  $user_mock->expects($this->once())->method('getId')->willReturn(2);
73  $user_mock->expects($this->once())->method('getEmail')->willReturn($old_email);
74 
75  $repository = new ProfileChangeMailTokenDBRepository($db_mock);
76 
77  $returned_email = $repository->getNewEmailForUser($user_mock, $our_token);
78 
79  $this->assertEquals($returned_email, '');
80  }
81 }