diff --git a/app/Http/Controllers/Reports/CustomComponentReportController.php b/app/Http/Controllers/Reports/CustomComponentReportController.php index f2f4bddc1f..b60f215705 100644 --- a/app/Http/Controllers/Reports/CustomComponentReportController.php +++ b/app/Http/Controllers/Reports/CustomComponentReportController.php @@ -101,6 +101,14 @@ class CustomComponentReportController extends Controller 'last_updated' => 'updated_at', ]); + if ($request->input('deleted_components') === 'include_deleted') { + $query->withTrashed(); + } + + if ($request->input('deleted_components') === 'only_deleted') { + $query->onlyTrashed(); + } + $query->orderBy('components.id', 'ASC')->chunk(500, function ($components) use ($handle, $request) { Log::debug('Walking results: '.$this->getExecutionTime()); diff --git a/tests/Feature/Reporting/Custom/CustomComponentReportTest.php b/tests/Feature/Reporting/Custom/CustomComponentReportTest.php index bee65bf738..e7cea7eb49 100644 --- a/tests/Feature/Reporting/Custom/CustomComponentReportTest.php +++ b/tests/Feature/Reporting/Custom/CustomComponentReportTest.php @@ -472,24 +472,49 @@ class CustomComponentReportTest extends TestCase ->assertDontSeeTextInStreamedResponse('Component B'); } - public function test_limiting_by_excluding_deleted_components() + public function test_excluding_deleted_components() { - $this->markTestIncomplete(); + Component::factory()->create(['name' => 'Deleted Component', 'deleted_at' => now()]); + Component::factory()->create(['name' => 'Active Component']); + + $this->sendRequest([ + 'component_name' => '1', + 'deleted_components' => 'exclude_deleted', + ]) + ->assertOk() + ->assertCsvHeader() + ->assertSeeTextInStreamedResponse('Active Component') + ->assertDontSeeTextInStreamedResponse('Deleted Component'); } - public function test_limiting_by_including_deleted_components() + public function test_including_deleted_components() { - $this->markTestIncomplete(); + Component::factory()->create(['name' => 'Deleted Component', 'deleted_at' => now()]); + Component::factory()->create(['name' => 'Active Component']); + + $this->sendRequest([ + 'component_name' => '1', + 'deleted_components' => 'include_deleted', + ]) + ->assertOk() + ->assertCsvHeader() + ->assertSeeTextInStreamedResponse('Active Component') + ->assertSeeTextInStreamedResponse('Deleted Component'); } - public function test_limiting_by_only_deleted_components() + public function test_including_only_deleted_components() { - $this->markTestIncomplete(); - } + Component::factory()->create(['name' => 'Deleted Component', 'deleted_at' => now()]); + Component::factory()->create(['name' => 'Active Component']); - public function test_custom_component_report_exclude_deleted() - { - $this->markTestIncomplete(); + $this->sendRequest([ + 'component_name' => '1', + 'deleted_components' => 'only_deleted', + ]) + ->assertOk() + ->assertCsvHeader() + ->assertDontSeeTextInStreamedResponse('Active Component') + ->assertSeeTextInStreamedResponse('Deleted Component'); } public function test_custom_component_report_adheres_to_company_scoping()