true, 'demo.protected_users' => ['admin'], 'demo.message' => null, ]); }); test('nobody is protected while demo mode is off', function () { config(['demo.enabled' => false]); $this->assertFalse(Demo::enabled()); $this->assertFalse(Demo::isProtectedUser(new User(['username' => 'admin']))); }); test('a guest is never protected', function () { $this->assertFalse(Demo::isProtectedUser(null)); }); test('a protected account is matched on its username', function () { $this->assertTrue(Demo::isProtectedUser(new User(['username' => 'admin']))); }); test('a protected account is matched on its email', function () { config(['demo.protected_users' => ['admin@example.com']]); $this->assertTrue(Demo::isProtectedUser(new User(['email' => 'admin@example.com']))); }); test('matching ignores case on both sides', function () { config(['demo.protected_users' => ['ADMIN']]); $this->assertTrue(Demo::isProtectedUser(new User(['username' => 'Admin']))); }); test('an ordinary account is not protected', function () { $this->assertFalse(Demo::isProtectedUser(new User([ 'username' => 'jane', 'email' => 'jane@example.com', ]))); }); test('a user without a username is not protected by an empty match', function () { config(['demo.protected_users' => ['']]); $this->assertFalse(Demo::isProtectedUser(new User(['email' => 'jane@example.com']))); }); test('the configured message overrides every reason', function () { config(['demo.message' => 'Nope.']); $this->assertSame('Nope.', Demo::message()); $this->assertSame('Nope.', Demo::message('Something more specific.')); }); test('a reason falls back to the generic refusal', function () { $this->assertSame('This action is disabled in the demo.', Demo::message()); $this->assertSame('Something more specific.', Demo::message('Something more specific.')); });