]> BookStack Code Mirror - system-cli/blobdiff - tests/Commands/DownloadVendorCommandTest.php
DownloadVendorCommand: Added check for ZIP file access
[system-cli] / tests / Commands / DownloadVendorCommandTest.php
index 855750f018b108003e4e0b28a1d9a024a803ca35..20a2fb829b7e4b73b4f012757f264b815a8ccb05 100644 (file)
@@ -1,6 +1,6 @@
-<?php
+<?php declare(strict_types=1);
 
-namespace Commands;
+namespace Tests\Commands;
 
 use Tests\TestCase;
 
@@ -11,7 +11,7 @@ class DownloadVendorCommandTest extends TestCase
         $this->withOwnBookStackFolder(function (string $basePath) {
             exec("rm -rf $basePath/vendor");
             file_put_contents("$basePath/version", 'v25.02');
-            mkdir("$basePath/dev/checksums", '0777', true);
+            mkdir("$basePath/dev/checksums", 0777, true);
             file_put_contents("$basePath/dev/checksums/vendor", '22e02ee72d21ff719c1073abbec8302f8e2096ba6d072e133051064ed24b45b1');
 
             $this->assertDirectoryDoesNotExist("$basePath/vendor");
@@ -33,7 +33,7 @@ class DownloadVendorCommandTest extends TestCase
 
             exec("rm -rf $basePath/vendor");
             file_put_contents("$basePath/version", 'v25.02');
-            mkdir("$basePath/dev/checksums", '0777', true);
+            mkdir("$basePath/dev/checksums", 0777, true);
             file_put_contents("$basePath/dev/checksums/vendor", '22e02ee72d21ff719c1073abbec8302f8e2096ba6d072e133051064ed24b45b1');
 
             $this->assertDirectoryDoesNotExist("$basePath/vendor");
@@ -53,7 +53,7 @@ class DownloadVendorCommandTest extends TestCase
     {
         $this->withOwnBookStackFolder(function (string $basePath) {
             file_put_contents("$basePath/version", 'v25.02');
-            mkdir("$basePath/dev/checksums", '0777', true);
+            mkdir("$basePath/dev/checksums", 0777, true);
             file_put_contents("$basePath/dev/checksums/vendor", '42e02ee72d21ff719c1073abbec8302f8e2096ba6d072e133051064ed24b45b1');
 
             $result = $this->runCommand('download-vendor');
@@ -66,4 +66,20 @@ class DownloadVendorCommandTest extends TestCase
         });
     }
 
+    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");
+        });
+    }
 }
\ No newline at end of file