ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
SelfRegistrationTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use ilObjUser;
28use ILIAS\LegalDocuments\test\ContainerMock;
32use PHPUnit\Framework\TestCase;
33
34require_once __DIR__ . '/../../ContainerMock.php';
35
36class SelfRegistrationTest extends TestCase
37{
38 use ContainerMock;
39
40 public function testConstruct(): void
41 {
42 $this->assertInstanceOf(SelfRegistration::class, new SelfRegistration(
43 'foo',
44 $this->mock(UI::class),
45 $this->mock(User::class),
46 $this->mock(Provide::class),
47 $this->fail(...),
48 $this->fail(...)
49 ));
50 }
51
52 public function testLegacyInputGUIs(): void
53 {
54 $instance = new SelfRegistration(
55 'foo',
56 $this->mock(UI::class),
57 $this->mockTree(User::class, ['matchingDocument' => new Ok($this->mock(Document::class))]),
58 $this->mock(Provide::class),
59 fn() => 'rendered',
60 $this->fail(...),
61 $this->mock(...)
62 );
63
64 $guis = $instance->legacyInputGUIs();
65 $this->assertSame(3, count($guis));
66 }
67
68 public function testSaveLegacyForm(): void
69 {
70 $instance = new SelfRegistration(
71 'foo',
72 $this->mock(UI::class),
73 $this->mockTree(User::class, ['matchingDocument' => new Ok($this->mock(Document::class))]),
74 $this->mock(Provide::class),
75 $this->fail(...),
76 $this->fail(...),
77 $this->fail(...)
78 );
79
80 $this->assertTrue($instance->saveLegacyForm($this->mockTree(ilPropertyFormGUI::class, ['getInput' => true])));
81 }
82
83 public function testSaveLegacyFormFailed(): void
84 {
85 $instance = new SelfRegistration(
86 'foo',
87 $this->mock(UI::class),
88 $this->mockTree(User::class, ['matchingDocument' => new Ok($this->mock(Document::class))]),
89 $this->mock(Provide::class),
90 $this->fail(...),
91 $this->fail(...),
92 $this->fail(...)
93 );
94
95 $checkbox = $this->mock(ilCheckboxInputGUI::class);
96 $checkbox->expects(self::once())->method('setAlert');
97
98 $form = $this->mockTree(ilPropertyFormGUI::class, ['getInput' => false]);
99 $form->expects(self::once())->method('getItemByPostVar')->with('accept_foo')->willReturn($checkbox);
100
101 $this->assertFalse($instance->saveLegacyForm($form));
102 }
103
104 public function testUserCreation(): void
105 {
106 $user = $this->mock(ilObjUser::class);
107 $ldoc_user = $this->mock(User::class);
108 $ldoc_user->expects(self::once())->method('acceptMatchingDocument');
109
110 $instance = new SelfRegistration(
111 'foo',
112 $this->mock(UI::class),
113 $this->mock(User::class),
114 $this->mock(Provide::class),
115 $this->fail(...),
116 function (ilObjUser $u) use ($user, $ldoc_user): User {
117 $this->assertSame($user, $u);
118 return $ldoc_user;
119 },
120 $this->fail(...)
121 );
122
123 $instance->userCreation($user);
124 }
125
126 public function testUserCreationFailed(): void
127 {
128 $user = $this->mock(ilObjUser::class);
129 $ldoc_user = $this->mock(User::class);
130 $ldoc_user->expects(self::once())->method('acceptMatchingDocument')->willReturnCallback(function () {
131 throw new \ILIAS\Data\NotOKException('This is not ok.');
132 });
133
134 $ldoc_user->expects(self::once())->method('acceptAnyDocument');
135
136 $instance = new SelfRegistration(
137 'foo',
138 $this->mock(UI::class),
139 $this->mock(User::class),
140 $this->mock(Provide::class),
141 $this->fail(...),
142 function (ilObjUser $u) use ($user, $ldoc_user): User {
143 $this->assertSame($user, $u);
144 return $ldoc_user;
145 },
146 $this->fail(...)
147 );
148
149 $instance->userCreation($user);
150 }
151}
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Ok.php:31
This class represents a checkbox property in a property form.
User class.
This class represents a property form user interface.