ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
UserSettingsTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use DateTimeImmutable;
29use ILIAS\LegalDocuments\test\ContainerMock;
30use ILIAS\Refinery\Factory as Refinery;
31use ilObjUser;
33use PHPUnit\Framework\TestCase;
34
35require_once __DIR__ . '/bootstrap.php';
36
37class 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 $consecutive = [
80 ['agree date', $return_date],
81 [$date, 'another date']
82 ];
83 $by_trying->expects(self::exactly(2))
84 ->method('transform')
85 ->willReturnCallback(
86 function ($in) use (&$consecutive) {
87 [$expected, $ret] = array_shift($consecutive);
88 $this->assertEquals($expected, $in);
89 return $ret;
90 }
91 );
92
93 $user = $this->mock(ilObjUser::class);
94 $user->expects(self::once())->method('getAgreeDate')->willReturn('agree date');
95 $user->expects(self::once())->method('setAgreeDate')->with('another date');
96 $user->expects(self::once())->method('update');
97
98 $refinery = $this->mockTree(Refinery::class, ['byTrying' => $by_trying]);
99
100 $instance = new UserSettings(
101 $user,
102 $this->mock(SelectSetting::class),
104 );
105
106 $setting = $instance->agreeDate();
107 $this->assertSame($return_date, $setting->value());
108 $setting->update($date);
109 }
110}
Builds data types.
Definition: Factory.php:36
ilSetting $setting
Definition: class.ilias.php:68
User class.