seed(RolePermissionSeeder::class); Queue::fake(); } #[Test] public function a_published_page_is_copied_as_a_draft_with_a_free_slug(): void { $this->actingAs($editor = $this->userWithRoles('editor')); $page = Page::factory()->published()->create([ 'title' => ['es' => 'Hola', 'en' => 'Hello'], 'slug' => ['es' => 'hola', 'en' => 'hello'], ]); Page::factory()->draft()->create(['slug' => ['es' => 'hola-copia']]); Livewire::test(EditPage::class, ['record' => $page->getRouteKey()]) ->callAction('duplicate') ->assertHasNoActionErrors(); $copy = Page::query()->latest('id')->first(); $this->assertSame(PageStatus::Draft, $copy->status); $this->assertNull($copy->published_at); $this->assertSame('Hola (copia)', $copy->getTranslation('title', 'es')); $this->assertSame('Hello (copy)', $copy->getTranslation('title', 'en')); $this->assertSame('hola-copia-2', $copy->getTranslation('slug', 'es')); $this->assertSame($editor->id, $copy->author_id); $this->assertSame($page->body, $copy->body); } #[Test] public function a_project_keeps_its_stack_and_team(): void { $this->actingAs($this->userWithRoles('editor')); $project = Project::factory()->published()->create(); $project->technologies()->attach(Technology::factory()->create()); $project->members()->attach(Member::factory()->create(), ['role' => 'Responsable']); Livewire::test(ListProjects::class)->callTableAction('duplicate', $project); $copy = Project::query()->latest('id')->first(); $this->assertNotSame($project->id, $copy->id); $this->assertNull($copy->published_at); $this->assertCount(1, $copy->technologies); $this->assertSame('Responsable', $copy->members()->first()->pivot->role); } #[Test] public function the_api_duplicates_too_and_only_for_who_may_create(): void { $page = Page::factory()->create(); $this->withHeaders($this->apiHeadersFor($this->userWithRoles('viewer'))); $this->postJson("/api/v1/pages/{$page->id}/duplicate")->assertForbidden(); $this->withHeaders($this->apiHeadersFor($this->userWithRoles('editor'))); $this->postJson("/api/v1/pages/{$page->id}/duplicate") ->assertCreated() ->assertJsonPath('data.type', 'pages'); $this->assertSame(2, Page::query()->count()); } }