|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Javaabu\Mediapicker\Tests\Feature\Commands; |
| 4 | + |
| 5 | +use Illuminate\Foundation\Testing\RefreshDatabase; |
| 6 | +use Javaabu\Mediapicker\Tests\TestCase; |
| 7 | +use PHPUnit\Framework\Attributes\Test; |
| 8 | + |
| 9 | +class AttachmentsCleanCommandTest extends TestCase |
| 10 | +{ |
| 11 | + use RefreshDatabase; |
| 12 | + |
| 13 | + #[Test] |
| 14 | + public function it_can_clean_all_attachments(): void |
| 15 | + { |
| 16 | + $attachment = $this->getAttachment(); |
| 17 | + |
| 18 | + $this->assertDatabaseHas('attachments', [ |
| 19 | + 'id' => $attachment->id, |
| 20 | + ]); |
| 21 | + |
| 22 | + $this->artisan('mediapicker:clear') |
| 23 | + ->assertSuccessful(); |
| 24 | + |
| 25 | + $this->assertDatabaseEmpty('attachments'); |
| 26 | + } |
| 27 | + |
| 28 | + /*#[Test] |
| 29 | + public function it_can_clear_attachments_of_a_specific_model_type(): void |
| 30 | + { |
| 31 | + $post = $this->getModel(); |
| 32 | + $attachment = $this->getAttachment($post); |
| 33 | +
|
| 34 | + $other_model = $this->getModelWithConversions(); |
| 35 | + $attachment_2 = $this->getAttachment($other_model); |
| 36 | +
|
| 37 | + $this->assertDatabaseHas('attachments', [ |
| 38 | + 'id' => $attachment->id, |
| 39 | + ]); |
| 40 | +
|
| 41 | + $this->assertDatabaseHas('attachments', [ |
| 42 | + 'id' => $attachment_2->id, |
| 43 | + ]); |
| 44 | +
|
| 45 | + $this->artisan('mediapicker:clear', ['modelType' => 'post']) |
| 46 | + ->assertSuccessful(); |
| 47 | +
|
| 48 | + $this->assertDatabaseMissing('attachments', [ |
| 49 | + 'id' => $attachment->id, |
| 50 | + ]); |
| 51 | +
|
| 52 | + $this->assertDatabaseHas('attachments', [ |
| 53 | + 'id' => $attachment_2->id, |
| 54 | + ]); |
| 55 | + } |
| 56 | +
|
| 57 | + #[Test] |
| 58 | + public function it_can_clear_attachments_of_a_specific_collection(): void |
| 59 | + { |
| 60 | + $post = $this->getModel(); |
| 61 | + $attachment = $this->getAttachment($post, 'test1'); |
| 62 | +
|
| 63 | + $other_model = $this->getModelWithConversions(); |
| 64 | + $attachment_2 = $this->getAttachment($other_model, 'test'); |
| 65 | +
|
| 66 | + $this->assertDatabaseHas('attachments', [ |
| 67 | + 'id' => $attachment->id, |
| 68 | + ]); |
| 69 | +
|
| 70 | + $this->assertDatabaseHas('attachments', [ |
| 71 | + 'id' => $attachment_2->id, |
| 72 | + ]); |
| 73 | +
|
| 74 | + $this->artisan('mediapicker:clear', ['collectionName' => 'test1']) |
| 75 | + ->assertSuccessful(); |
| 76 | +
|
| 77 | + $this->assertDatabaseMissing('attachments', [ |
| 78 | + 'id' => $attachment->id, |
| 79 | + ]); |
| 80 | +
|
| 81 | + $this->assertDatabaseHas('attachments', [ |
| 82 | + 'id' => $attachment_2->id, |
| 83 | + ]); |
| 84 | + }*/ |
| 85 | +} |
0 commit comments