First commit
This commit is contained in:
commit
7cf3558ba7
12933 changed files with 1180047 additions and 0 deletions
165
packages/flux-cms/core/tests/Unit/ComponentRegistryTest.php
Normal file
165
packages/flux-cms/core/tests/Unit/ComponentRegistryTest.php
Normal file
|
|
@ -0,0 +1,165 @@
|
|||
<?php
|
||||
|
||||
namespace FluxCms\Core\Tests\Unit;
|
||||
|
||||
use FluxCms\Core\Services\ComponentRegistry;
|
||||
use FluxCms\Core\FieldTypes\TextField;
|
||||
use FluxCms\Core\FieldTypes\MediaField;
|
||||
use Orchestra\Testbench\TestCase;
|
||||
use Livewire\Component;
|
||||
use Mockery;
|
||||
|
||||
class ComponentRegistryTest extends TestCase
|
||||
{
|
||||
protected ComponentRegistry $registry;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->registry = new ComponentRegistry();
|
||||
}
|
||||
|
||||
public function test_can_detect_valid_component()
|
||||
{
|
||||
$componentClass = TestComponent::class;
|
||||
|
||||
$this->assertTrue($this->registry->isValidComponent($componentClass));
|
||||
}
|
||||
|
||||
public function test_can_get_component_config()
|
||||
{
|
||||
$componentClass = TestComponent::class;
|
||||
|
||||
$config = $this->registry->getComponentConfig($componentClass);
|
||||
|
||||
$this->assertIsArray($config);
|
||||
$this->assertEquals('Test Component', $config['name']);
|
||||
$this->assertEquals('Testing', $config['category']);
|
||||
$this->assertCount(2, $config['fields']);
|
||||
}
|
||||
|
||||
public function test_can_validate_component_content()
|
||||
{
|
||||
$componentClass = TestComponent::class;
|
||||
|
||||
// Valid content
|
||||
$validContent = [
|
||||
'title' => ['de' => 'Test Titel', 'en' => 'Test Title'],
|
||||
'image' => 123
|
||||
];
|
||||
|
||||
$errors = $this->registry->validateComponentContent($componentClass, $validContent);
|
||||
$this->assertEmpty($errors);
|
||||
|
||||
// Invalid content (missing required field)
|
||||
$invalidContent = [
|
||||
'image' => 123
|
||||
];
|
||||
|
||||
$errors = $this->registry->validateComponentContent($componentClass, $invalidContent);
|
||||
$this->assertNotEmpty($errors);
|
||||
}
|
||||
|
||||
public function test_can_search_components()
|
||||
{
|
||||
// Mock some components in registry
|
||||
$components = [
|
||||
TestComponent::class => [
|
||||
'name' => 'Test Component',
|
||||
'category' => 'Testing',
|
||||
'description' => 'A test component',
|
||||
'tags' => ['test', 'example']
|
||||
]
|
||||
];
|
||||
|
||||
$registry = Mockery::mock(ComponentRegistry::class)->makePartial();
|
||||
$registry->shouldReceive('getAvailableComponents')->andReturn($components);
|
||||
|
||||
$results = $registry->searchComponents('test');
|
||||
|
||||
$this->assertCount(1, $results);
|
||||
$this->assertArrayHasKey(TestComponent::class, $results);
|
||||
}
|
||||
|
||||
public function test_can_get_components_by_category()
|
||||
{
|
||||
$components = [
|
||||
TestComponent::class => [
|
||||
'name' => 'Test Component',
|
||||
'category' => 'Testing',
|
||||
],
|
||||
AnotherTestComponent::class => [
|
||||
'name' => 'Another Component',
|
||||
'category' => 'Layout',
|
||||
]
|
||||
];
|
||||
|
||||
$registry = Mockery::mock(ComponentRegistry::class)->makePartial();
|
||||
$registry->shouldReceive('getAvailableComponents')->andReturn($components);
|
||||
|
||||
$categorized = $registry->getComponentsByCategory();
|
||||
|
||||
$this->assertArrayHasKey('Testing', $categorized);
|
||||
$this->assertArrayHasKey('Layout', $categorized);
|
||||
$this->assertCount(1, $categorized['Testing']);
|
||||
$this->assertCount(1, $categorized['Layout']);
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
Mockery::close();
|
||||
parent::tearDown();
|
||||
}
|
||||
}
|
||||
|
||||
// Test component classes
|
||||
class TestComponent extends Component
|
||||
{
|
||||
public static function getCmsName(): string
|
||||
{
|
||||
return 'Test Component';
|
||||
}
|
||||
|
||||
public static function getCmsCategory(): string
|
||||
{
|
||||
return 'Testing';
|
||||
}
|
||||
|
||||
public static function getCmsFields(): array
|
||||
{
|
||||
return [
|
||||
TextField::make('title', 'Title')->translatable()->required(),
|
||||
MediaField::make('image', 'Image')->images(),
|
||||
];
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return '<div>Test Component</div>';
|
||||
}
|
||||
}
|
||||
|
||||
class AnotherTestComponent extends Component
|
||||
{
|
||||
public static function getCmsName(): string
|
||||
{
|
||||
return 'Another Component';
|
||||
}
|
||||
|
||||
public static function getCmsCategory(): string
|
||||
{
|
||||
return 'Layout';
|
||||
}
|
||||
|
||||
public static function getCmsFields(): array
|
||||
{
|
||||
return [
|
||||
TextField::make('content', 'Content'),
|
||||
];
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return '<div>Another Component</div>';
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue