ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
SettingsTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
26use ILIAS\LegalDocuments\test\ContainerMock;
29use PHPUnit\Framework\TestCase;
30
31require_once __DIR__ . '/bootstrap.php';
32
33class SettingsTest extends TestCase
34{
35 use ContainerMock;
36
37 public function testConstruct(): void
38 {
39 $this->assertInstanceOf(Settings::class, new Settings($this->mock(SelectSetting::class)));
40 }
41
42 public function testEnabled(): void
43 {
44 $this->assertSelect('enabled', 'tos_status', 'boolean');
45 }
46
47 public function testValidateOnLogin(): void
48 {
49 $this->assertSelect('validateOnLogin', 'tos_reevaluate_on_login', 'boolean');
50 }
51
52 public function testDeleteUserOnWithdrawal(): void
53 {
54 $this->assertSelect('deleteUserOnWithdrawal', 'tos_withdrawal_usr_deletion', 'boolean');
55 }
56
57 public function testAdminEmail(): void
58 {
59 $this->assertSelect('adminEmail', 'admin_email', 'string');
60 }
61
62 public function testAuthMode(): void
63 {
64 $this->assertSelect('authMode', 'auth_mode', 'string');
65 }
66
67 public function testLastResetDate(): void
68 {
69 $this->assertSelect('lastResetDate', 'tos_last_reset', 'dateTime');
70 }
71
72 private function assertSelect(string $method, string $key, string $type): void
73 {
74 $setting = $this->mock(Setting::class);
75 $convert = $this->mock(Convert::class);
76
77 $marshal = $this->mockMethod(Marshal::class, $type, [], $convert);
78
79 $settings = $this->mock(SelectSetting::class);
80 $settings->expects(self::once())->method('typed')->willReturnCallback(function (string $k, callable $select) use ($marshal, $convert, $setting, $key) {
81 $this->assertSame($key, $k);
82 $this->assertSame($convert, $select($marshal));
83 return $setting;
84 });
85
86 $this->assertSame($setting, (new Settings($settings))->$method());
87 }
88}
assertSelect(string $method, string $key, string $type)
ilSetting $setting
Definition: class.ilias.php:68