Initial commit

This commit is contained in:
root
2026-05-09 17:28:23 +02:00
commit 9d73f82529
5575 changed files with 281989 additions and 0 deletions
+50
View File
@@ -0,0 +1,50 @@
<?php
test('that true is true', function () {
expect(true)->toBeTrue();
expect(true)->toBeBool();
expect(true)->not->toBeFalse();
expect(true)->not->toBeNull();
expect(true)->toEqual(true);
expect(true === true)->toBeTrue();
});
test('that false is false', function () {
expect(false)->toBeFalse();
expect(false)->toBeBool();
expect(false)->not->toBeTrue();
expect(false)->not->toBeNull();
expect(false)->toEqual(false);
expect(false === false)->toBeTrue();
});
test('that null is null', function () {
expect(null)->toBeNull();
expect(null)->not->toBeTrue();
expect(null)->not->toBeFalse();
expect(null === null)->toBeTrue();
});
test('basic arithmetic operations', function () {
expect(1 + 1)->toBe(2);
expect(2 * 2)->toBe(4);
expect(10 - 5)->toBe(5);
expect(8 / 2)->toBe(4);
expect(10 % 3)->toBe(1);
});
test('string operations', function () {
expect('hello')->toBeString();
expect('hello')->toHaveLength(5);
expect('hello world')->toContain('world');
expect('hello')->not->toBeEmpty();
expect('')->toBeEmpty();
});
test('array operations', function () {
$array = [1, 2, 3];
expect($array)->toBeArray();
expect($array)->toHaveCount(3);
expect($array)->toContain(2);
expect($array)->not->toBeEmpty();
});
+255
View File
@@ -0,0 +1,255 @@
<?php
use App\Models\Miscellaneous\WebsiteSetting;
use App\Services\SettingsService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
uses(TestCase::class, RefreshDatabase::class);
test('settings service returns default value when setting not found', function () {
$settingsService = app(SettingsService::class);
$value = $settingsService->getOrDefault('nonexistent_key', 'default_value');
// Value checks
expect($value)->toBe('default_value');
expect($value)->toBeString();
expect(strlen($value))->toBeGreaterThan(0);
expect(strlen($value))->toBe(13);
// Type checks
expect($value)->not->toBeNull();
expect($value)->not->toBeInt();
expect($value)->not->toBeBool();
expect($value)->not->toBeArray();
// Content checks
expect($value)->toContain('default');
expect($value)->toContain('_');
expect($value)->toStartWith('default');
expect($value)->toEndWith('value');
// Verify setting does not exist in database
$this->assertDatabaseMissing('website_settings', [
'key' => 'nonexistent_key',
]);
// Count check
expect(WebsiteSetting::where('key', 'nonexistent_key')->count())->toBe(0);
});
test('settings service returns existing setting value', function () {
installHotel();
// Clear cache and re-instantiate service to get fresh data
SettingsService::clearCache();
$settingsService = new SettingsService;
$value = $settingsService->getOrDefault('disable_registration', 'default');
// Value checks
expect($value)->toBe('0');
expect($value)->not->toBe('default');
expect($value)->toBeString();
expect(strlen($value))->toBe(1);
// Type checks
expect($value)->not->toBeNull();
expect($value)->not->toBeInt();
expect($value)->not->toBeBool();
// Content checks
expect($value)->toBeNumeric();
expect($value)->toBe('0');
// Verify setting exists in database
$this->assertDatabaseHas('website_settings', [
'key' => 'disable_registration',
'value' => '0',
]);
// Retrieve setting and verify all fields
$setting = WebsiteSetting::where('key', 'disable_registration')->first();
expect($setting)->not->toBeNull();
expect($setting->key)->toBe('disable_registration');
expect($setting->value)->toBe('0');
expect($setting->id)->toBeInt();
expect($setting->id)->toBeGreaterThan(0);
});
test('settings service returns default for non-existent key', function () {
installHotel();
// Clear cache and re-instantiate service to get fresh data
SettingsService::clearCache();
$settingsService = new SettingsService;
$value = $settingsService->getOrDefault('non_existent_key', 'default');
// Value checks
expect($value)->toBe('default');
expect($value)->toBeString();
expect(strlen($value))->toBe(7);
// Type checks
expect($value)->not->toBeNull();
// Verify setting does not exist in database
$this->assertDatabaseMissing('website_settings', [
'key' => 'non_existent_key',
]);
// Count check
expect(WebsiteSetting::where('key', 'non_existent_key')->count())->toBe(0);
expect(WebsiteSetting::where('key', 'non_existent_key')->exists())->toBeFalse();
// Verify existing settings are not affected
expect(WebsiteSetting::count())->toBeGreaterThan(0);
});
test('install helper creates basic settings', function () {
// Check current state before installHotel
$themeExistedBefore = WebsiteSetting::where('key', 'theme')->exists();
$countBefore = WebsiteSetting::count();
installHotel();
// Verify settings exist after installHotel
expect(WebsiteSetting::where('key', 'theme')->exists())->toBeTrue();
expect(WebsiteSetting::where('key', 'max_accounts_per_ip')->exists())->toBeTrue();
expect(WebsiteSetting::where('key', 'disable_registration')->exists())->toBeTrue();
// Count check
$countAfter = WebsiteSetting::count();
expect($countAfter)->toBeGreaterThanOrEqual(9);
expect($countAfter)->toBeGreaterThan($countBefore);
// Verify all expected settings in database
$this->assertDatabaseHas('website_settings', ['key' => 'theme']);
$this->assertDatabaseHas('website_settings', ['key' => 'max_accounts_per_ip']);
$this->assertDatabaseHas('website_settings', ['key' => 'disable_registration']);
$this->assertDatabaseHas('website_settings', ['key' => 'requires_beta_code']);
$this->assertDatabaseHas('website_settings', ['key' => 'username_regex']);
$this->assertDatabaseHas('website_settings', ['key' => 'start_motto']);
$this->assertDatabaseHas('website_settings', ['key' => 'start_look']);
$this->assertDatabaseHas('website_settings', ['key' => 'start_credits']);
$this->assertDatabaseHas('website_settings', ['key' => 'hotel_home_room']);
$this->assertDatabaseHas('website_settings', ['key' => 'enable_discord_webhook']);
// Verify specific setting values
$themeSetting = WebsiteSetting::where('key', 'theme')->first();
expect($themeSetting->value)->toBe('atom');
expect($themeSetting->comment)->toBe('Theme');
$creditsSetting = WebsiteSetting::where('key', 'start_credits')->first();
expect($creditsSetting->value)->toBe('1000');
// Verify setting count
$settingsCount = WebsiteSetting::count();
expect($settingsCount)->toBeGreaterThanOrEqual(9);
expect($settingsCount)->toBeLessThan(100);
});
test('settings service cache works correctly', function () {
installHotel();
// Clear cache
SettingsService::clearCache();
// Create service instance and get value
$settingsService1 = new SettingsService;
$value1 = $settingsService1->getOrDefault('theme', 'default');
expect($value1)->toBe('atom');
// Create another service instance and get same value (should use cache)
$settingsService2 = new SettingsService;
$value2 = $settingsService2->getOrDefault('theme', 'default');
expect($value2)->toBe('atom');
// Both values should be identical
expect($value1)->toBe($value2);
// Verify value is string
expect($value1)->toBeString();
expect($value2)->toBeString();
});
test('settings can be updated and retrieved', function () {
installHotel();
// Clear cache
SettingsService::clearCache();
// Verify initial value
$settingsService = new SettingsService;
$initialValue = $settingsService->getOrDefault('test_setting', 'initial');
expect($initialValue)->toBe('initial');
// Create setting in database
WebsiteSetting::create([
'key' => 'test_setting',
'value' => 'updated_value',
'comment' => 'Test comment',
]);
// Clear cache to get fresh data
SettingsService::clearCache();
$settingsService2 = new SettingsService;
$updatedValue = $settingsService2->getOrDefault('test_setting', 'default');
// Verify updated value
expect($updatedValue)->toBe('updated_value');
expect($updatedValue)->not->toBe('initial');
expect($updatedValue)->toBeString();
expect(strlen($updatedValue))->toBe(13);
// Database verification
$this->assertDatabaseHas('website_settings', [
'key' => 'test_setting',
'value' => 'updated_value',
]);
// Retrieve and verify all fields
$setting = WebsiteSetting::where('key', 'test_setting')->first();
expect($setting->comment)->toBe('Test comment');
expect($setting->id)->toBeInt();
expect($setting->id)->toBeGreaterThan(0);
});
test('settings service handles empty string default', function () {
installHotel();
SettingsService::clearCache();
$settingsService = new SettingsService;
$value = $settingsService->getOrDefault('non_existent_key_2', '');
// Verify empty string is returned
expect($value)->toBe('');
expect($value)->toBeString();
expect(strlen($value))->toBe(0);
expect($value)->toBeEmpty();
// Verify setting does not exist
$this->assertDatabaseMissing('website_settings', [
'key' => 'non_existent_key_2',
]);
});
test('settings service handles numeric defaults', function () {
installHotel();
SettingsService::clearCache();
$settingsService = new SettingsService;
$value = $settingsService->getOrDefault('non_existent_key_3', '12345');
// Verify numeric string is returned
expect($value)->toBe('12345');
expect($value)->toBeString();
expect($value)->toBeNumeric();
expect(strlen($value))->toBe(5);
expect((int) $value)->toBe(12345);
// Verify setting does not exist
$this->assertDatabaseMissing('website_settings', [
'key' => 'non_existent_key_3',
]);
});
+231
View File
@@ -0,0 +1,231 @@
<?php
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
uses(TestCase::class, RefreshDatabase::class);
test('user can be created with factory', function () {
installHotel();
$user = User::factory()->create([
'username' => 'TestUser',
'mail' => 'test@example.com',
]);
// Basic property checks
expect($user->username)->toBe('TestUser');
expect($user->mail)->toBe('test@example.com');
expect($user->password)->not->toBe('password'); // Should be hashed
expect($user->id)->toBeInt();
expect($user->id)->toBeGreaterThan(0);
// Type checks
expect($user->username)->toBeString();
expect($user->mail)->toBeString();
expect($user->password)->toBeString();
expect($user->id)->toBeNumeric();
// String length checks
expect($user->username)->toHaveLength(8);
expect($user->mail)->toHaveLength(16);
expect($user->password)->toHaveLength(60); // Bcrypt hash length
// Not null checks
expect($user->username)->not->toBeNull();
expect($user->mail)->not->toBeNull();
expect($user->password)->not->toBeNull();
expect($user->id)->not->toBeNull();
// Contains checks
expect($user->mail)->toContain('@');
expect($user->mail)->toContain('example.com');
// Verify user exists in database with all fields
$this->assertDatabaseHas('users', [
'id' => $user->id,
'username' => 'TestUser',
'mail' => 'test@example.com',
]);
// Verify count
expect(User::count())->toBe(1);
// Verify we can retrieve the user
$retrievedUser = User::find($user->id);
expect($retrievedUser)->not->toBeNull();
expect($retrievedUser->username)->toBe('TestUser');
expect($retrievedUser->mail)->toBe('test@example.com');
});
test('user factory creates proper defaults', function () {
installHotel();
$user = User::factory()->create();
// Basic default checks
expect($user->username)->toBe('NewRetro');
expect((int) $user->credits)->toBeGreaterThan(0);
expect($user->ip_register)->toBe('127.0.0.1');
expect($user->ip_current)->toBe('127.0.0.1');
expect($user->id)->toBeInt();
expect($user->id)->toBeGreaterThan(0);
expect($user->account_created)->toBeInt();
expect($user->last_login)->toBeInt();
expect($user->password)->not->toBeEmpty();
// Type checks
expect($user->username)->toBeString();
expect($user->credits)->toBeInt();
expect($user->ip_register)->toBeString();
expect($user->ip_current)->toBeString();
expect($user->account_created)->toBeInt();
expect($user->last_login)->toBeInt();
expect($user->password)->toBeString();
// IP format checks
expect($user->ip_register)->toContain('.');
expect($user->ip_current)->toContain('.');
expect($user->ip_register)->toHaveLength(9);
expect($user->ip_current)->toHaveLength(9);
// Credits checks
expect($user->credits)->toBeGreaterThanOrEqual(0);
expect($user->credits)->toBeLessThan(10000);
// Timestamp checks
expect($user->account_created)->toBeGreaterThan(0);
expect($user->last_login)->toBeGreaterThan(0);
expect($user->account_created)->toBeLessThan(time() + 10);
expect($user->last_login)->toBeLessThan(time() + 10);
// Verify user exists in database
$this->assertDatabaseHas('users', [
'id' => $user->id,
'username' => 'NewRetro',
'ip_register' => '127.0.0.1',
'ip_current' => '127.0.0.1',
]);
// Verify count
expect(User::count())->toBe(1);
// Verify we can retrieve the user
$retrievedUser = User::find($user->id);
expect($retrievedUser)->not->toBeNull();
expect($retrievedUser->username)->toBe('NewRetro');
});
test('user can be updated', function () {
installHotel();
$user = User::factory()->create([
'username' => 'OriginalUser',
'mail' => 'original@example.com',
]);
$originalId = $user->id;
// Update user
$user->username = 'UpdatedUser';
$user->mail = 'updated@example.com';
$user->save();
// Refresh from database
$user->refresh();
// Verify updates
expect($user->username)->toBe('UpdatedUser');
expect($user->mail)->toBe('updated@example.com');
expect($user->id)->toBe($originalId);
// Database verification
$this->assertDatabaseHas('users', [
'id' => $originalId,
'username' => 'UpdatedUser',
'mail' => 'updated@example.com',
]);
$this->assertDatabaseMissing('users', [
'id' => $originalId,
'username' => 'OriginalUser',
]);
});
test('user can be deleted', function () {
installHotel();
$user = User::factory()->create([
'username' => 'DeleteMe',
'mail' => 'delete@example.com',
]);
$userId = $user->id;
// Verify user exists
expect(User::find($userId))->not->toBeNull();
expect(User::count())->toBe(1);
// Delete user
$user->delete();
// Verify user is deleted
expect(User::find($userId))->toBeNull();
expect(User::count())->toBe(0);
// Database verification
$this->assertDatabaseMissing('users', [
'id' => $userId,
]);
});
test('user password is hashed', function () {
installHotel();
$user = User::factory()->create([
'username' => 'PasswordTest',
'mail' => 'password@example.com',
'password' => 'mysecretpassword',
]);
// Verify password is hashed (bcrypt starts with $2y$)
expect($user->password)->toStartWith('$2y$');
expect($user->password)->toHaveLength(60);
expect($user->password)->not->toBe('mysecretpassword');
// Verify we can check the password
expect(password_verify('mysecretpassword', $user->password))->toBeTrue();
expect(password_verify('wrongpassword', $user->password))->toBeFalse();
});
test('multiple users can be created', function () {
installHotel();
$user1 = User::factory()->create(['username' => 'User1', 'mail' => 'user1@example.com']);
$user2 = User::factory()->create(['username' => 'User2', 'mail' => 'user2@example.com']);
$user3 = User::factory()->create(['username' => 'User3', 'mail' => 'user3@example.com']);
// Verify count
expect(User::count())->toBe(3);
// Verify all users exist
expect(User::find($user1->id))->not->toBeNull();
expect(User::find($user2->id))->not->toBeNull();
expect(User::find($user3->id))->not->toBeNull();
// Verify usernames are unique
expect($user1->username)->not->toBe($user2->username);
expect($user2->username)->not->toBe($user3->username);
expect($user1->username)->not->toBe($user3->username);
// Verify emails are unique
expect($user1->mail)->not->toBe($user2->mail);
expect($user2->mail)->not->toBe($user3->mail);
expect($user1->mail)->not->toBe($user3->mail);
// Database verification
$this->assertDatabaseHas('users', ['username' => 'User1']);
$this->assertDatabaseHas('users', ['username' => 'User2']);
$this->assertDatabaseHas('users', ['username' => 'User3']);
});