1 <?php declare(strict_types=1);
3 namespace Tests\Commands;
7 class RestoreCommandTest extends TestCase
10 public function test_restore_into_cwd_by_default_with_all_content_types()
12 $mysql = new \mysqli('db', 'bookstack', 'bookstack', 'bookstack');
13 $mysql->query('CREATE TABLE xx_testing (labels varchar(255));');
15 $result = $mysql->query('SHOW TABLES LIKE \'zz_testing\';');
16 $this->assertEquals(0, mysqli_num_rows($result));
18 $zipFile = $this->buildZip(function (\ZipArchive $zip) {
19 $zip->addFromString('.env', "APP_KEY=abc123\nAPP_URL=https://example.com");
20 $zip->addFromString('public/uploads/test.txt', 'hello-public-uploads');
21 $zip->addFromString('storage/uploads/test.txt', 'hello-storage-uploads');
22 $zip->addFromString('themes/test.txt', 'hello-themes');
23 $zip->addFromString('db.sql', "CREATE TABLE zz_testing (names varchar(255));\nINSERT INTO zz_testing values ('barry');");
26 exec('cp -r /var/www/bookstack /var/www/bookstack-restore');
27 chdir('/var/www/bookstack-restore');
29 $result = $this->runCommand('restore', [
30 'backup-zip' => $zipFile,
36 $result->assertSuccessfulExit();
37 $result->assertStdoutContains('Restore operation complete!');
39 $result = $mysql->query('SELECT * FROM zz_testing where names = \'barry\';');
40 $this->assertEquals(1, mysqli_num_rows($result));
41 $result = $mysql->query('SHOW TABLES LIKE \'xx_testing\';');
42 $this->assertEquals(0, mysqli_num_rows($result));
44 $this->assertStringEqualsFile('/var/www/bookstack-restore/public/uploads/test.txt', 'hello-public-uploads');
45 $this->assertStringEqualsFile('/var/www/bookstack-restore/storage/uploads/test.txt', 'hello-storage-uploads');
46 $this->assertStringEqualsFile('/var/www/bookstack-restore/themes/test.txt', 'hello-themes');
48 $mysql->query("DROP TABLE zz_testing;");
49 exec('rm -rf /var/www/bookstack-restore');
52 protected function buildZip(callable $builder): string
54 $zipFile = tempnam(sys_get_temp_dir(), 'cli-test');
55 $testZip = new \ZipArchive('');
56 $testZip->open($zipFile);