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', 'dpro_enabled', 'boolean');
45 }
46
47 public function testValidateOnLogin(): void
48 {
49 $this->assertSelect('validateOnLogin', 'dpro_validate_on_login', 'boolean');
50 }
51
52 public function testDeleteUserOnWithdrawal(): void
53 {
54 $this->assertSelect('deleteUserOnWithdrawal', 'dpro_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', 'dpro_last_reset_date', 'dateTime');
70 }
71
72 public function testNoAcceptance(): void
73 {
74 $this->assertSelect('noAcceptance', 'dpro_no_acceptance', 'boolean');
75 }
76
77 private function assertSelect(string $method, string $key, string $type): void
78 {
79 $setting = $this->mock(Setting::class);
80 $convert = $this->mock(Convert::class);
81
82 $marshal = $this->mockMethod(Marshal::class, $type, [], $convert);
83
84 $settings = $this->mock(SelectSetting::class);
85 $settings->expects(self::once())->method('typed')->willReturnCallback(function (string $k, callable $select) use ($marshal, $convert, $setting, $key) {
86 $this->assertSame($key, $k);
87 $this->assertSame($convert, $select($marshal));
88 return $setting;
89 });
90
91 $this->assertSame($setting, (new Settings($settings))->$method());
92 }
93}
assertSelect(string $method, string $key, string $type)
ilSetting $setting
Definition: class.ilias.php:68