1 <?php declare(strict_types=1);
3 namespace Tests\Commands;
7 class DownloadVendorCommandTest extends TestCase
9 public function test_command_downloads_vendor_folder()
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');
19 $this->assertDirectoryDoesNotExist("$basePath/vendor");
21 $result = $this->runCommand('download-vendor');
23 $result->assertSuccessfulExit();
24 $result->assertStdoutContains('Downloading ZIP from files.bookstackapp.com...');
25 $result->assertStdoutContains('Successfully downloaded & extracted vendor files into BookStack instance!');
27 $this->assertDirectoryExists("$basePath/vendor/composer");
28 $this->assertFileDoesNotExist("$basePath/bootstrap/cache/packages.php");
29 $this->assertFileDoesNotExist("$basePath/bootstrap/cache/services.php");
33 public function test_app_directory_option()
35 $this->withOwnBookStackFolder(function (string $basePath) {
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');
43 $this->assertDirectoryDoesNotExist("$basePath/vendor");
45 $result = $this->runCommand('download-vendor', ['--app-directory' => $basePath]);
47 $result->assertSuccessfulExit();
48 $this->assertDirectoryExists("$basePath/vendor/composer");
50 $result = $this->runCommand('download-vendor', ['--app-directory' => '/var/beans']);
51 $result->assertErrorExit();
52 $result->assertStderrContains('Could not find a valid BookStack installation');
56 public function test_command_fails_on_checksum_mismatch()
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');
63 $result = $this->runCommand('download-vendor');
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.');
69 $this->assertDirectoryExists("$basePath/vendor/composer");
73 public function test_command_fails_on_zip_not_found()
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');
80 $result = $this->runCommand('download-vendor');
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');
86 $this->assertDirectoryExists("$basePath/vendor/composer");