]> BookStack Code Mirror - system-cli/blob - tests/Commands/DownloadVendorCommandTest.php
Bumped version
[system-cli] / tests / Commands / DownloadVendorCommandTest.php
1 <?php declare(strict_types=1);
2
3 namespace Tests\Commands;
4
5 use Tests\TestCase;
6
7 class DownloadVendorCommandTest extends TestCase
8 {
9     public function test_command_downloads_vendor_folder()
10     {
11         $this->withOwnBookStackFolder(function (string $basePath) {
12             exec("rm -rf $basePath/vendor");
13             file_put_contents("$basePath/version", 'v25.02');
14             file_put_contents("$basePath/bootstrap/cache/packages.php", 'cat');
15             file_put_contents("$basePath/bootstrap/cache/services.php", 'dog');
16             @mkdir("$basePath/dev/checksums", 0777, true);
17             file_put_contents("$basePath/dev/checksums/vendor", '22e02ee72d21ff719c1073abbec8302f8e2096ba6d072e133051064ed24b45b1');
18
19             $this->assertDirectoryDoesNotExist("$basePath/vendor");
20
21             $result = $this->runCommand('download-vendor');
22
23             $result->assertSuccessfulExit();
24             $result->assertStdoutContains('Downloading ZIP from files.bookstackapp.com...');
25             $result->assertStdoutContains('Successfully downloaded & extracted vendor files into BookStack instance!');
26
27             $this->assertDirectoryExists("$basePath/vendor/composer");
28             $this->assertFileDoesNotExist("$basePath/bootstrap/cache/packages.php");
29             $this->assertFileDoesNotExist("$basePath/bootstrap/cache/services.php");
30         });
31     }
32
33     public function test_app_directory_option()
34     {
35         $this->withOwnBookStackFolder(function (string $basePath) {
36             chdir('/var');
37
38             exec("rm -rf $basePath/vendor");
39             file_put_contents("$basePath/version", 'v25.02');
40             @mkdir("$basePath/dev/checksums", 0777, true);
41             file_put_contents("$basePath/dev/checksums/vendor", '22e02ee72d21ff719c1073abbec8302f8e2096ba6d072e133051064ed24b45b1');
42
43             $this->assertDirectoryDoesNotExist("$basePath/vendor");
44
45             $result = $this->runCommand('download-vendor', ['--app-directory' => $basePath]);
46
47             $result->assertSuccessfulExit();
48             $this->assertDirectoryExists("$basePath/vendor/composer");
49
50             $result = $this->runCommand('download-vendor', ['--app-directory' => '/var/beans']);
51             $result->assertErrorExit();
52             $result->assertStderrContains('Could not find a valid BookStack installation');
53         });
54     }
55
56     public function test_command_fails_on_checksum_mismatch()
57     {
58         $this->withOwnBookStackFolder(function (string $basePath) {
59             file_put_contents("$basePath/version", 'v25.02');
60             @mkdir("$basePath/dev/checksums", 0777, true);
61             file_put_contents("$basePath/dev/checksums/vendor", '42e02ee72d21ff719c1073abbec8302f8e2096ba6d072e133051064ed24b45b1');
62
63             $result = $this->runCommand('download-vendor');
64
65             $result->assertErrorExit();
66             $result->assertStdoutContains('Downloading ZIP from files.bookstackapp.com...');
67             $result->assertStderrContains('Checksum of downloaded ZIP does not match the expected checksum.');
68
69             $this->assertDirectoryExists("$basePath/vendor/composer");
70         });
71     }
72
73     public function test_command_fails_on_zip_not_found()
74     {
75         $this->withOwnBookStackFolder(function (string $basePath) {
76             file_put_contents("$basePath/version", 'v10.02');
77             @mkdir("$basePath/dev/checksums", 0777, true);
78             file_put_contents("$basePath/dev/checksums/vendor", 'abc');
79
80             $result = $this->runCommand('download-vendor');
81
82             $result->assertErrorExit();
83             $result->assertStdoutContains('Downloading ZIP from files.bookstackapp.com...');
84             $result->assertStderrContains('Failed to download ZIP file from https://files.bookstackapp.com/vendor/v10.02.zip');
85
86             $this->assertDirectoryExists("$basePath/vendor/composer");
87         });
88     }
89 }