--- /dev/null
+<?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
return new CommandResult($commandTester, $err);
}
+
+ /**
+ * Create a clone of a BookStack install folder, then pass that path
+ * and run the given callback.
+ * Destroys the folder afterwards.
+ */
+ protected function withOwnBookStackFolder(callable $callback)
+ {
+ $path = '/var/www/bookstack-' . md5(random_bytes(5));
+ exec("cp -r /var/www/bookstack $path");
+ chdir($path);
+ $callback($path);
+ exec("rm -rf $path");
+ }
}
\ No newline at end of file