+<?php
+
+namespace Commands;
+
+use Tests\TestCase;
+
+class DownloadVendorCommandTest extends TestCase
+{
+ public function test_command_downloads_vendor_folder()
+ {
+ $this->withOwnBookStackFolder(function (string $basePath) {
+ exec("rm -rf $basePath/vendor");
+ file_put_contents("$basePath/version", 'v25.02');
+ mkdir("$basePath/dev/checksums", '0777', true);
+ file_put_contents("$basePath/dev/checksums/vendor", '22e02ee72d21ff719c1073abbec8302f8e2096ba6d072e133051064ed24b45b1');
+
+ $this->assertDirectoryDoesNotExist("$basePath/vendor");
+
+ $result = $this->runCommand('download-vendor');
+
+ $result->assertSuccessfulExit();
+ $result->assertStdoutContains('Downloading ZIP from files.bookstackapp.com...');
+ $result->assertStdoutContains('Successfully downloaded & extracted vendor files into BookStack instance!');
+
+ $this->assertDirectoryExists("$basePath/vendor/composer");
+ });
+ }
+
+ public function test_app_directory_option()
+ {
+ $this->withOwnBookStackFolder(function (string $basePath) {
+ chdir('/var');
+
+ exec("rm -rf $basePath/vendor");
+ file_put_contents("$basePath/version", 'v25.02');
+ mkdir("$basePath/dev/checksums", '0777', true);
+ file_put_contents("$basePath/dev/checksums/vendor", '22e02ee72d21ff719c1073abbec8302f8e2096ba6d072e133051064ed24b45b1');
+
+ $this->assertDirectoryDoesNotExist("$basePath/vendor");
+
+ $result = $this->runCommand('download-vendor', ['--app-directory' => $basePath]);
+
+ $result->assertSuccessfulExit();
+ $this->assertDirectoryExists("$basePath/vendor/composer");
+
+ $result = $this->runCommand('download-vendor', ['--app-directory' => '/var/beans']);
+ $result->assertErrorExit();
+ $result->assertStderrContains('Could not find a valid BookStack installation');
+ });
+ }
+
+ public function test_command_fails_on_checksum_mismatch()
+ {
+ $this->withOwnBookStackFolder(function (string $basePath) {
+ file_put_contents("$basePath/version", 'v25.02');
+ mkdir("$basePath/dev/checksums", '0777', true);
+ file_put_contents("$basePath/dev/checksums/vendor", '42e02ee72d21ff719c1073abbec8302f8e2096ba6d072e133051064ed24b45b1');
+
+ $result = $this->runCommand('download-vendor');
+
+ $result->assertErrorExit();
+ $result->assertStdoutContains('Downloading ZIP from files.bookstackapp.com...');
+ $result->assertStderrContains('Checksum of downloaded ZIP does not match the expected checksum.');
+
+ $this->assertDirectoryExists("$basePath/vendor/composer");
+ });
+ }
+
+}
\ No newline at end of file