Skip to content

Commit ee36851

Browse files
committed
- Changed reuse conversion test
1 parent 5ead0c3 commit ee36851

File tree

2 files changed

+88
-7
lines changed

2 files changed

+88
-7
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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+
}

tests/Unit/Concerns/InteractsWithAttachmentsTest.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -631,10 +631,7 @@ public function it_reuses_conversions_from_other_models(): void
631631
$this->assertEquals($this->getMediaDirectory($media->getKey() . '/conversions/test-test.jpg'), $path);
632632
$this->assertFileExists($path);
633633

634-
$dimensions = $this->getImageDimensions($path);
635-
$this->assertEquals(100, $dimensions['width']);
636-
$this->assertEquals(100, $dimensions['height']);
637-
634+
$file_hash = hash_file('sha256', $path);
638635

639636
$attachment_2 = $model_2->addAttachment($media)
640637
->toAttachmentCollection();
@@ -644,8 +641,7 @@ public function it_reuses_conversions_from_other_models(): void
644641
$this->assertEquals($this->getMediaDirectory($media->getKey() . '/conversions/test-test.jpg'), $path_2);
645642
$this->assertFileExists($path_2);
646643

647-
$dimensions_2 = $this->getImageDimensions($path_2);
648-
$this->assertEquals(100, $dimensions_2['width']);
649-
$this->assertEquals(100, $dimensions_2['height']);
644+
$file_hash_2 = hash_file('sha256', $path_2);
645+
$this->assertEquals($file_hash, $file_hash_2);
650646
}
651647
}

0 commit comments

Comments
 (0)