withOwnBookStackFolder(function (string $basePath) { exec("rm -rf $basePath/vendor"); file_put_contents("$basePath/version", 'v25.02'); file_put_contents("$basePath/bootstrap/cache/packages.php", 'cat'); file_put_contents("$basePath/bootstrap/cache/services.php", 'dog'); @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"); $this->assertFileDoesNotExist("$basePath/bootstrap/cache/packages.php"); $this->assertFileDoesNotExist("$basePath/bootstrap/cache/services.php"); }); } 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"); }); } public function test_command_fails_on_zip_not_found() { $this->withOwnBookStackFolder(function (string $basePath) { file_put_contents("$basePath/version", 'v10.02'); @mkdir("$basePath/dev/checksums", 0777, true); file_put_contents("$basePath/dev/checksums/vendor", 'abc'); $result = $this->runCommand('download-vendor'); $result->assertErrorExit(); $result->assertStdoutContains('Downloading ZIP from files.bookstackapp.com...'); $result->assertStderrContains('Failed to download ZIP file from https://files.bookstackapp.com/vendor/v10.02.zip'); $this->assertDirectoryExists("$basePath/vendor/composer"); }); } }