Skip to content

Commit 49cfc6e

Browse files
committed
adds tests for logging in with a guest user
1 parent e76e883 commit 49cfc6e

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

tests/AuthManagerTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,38 @@ public function testLoginAndCheckAuth()
112112

113113
$this->assertTrue(Auth::check());
114114
}
115+
116+
/**
117+
* testLoginAfterRegisteringWithSharedGuestEmail verifies the scenario reported
118+
* in rainlab/user-plugin#544: after a guest exists for an email, a real
119+
* registration succeeds and credential lookup resolves to the registered
120+
* account, not the guest.
121+
*/
122+
public function testLoginAfterRegisteringWithSharedGuestEmail()
123+
{
124+
$guest = User::create([
125+
'first_name' => 'Guest',
126+
'email' => 'person@acme.tld',
127+
'is_guest' => true,
128+
]);
129+
130+
$registered = User::create([
131+
'first_name' => 'Registered',
132+
'email' => 'person@acme.tld',
133+
'password' => 'ChangeMe888',
134+
'password_confirmation' => 'ChangeMe888',
135+
]);
136+
137+
$this->assertEquals(2, User::where('email', 'person@acme.tld')->count());
138+
$this->assertTrue($guest->is_guest);
139+
$this->assertFalse((bool) $registered->is_guest);
140+
141+
$found = Auth::attempt([
142+
'email' => 'person@acme.tld',
143+
'password' => 'ChangeMe888',
144+
]);
145+
146+
$this->assertTrue($found);
147+
$this->assertEquals($registered->id, Auth::user()->id);
148+
}
115149
}

0 commit comments

Comments
 (0)