mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-28 23:19:42 -08:00
Merge pull request #15852 from marcusmoore/testing/ui-delete-component
Some checks are pending
Crowdin Action / upload-sources-to-crowdin (push) Waiting to run
Docker images (Alpine) / docker (push) Waiting to run
Docker images / docker (push) Waiting to run
Tests in MySQL / PHP ${{ matrix.php-version }} (8.1) (push) Waiting to run
Tests in MySQL / PHP ${{ matrix.php-version }} (8.2) (push) Waiting to run
Tests in MySQL / PHP ${{ matrix.php-version }} (8.3) (push) Waiting to run
Tests in SQLite / PHP ${{ matrix.php-version }} (8.1.1) (push) Waiting to run
Some checks are pending
Crowdin Action / upload-sources-to-crowdin (push) Waiting to run
Docker images (Alpine) / docker (push) Waiting to run
Docker images / docker (push) Waiting to run
Tests in MySQL / PHP ${{ matrix.php-version }} (8.1) (push) Waiting to run
Tests in MySQL / PHP ${{ matrix.php-version }} (8.2) (push) Waiting to run
Tests in MySQL / PHP ${{ matrix.php-version }} (8.3) (push) Waiting to run
Tests in SQLite / PHP ${{ matrix.php-version }} (8.1.1) (push) Waiting to run
Added tests around deleting component via ui
This commit is contained in:
commit
cca76005a2
|
@ -193,7 +193,7 @@ class ComponentsController extends Controller
|
|||
$this->authorize('delete', $component);
|
||||
|
||||
// Remove the image if one exists
|
||||
if (Storage::disk('public')->exists('components/'.$component->image)) {
|
||||
if ($component->image && Storage::disk('public')->exists('components/' . $component->image)) {
|
||||
try {
|
||||
Storage::disk('public')->delete('components/'.$component->image);
|
||||
} catch (\Exception $e) {
|
||||
|
|
88
tests/Feature/Components/Ui/DeleteComponentTest.php
Normal file
88
tests/Feature/Components/Ui/DeleteComponentTest.php
Normal file
|
@ -0,0 +1,88 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\Components\Ui;
|
||||
|
||||
use App\Models\Company;
|
||||
use App\Models\Component;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Tests\Concerns\TestsFullMultipleCompaniesSupport;
|
||||
use Tests\Concerns\TestsPermissionsRequirement;
|
||||
use Tests\TestCase;
|
||||
|
||||
class DeleteComponentTest extends TestCase implements TestsFullMultipleCompaniesSupport, TestsPermissionsRequirement
|
||||
{
|
||||
public function testRequiresPermission()
|
||||
{
|
||||
$component = Component::factory()->create();
|
||||
|
||||
$this->actingAs(User::factory()->create())
|
||||
->delete(route('components.destroy', $component->id))
|
||||
->assertForbidden();
|
||||
}
|
||||
|
||||
public function testHandlesNonExistentComponent()
|
||||
{
|
||||
$this->actingAs(User::factory()->deleteComponents()->create())
|
||||
->delete(route('components.destroy', 10000))
|
||||
->assertSessionHas('error');
|
||||
}
|
||||
|
||||
public function testCanDeleteComponent()
|
||||
{
|
||||
$component = Component::factory()->create();
|
||||
|
||||
$this->actingAs(User::factory()->deleteComponents()->create())
|
||||
->delete(route('components.destroy', $component->id))
|
||||
->assertSessionHas('success')
|
||||
->assertRedirect(route('components.index'));
|
||||
|
||||
$this->assertSoftDeleted($component);
|
||||
}
|
||||
|
||||
public function testDeletingComponentRemovesComponentImage()
|
||||
{
|
||||
Storage::fake('public');
|
||||
|
||||
$component = Component::factory()->create(['image' => 'component-image.jpg']);
|
||||
|
||||
Storage::disk('public')->put('components/component-image.jpg', 'content');
|
||||
|
||||
Storage::disk('public')->assertExists('components/component-image.jpg');
|
||||
|
||||
$this->actingAs(User::factory()->deleteComponents()->create())->delete(route('components.destroy', $component->id));
|
||||
|
||||
Storage::disk('public')->assertMissing('components/component-image.jpg');
|
||||
}
|
||||
|
||||
public function testDeletingComponentIsLogged()
|
||||
{
|
||||
$user = User::factory()->deleteComponents()->create();
|
||||
$component = Component::factory()->create();
|
||||
|
||||
$this->actingAs($user)->delete(route('components.destroy', $component->id));
|
||||
|
||||
$this->assertDatabaseHas('action_logs', [
|
||||
'created_by' => $user->id,
|
||||
'action_type' => 'delete',
|
||||
'item_type' => Component::class,
|
||||
'item_id' => $component->id,
|
||||
]);
|
||||
}
|
||||
|
||||
public function testAdheresToFullMultipleCompaniesSupportScoping()
|
||||
{
|
||||
$this->settings->enableMultipleFullCompanySupport();
|
||||
|
||||
[$companyA, $companyB] = Company::factory()->count(2)->create();
|
||||
|
||||
$userInCompanyA = User::factory()->for($companyA)->create();
|
||||
$componentForCompanyB = Component::factory()->for($companyB)->create();
|
||||
|
||||
$this->actingAs($userInCompanyA)
|
||||
->delete(route('components.destroy', $componentForCompanyB->id))
|
||||
->assertSessionHas('error');
|
||||
|
||||
$this->assertNotSoftDeleted($componentForCompanyB);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue