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