First commit
This commit is contained in:
commit
7cf3558ba7
12933 changed files with 1180047 additions and 0 deletions
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace FluxCms\Core\Tests\Unit\Admin;
|
||||
|
||||
use FluxCms\Core\Models\User;
|
||||
use FluxCms\Core\Models\BlogPost;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Orchestra\Testbench\TestCase;
|
||||
|
||||
class BlogControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
protected User $adminUser;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->adminUser = User::factory()->create(['is_admin' => true]);
|
||||
$this->actingAs($this->adminUser);
|
||||
}
|
||||
|
||||
public function test_can_display_blog_posts_index()
|
||||
{
|
||||
BlogPost::factory()->count(3)->create();
|
||||
$response = $this->get(route('admin.cms.blog.index'));
|
||||
$response->assertOk();
|
||||
$response->assertViewHas('posts');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
namespace FluxCms\Core\Tests\Unit\Admin;
|
||||
|
||||
use FluxCms\Core\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Orchestra\Testbench\TestCase;
|
||||
|
||||
class DashboardControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
protected User $adminUser;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->adminUser = User::factory()->create(['is_admin' => true]);
|
||||
$this->actingAs($this->adminUser);
|
||||
}
|
||||
|
||||
public function test_admin_can_see_dashboard()
|
||||
{
|
||||
$response = $this->get(route('admin.cms.index'));
|
||||
$response->assertOk();
|
||||
$response->assertViewHas('stats');
|
||||
$response->assertViewHas('recentPages');
|
||||
}
|
||||
}
|
||||
123
packages/flux-cms/core/tests/Unit/Admin/PageControllerTest.php
Normal file
123
packages/flux-cms/core/tests/Unit/Admin/PageControllerTest.php
Normal file
|
|
@ -0,0 +1,123 @@
|
|||
<?php
|
||||
|
||||
namespace FluxCms\Core\Tests\Unit\Admin;
|
||||
|
||||
use FluxCms\Core\Models\User;
|
||||
use FluxCms\Core\Models\Page;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Orchestra\Testbench\TestCase;
|
||||
|
||||
class PageControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
protected User $adminUser;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->adminUser = User::factory()->create(['is_admin' => true]);
|
||||
$this->actingAs($this->adminUser);
|
||||
}
|
||||
|
||||
public function test_can_display_pages_index()
|
||||
{
|
||||
Page::factory()->count(3)->create();
|
||||
$response = $this->get(route('admin.cms.pages.index'));
|
||||
$response->assertOk();
|
||||
$response->assertViewHas('pages');
|
||||
}
|
||||
|
||||
public function test_can_show_create_page_form()
|
||||
{
|
||||
$response = $this->get(route('admin.cms.pages.create'));
|
||||
$response->assertOk();
|
||||
}
|
||||
|
||||
public function test_can_store_a_new_page()
|
||||
{
|
||||
$pageData = [
|
||||
'domain_key' => 'default',
|
||||
'title' => ['en' => 'New Page'],
|
||||
'slugs' => ['en' => '/new-page'],
|
||||
'is_published' => true,
|
||||
];
|
||||
|
||||
$response = $this->post(route('admin.cms.pages.store'), $pageData);
|
||||
|
||||
$this->assertDatabaseHas('flux_cms_pages', ['title' => '{"en":"New Page"}']);
|
||||
$this->assertDatabaseHas('flux_cms_slugs', ['slug' => '/new-page']);
|
||||
$response->assertRedirect();
|
||||
}
|
||||
|
||||
public function test_store_fails_with_invalid_data()
|
||||
{
|
||||
$response = $this->post(route('admin.cms.pages.store'), [
|
||||
'title' => ['en' => ''], // Invalid: title is required
|
||||
]);
|
||||
|
||||
$response->assertSessionHasErrors('title.en');
|
||||
$response->assertStatus(302); // Should redirect back
|
||||
}
|
||||
|
||||
public function test_unauthorized_user_cannot_create_page()
|
||||
{
|
||||
$user = User::factory()->create(); // Non-admin user
|
||||
$this->actingAs($user);
|
||||
|
||||
$response = $this->get(route('admin.cms.pages.create'));
|
||||
$response->assertStatus(403);
|
||||
|
||||
$response = $this->post(route('admin.cms.pages.store'), []);
|
||||
$response->assertStatus(403);
|
||||
}
|
||||
|
||||
public function test_can_show_edit_page_form()
|
||||
{
|
||||
$page = Page::factory()->create();
|
||||
$response = $this->get(route('admin.cms.pages.edit', $page));
|
||||
$response->assertOk();
|
||||
$response->assertViewHas('page', $page);
|
||||
}
|
||||
|
||||
public function test_can_update_a_page()
|
||||
{
|
||||
$page = Page::factory()->create();
|
||||
$page->slugs()->create(['locale' => 'en', 'slug' => '/old-slug']);
|
||||
|
||||
$updateData = [
|
||||
'title' => ['en' => 'Updated Title'],
|
||||
'slugs' => ['en' => '/updated-slug'],
|
||||
];
|
||||
|
||||
$response = $this->put(route('admin.cms.pages.update', $page), $updateData);
|
||||
|
||||
$this->assertDatabaseHas('flux_cms_pages', ['id' => $page->id, 'title' => '{"en":"Updated Title"}']);
|
||||
$this->assertDatabaseHas('flux_cms_slugs', ['slug' => '/updated-slug']);
|
||||
$response->assertRedirect();
|
||||
}
|
||||
|
||||
public function test_unauthorized_user_cannot_edit_or_delete_page()
|
||||
{
|
||||
$user = User::factory()->create(); // Non-admin user
|
||||
$page = Page::factory()->create();
|
||||
$this->actingAs($user);
|
||||
|
||||
$response = $this->get(route('admin.cms.pages.edit', $page));
|
||||
$response->assertStatus(403);
|
||||
|
||||
$response = $this->put(route('admin.cms.pages.update', $page), []);
|
||||
$response->assertStatus(403);
|
||||
|
||||
$response = $this->delete(route('admin.cms.pages.destroy', $page));
|
||||
$response->assertStatus(403);
|
||||
}
|
||||
|
||||
public function test_can_delete_a_page()
|
||||
{
|
||||
$page = Page::factory()->create();
|
||||
$response = $this->delete(route('admin.cms.pages.destroy', $page));
|
||||
$this->assertModelMissing($page);
|
||||
$response->assertRedirect(route('admin.cms.pages.index'));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue