]> BookStack Code Mirror - bookstack/blob - tests/Commands/CleanupImagesCommandTest.php
Merge pull request #4972 from johnroyer/fix-typo-in-language-file
[bookstack] / tests / Commands / CleanupImagesCommandTest.php
1 <?php
2
3 namespace Tests\Commands;
4
5 use BookStack\Uploads\Image;
6 use Tests\TestCase;
7
8 class CleanupImagesCommandTest extends TestCase
9 {
10     public function test_command_defaults_to_dry_run()
11     {
12         $page = $this->entities->page();
13         $image = Image::factory()->create(['uploaded_to' => $page->id]);
14
15         $this->artisan('bookstack:cleanup-images -v')
16             ->expectsOutput('Dry run, no images have been deleted')
17             ->expectsOutput('1 image(s) found that would have been deleted')
18             ->expectsOutputToContain($image->path)
19             ->assertExitCode(0);
20
21         $this->assertDatabaseHas('images', ['id' => $image->id]);
22     }
23
24     public function test_command_force_run()
25     {
26         $page = $this->entities->page();
27         $image = Image::factory()->create(['uploaded_to' => $page->id]);
28
29         $this->artisan('bookstack:cleanup-images --force')
30             ->expectsOutputToContain('This operation is destructive and is not guaranteed to be fully accurate')
31             ->expectsConfirmation('Are you sure you want to proceed?', 'yes')
32             ->expectsOutput('1 image(s) deleted')
33             ->assertExitCode(0);
34
35         $this->assertDatabaseMissing('images', ['id' => $image->id]);
36     }
37
38     public function test_command_force_run_negative_confirmation()
39     {
40         $page = $this->entities->page();
41         $image = Image::factory()->create(['uploaded_to' => $page->id]);
42
43         $this->artisan('bookstack:cleanup-images --force')
44             ->expectsConfirmation('Are you sure you want to proceed?', 'no')
45             ->assertExitCode(0);
46
47         $this->assertDatabaseHas('images', ['id' => $image->id]);
48     }
49
50     public function test_command_force_no_interaction_run()
51     {
52         $page = $this->entities->page();
53         $image = Image::factory()->create(['uploaded_to' => $page->id]);
54
55         $this->artisan('bookstack:cleanup-images --force --no-interaction')
56             ->expectsOutputToContain('This operation is destructive and is not guaranteed to be fully accurate')
57             ->expectsOutput('1 image(s) deleted')
58             ->assertExitCode(0);
59
60         $this->assertDatabaseMissing('images', ['id' => $image->id]);
61     }
62 }