42
42
*/
43
43
final class ChoiceAuthTest extends \VuFindTest \Integration \MinkTestCase
44
44
{
45
+ use \VuFindTest \Feature \EmailTrait;
45
46
use \VuFindTest \Feature \LiveDatabaseTrait;
46
47
use \VuFindTest \Feature \UserCreationTrait;
47
48
@@ -60,7 +61,7 @@ public static function setUpBeforeClass(): void
60
61
*
61
62
* @return array
62
63
*/
63
- public function getConfigIniOverrides ()
64
+ protected function getConfigIniOverrides (): array
64
65
{
65
66
return [
66
67
'Catalog ' => [
@@ -80,7 +81,7 @@ public function getConfigIniOverrides()
80
81
*
81
82
* @return array
82
83
*/
83
- public function getConfigIniSSOOverrides ()
84
+ protected function getConfigIniSSOOverrides (): array
84
85
{
85
86
return [
86
87
'ChoiceAuth ' => [
@@ -90,13 +91,29 @@ public function getConfigIniSSOOverrides()
90
91
}
91
92
92
93
/**
93
- * Get Demo .ini override settings for testing ILS functions .
94
+ * Get config .ini override settings for testing ChoiceAuth with Email authentication .
94
95
*
95
- * @param string $bibId Bibliographic record ID to create fake item info for.
96
+ * @return array
97
+ */
98
+ protected function getConfigIniEmailOverrides (): array
99
+ {
100
+ return [
101
+ 'ChoiceAuth ' => [
102
+ 'choice_order ' => 'Database, Email ' ,
103
+ ],
104
+ 'Mail ' => [
105
+ 'testOnly ' => true ,
106
+ 'message_log ' => $ this ->getEmailLogPath (),
107
+ ],
108
+ ];
109
+ }
110
+
111
+ /**
112
+ * Get Demo.ini override settings for testing ILS functions.
96
113
*
97
114
* @return array
98
115
*/
99
- public function getDemoIniOverrides ($ bibId = ' testsample1 ' )
116
+ protected function getDemoIniOverrides (): array
100
117
{
101
118
return [
102
119
'Users ' => ['catuser ' => 'catpass ' ],
@@ -108,7 +125,7 @@ public function getDemoIniOverrides($bibId = 'testsample1')
108
125
*
109
126
* @return array
110
127
*/
111
- public function getSimulatedSSOIniOverrides ()
128
+ protected function getSimulatedSSOIniOverrides (): array
112
129
{
113
130
return [
114
131
'General ' => [
@@ -122,7 +139,7 @@ public function getSimulatedSSOIniOverrides()
122
139
*
123
140
* @return void
124
141
*/
125
- public function testCreateDatabaseUser ()
142
+ public function testCreateDatabaseUser (): void
126
143
{
127
144
$ this ->changeConfigs (
128
145
[
@@ -161,7 +178,7 @@ public function testCreateDatabaseUser()
161
178
*
162
179
* @return void
163
180
*/
164
- public function testProfile ()
181
+ public function testProfile (): void
165
182
{
166
183
$ this ->changeConfigs (
167
184
[
@@ -193,7 +210,7 @@ public function testProfile()
193
210
*
194
211
* @return void
195
212
*/
196
- public function testRecordPageWithILSAndSSO ()
213
+ public function testRecordPageWithILSAndSSO (): void
197
214
{
198
215
// Set up configs and session
199
216
$ this ->changeConfigs (
@@ -212,7 +229,6 @@ public function testRecordPageWithILSAndSSO()
212
229
$ this ->clickCss ($ page , '#loginOptions a ' );
213
230
214
231
// login with ILS
215
- $ this ->clickCss ($ page , '#loginOptions a ' );
216
232
$ this ->fillInLoginForm ($ page , 'catuser ' , 'catpass ' , false , '.authmethod0 ' );
217
233
$ this ->submitLoginForm ($ page , false , '.authmethod0 ' );
218
234
@@ -241,6 +257,43 @@ public function testRecordPageWithILSAndSSO()
241
257
$ this ->clickCss ($ page , '.logoutOptions a.logout ' );
242
258
}
243
259
260
+ /**
261
+ * Test login with Email authentication.
262
+ *
263
+ * @return void
264
+ */
265
+ public function testEmailAuthentication (): void
266
+ {
267
+ // Set up configs, session and message logging:
268
+ $ this ->changeConfigs (
269
+ [
270
+ 'config ' => $ this ->getConfigIniEmailOverrides () + $ this ->getConfigIniOverrides (),
271
+ ]
272
+ );
273
+ $ session = $ this ->getMinkSession ();
274
+ $ session ->visit ($ this ->getVuFindUrl ());
275
+ $ page = $ session ->getPage ();
276
+ $ this ->resetEmailLog ();
277
+
278
+ // Click login and request email:
279
+ $ this ->clickCss ($ page , '#loginOptions a ' );
280
+ $ this ->findCssAndSetValue ($ page , '#login_Email_username ' , 'username1@ignore.com ' );
281
+ $ this ->clickCss ($ page , '.authmethod1 input[type="submit"] ' );
282
+ $ this ->assertEquals (
283
+ 'We have sent a login link to your email address. It may take a few moments for the link to arrive. '
284
+ . "If you don't receive the link shortly, please check also your spam filter. " ,
285
+ $ this ->findCssAndGetText ($ page , '.modal .alert-success ' )
286
+ );
287
+
288
+ // Extract the link from the provided message:
289
+ $ email = file_get_contents ($ this ->getEmailLogPath ());
290
+ preg_match ('/Link to login: <(http.*)>/ ' , $ email , $ matches );
291
+ $ session ->visit ($ matches [1 ]);
292
+
293
+ // Log out
294
+ $ this ->clickCss ($ page , '.logoutOptions a.logout ' );
295
+ }
296
+
244
297
/**
245
298
* Standard teardown method.
246
299
*
0 commit comments