ILIAS  trunk Revision v11.0_alpha-1702-gfd3ecb7f852
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ChangeMailTokenTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\User\Tests;
22 
26 
28 {
29  public function testGettersReturnCorrectValues(): void
30  {
31  $user_id = 5;
32  $old_email = 'oldemmail@ilias.de';
33  $new_email = 'newemail@ilias.de';
34  $timestamp = time();
35  $status = ChangeMailStatus::Login;
36  $token_string = hash('md5', "{$timestamp}-{$user_id}-{$old_email}-{$status->value}");
37 
38  $token1 = new ChangeMailToken(
39  $user_id,
40  $old_email,
41  $new_email,
42  $timestamp,
43  $status,
44  $token_string
45  );
46 
47  $this->assertEquals($user_id, $token1->getUserId());
48  $this->assertEquals($old_email, $token1->getCurrentEmail());
49  $this->assertEquals($new_email, $token1->getNewEmail());
50  $this->assertEquals($timestamp, $token1->getCreatedTimestamp());
51  $this->assertEquals($status, $token1->getStatus());
52  $this->assertEquals($token_string, $token1->getToken());
53 
54  $token2 = new ChangeMailToken(
55  $user_id,
56  $old_email,
57  $new_email,
59  );
60 
61  $this->assertEquals($user_id, $token2->getUserId());
62  $this->assertEquals($old_email, $token2->getCurrentEmail());
63  $this->assertEquals($new_email, $token2->getNewEmail());
64  $this->assertEquals($timestamp, $token2->getCreatedTimestamp());
65  $this->assertEquals($status, $token2->getStatus());
66  $this->assertEquals($token_string, $token2->getToken());
67  }
68 
70  {
71  $user_id = 5;
72  $old_email = 'oldemmail@ilias.de';
73  $new_email = 'newemail@ilias.de';
74 
75  $token1 = new ChangeMailToken(
76  $user_id,
77  $old_email,
78  $new_email,
79  time()
80  );
81 
82  $this->assertEquals(true, $token1->isTokenValidForCurrentStatus($this->createMock(\ilSetting::class)));
83 
84  $token2 = new ChangeMailToken(
85  $user_id,
86  $old_email,
87  $new_email,
88  time() - ChangeMailStatus::VALIDITY_LOGIN - 60
89  );
90 
91  $this->assertEquals(false, $token2->isTokenValidForCurrentStatus($this->createMock(\ilSetting::class)));
92 
93  $token3 = new ChangeMailToken(
94  $user_id,
95  $old_email,
96  $new_email,
98  ChangeMailStatus::EmailConfirmation
99  );
100 
101  $settings_mock = $this->createMock(\ilSetting::class);
102  $settings_mock->expects($this->once())->method('get')->willReturn('0');
103 
104  $this->assertEquals(false, $token3->isTokenValidForCurrentStatus($settings_mock));
105  }
106 }
foreach($mandatory_scripts as $file) $timestamp
Definition: buildRTE.php:70