]> BookStack Code Mirror - system-cli/blobdiff - tests/Commands/RestoreCommandTest.php
Added support for key restore files/folders being symlinks
[system-cli] / tests / Commands / RestoreCommandTest.php
index a8ff2b45a78e142f2d3843b30b859189bd8fc710..df70d16ae1f14000ef0fbf70cfc333d5e21d3aab 100644 (file)
@@ -29,11 +29,8 @@ class RestoreCommandTest extends TestCase
 
         $result = $this->runCommand('restore', [
             'backup-zip' => $zipFile,
-        ], [
-            'yes', '1'
-        ]);
+        ], ['yes', '1']);
 
-        $result->dumpError();
         $result->assertSuccessfulExit();
         $result->assertStdoutContains('✔ .env Config File');
         $result->assertStdoutContains('✔ Themes Folder');
@@ -98,6 +95,44 @@ class RestoreCommandTest extends TestCase
         $mysql->query("DROP TABLE zz_testing;");
     }
 
+    public function test_restore_with_symlinked_content_folders()
+    {
+        $zipFile = $this->buildZip(function (\ZipArchive $zip) {
+            $zip->addFromString('.env', "APP_KEY=abc123\nAPP_URL=https://example.com");
+            $zip->addFromString('public/uploads/test.txt', 'hello-public-uploads');
+            $zip->addFromString('storage/uploads/test.txt', 'hello-storage-uploads');
+            $zip->addFromString('themes/test.txt', 'hello-themes');
+        });
+
+        exec('cp -r /var/www/bookstack /var/www/bookstack-symlink-restore');
+        chdir('/var/www/bookstack-symlink-restore');
+        mkdir('/symlinks');
+
+        $symlinkPaths = ['public/uploads', 'storage/uploads', '.env', 'themes'];
+        foreach ($symlinkPaths as $path) {
+            $targetFile = str_replace('/', '-', $path);
+            $code = 0;
+            $output = null;
+            exec("mv /var/www/bookstack-symlink-restore/{$path} /symlinks/{$targetFile}", $output, $code);
+            exec("ln -s /symlinks/{$targetFile} /var/www/bookstack-symlink-restore/{$path}", $output, $code);
+            if ($code !== 0) {
+                $this->fail("Error when setting up symlinks");
+            }
+        }
+
+        $result = $this->runCommand('restore', [
+            'backup-zip' => $zipFile,
+        ], ['yes', '1']);
+
+        $result->assertSuccessfulExit();
+
+        $this->assertStringEqualsFile('/var/www/bookstack-symlink-restore/public/uploads/test.txt', 'hello-public-uploads');
+        $this->assertStringEqualsFile('/var/www/bookstack-symlink-restore/storage/uploads/test.txt', 'hello-storage-uploads');
+        $this->assertStringEqualsFile('/var/www/bookstack-symlink-restore/themes/test.txt', 'hello-themes');
+
+        exec('rm -rf /var/www/bookstack-symlink-restore');
+    }
+
     protected function buildZip(callable $builder): string
     {
         $zipFile = tempnam(sys_get_temp_dir(), 'cli-test');