ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
UserSettingsTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
31 use ilObjUser;
34 
35 require_once __DIR__ . '/bootstrap.php';
36 
37 class UserSettingsTest extends TestCase
38 {
39  use ContainerMock;
40 
41  public function testConstruct(): void
42  {
43  $this->assertInstanceOf(UserSettings::class, new UserSettings(
44  $this->mock(ilObjUser::class),
45  $this->mock(SelectSetting::class),
46  $this->mock(Refinery::class)
47  ));
48  }
49 
50  public function testWithdrawalRequested(): void
51  {
52  $setting = $this->mock(Setting::class);
53  $convert = $this->mock(Convert::class);
54 
55  $marshal = $this->mockMethod(Marshal::class, 'boolean', [], $convert);
56 
57  $settings = $this->mock(SelectSetting::class);
58  $settings->expects(self::once())->method('typed')->willReturnCallback(function (string $key, callable $select) use ($marshal, $convert, $setting) {
59  $this->assertSame('consent_withdrawal_requested', $key);
60  $this->assertSame($convert, $select($marshal));
61  return $setting;
62  });
63 
64  $instance = new UserSettings(
65  $this->mock(ilObjUser::class),
66  $settings,
67  $this->mock(Refinery::class)
68  );
69 
70  $this->assertSame($setting, $instance->withdrawalRequested());
71  }
72 
73  public function testAgreeDate(): void
74  {
75  $date = new DateTimeImmutable();
76  $return_date = new DateTimeImmutable();
77 
78  $by_trying = $this->mock(ByTrying::class);
79  $by_trying->expects(self::exactly(2))->method('transform')->withConsecutive(['agree date'], [$date])->willReturnOnConsecutiveCalls($return_date, 'another date');
80 
81  $user = $this->mock(ilObjUser::class);
82  $user->expects(self::once())->method('getAgreeDate')->willReturn('agree date');
83  $user->expects(self::once())->method('setAgreeDate')->with('another date');
84  $user->expects(self::once())->method('update');
85 
86  $refinery = $this->mockTree(Refinery::class, ['byTrying' => $by_trying]);
87 
88  $instance = new UserSettings(
89  $user,
90  $this->mock(SelectSetting::class),
91  $refinery
92  );
93 
94  $setting = $instance->agreeDate();
95  $this->assertSame($return_date, $setting->value());
96  $setting->update($date);
97  }
98 }
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200
ilSetting $setting
Definition: class.ilias.php:54
string $key
Consumer key/client ID value.
Definition: System.php:193
Refinery Factory $refinery