From 30095519e478ddb1fd5cd2dba04161a665855551 Mon Sep 17 00:00:00 2001 From: Doar Mihai Date: Sun, 19 Jul 2026 16:43:13 +0300 Subject: [PATCH] feat: add cms_type and WordPress credential fields to sites --- app/Models/Site.php | 5 ++++ database/factories/SiteFactory.php | 12 +++++++++ ...9_134201_add_cms_fields_to_sites_table.php | 24 +++++++++++++++++ tests/Feature/SiteModelTest.php | 27 +++++++++++++++++++ 4 files changed, 68 insertions(+) create mode 100644 database/migrations/2026_07_19_134201_add_cms_fields_to_sites_table.php diff --git a/app/Models/Site.php b/app/Models/Site.php index cd39e75..c26a0c6 100644 --- a/app/Models/Site.php +++ b/app/Models/Site.php @@ -9,9 +9,14 @@ class Site extends Model { use HasFactory; + public const CMS_TYPES = ['wordpress', 'custom', 'other']; + protected $fillable = [ 'name', 'url', 'description', + 'cms_type', + 'wp_username', + 'wp_app_password', ]; } diff --git a/database/factories/SiteFactory.php b/database/factories/SiteFactory.php index c23064b..d62e2f8 100644 --- a/database/factories/SiteFactory.php +++ b/database/factories/SiteFactory.php @@ -15,6 +15,18 @@ class SiteFactory extends Factory 'name' => fake()->company(), 'url' => fake()->url(), 'description' => fake()->optional()->sentence(), + 'cms_type' => 'custom', + 'wp_username' => null, + 'wp_app_password' => null, ]; } + + public function wordpress(): static + { + return $this->state(fn () => [ + 'cms_type' => 'wordpress', + 'wp_username' => fake()->userName(), + 'wp_app_password' => fake()->password(), + ]); + } } diff --git a/database/migrations/2026_07_19_134201_add_cms_fields_to_sites_table.php b/database/migrations/2026_07_19_134201_add_cms_fields_to_sites_table.php new file mode 100644 index 0000000..0bb3811 --- /dev/null +++ b/database/migrations/2026_07_19_134201_add_cms_fields_to_sites_table.php @@ -0,0 +1,24 @@ +string('cms_type')->default('custom')->after('description'); + $table->string('wp_username')->nullable()->after('cms_type'); + $table->string('wp_app_password')->nullable()->after('wp_username'); + }); + } + + public function down(): void + { + Schema::table('sites', function (Blueprint $table) { + $table->dropColumn(['cms_type', 'wp_username', 'wp_app_password']); + }); + } +}; diff --git a/tests/Feature/SiteModelTest.php b/tests/Feature/SiteModelTest.php index 889b0a9..6c9b7ff 100644 --- a/tests/Feature/SiteModelTest.php +++ b/tests/Feature/SiteModelTest.php @@ -23,3 +23,30 @@ test('a site can be created without a description', function () { expect($site->fresh()->description)->toBeNull(); }); + +test('a site defaults to cms_type custom with null WordPress credentials', function () { + $site = Site::create([ + 'name' => 'My Blog', + 'url' => 'https://example.com', + ]); + + expect($site->fresh()) + ->cms_type->toBe('custom') + ->wp_username->toBeNull() + ->wp_app_password->toBeNull(); +}); + +test('a site can be created as WordPress with credentials', function () { + $site = Site::create([ + 'name' => 'My WP Blog', + 'url' => 'https://wp.example.com', + 'cms_type' => 'wordpress', + 'wp_username' => 'admin', + 'wp_app_password' => 'abcd 1234 efgh 5678', + ]); + + expect($site->fresh()) + ->cms_type->toBe('wordpress') + ->wp_username->toBe('admin') + ->wp_app_password->toBe('abcd 1234 efgh 5678'); +});