Files
muninn/tests/Feature/SiteModelTest.php
T

70 lines
2.0 KiB
PHP
Raw Normal View History

<?php
use App\Models\Site;
test('a site can be created with name, url, and optional description', function () {
$site = Site::create([
'name' => 'My Blog',
'url' => 'https://example.com',
'description' => 'A blog about things',
]);
expect($site->fresh())
->name->toBe('My Blog')
->url->toBe('https://example.com')
->description->toBe('A blog about things');
});
test('a site can be created without a description', function () {
$site = Site::create([
'name' => 'My Blog',
'url' => 'https://example.com',
]);
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');
});
test('a custom site can store free-text api_instructions', function () {
$site = Site::create([
'name' => 'Custom Site',
'url' => 'https://custom.example.com',
'cms_type' => 'custom',
'api_instructions' => 'POST to /api/publish with a bearer token from .env',
]);
expect($site->fresh()->api_instructions)->toBe('POST to /api/publish with a bearer token from .env');
});
test('api_instructions defaults to null', function () {
$site = Site::create(['name' => 'My Blog', 'url' => 'https://example.com']);
expect($site->fresh()->api_instructions)->toBeNull();
});