From 03d034a0d0ba531dae8b13a58105f6eb80d3f650 Mon Sep 17 00:00:00 2001 From: Bastian Allgeier Date: Tue, 20 Jan 2026 11:23:43 +0100 Subject: [PATCH 1/3] refact: Migrate remove command to command classes --- commands/remove/command.php | 47 +--------------------- src/CLI/Commands/Remove/Command.php | 61 +++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 46 deletions(-) create mode 100644 src/CLI/Commands/Remove/Command.php diff --git a/commands/remove/command.php b/commands/remove/command.php index 76b992e..490fbd8 100755 --- a/commands/remove/command.php +++ b/commands/remove/command.php @@ -1,48 +1,3 @@ 'Removes a custom command', - 'args' => [ - 'name' => [ - 'description' => 'The name of the command', - ] - ], - 'command' => static function (CLI $cli): void { - $name = $cli->argOrPrompt('name', 'Enter a name for the command:'); - $name = str_replace(':', '/', $name); - - $global = $cli->root('commands.global') . '/' . $name . '.php'; - $local = $cli->root('commands.local') . '/' . $name . '.php'; - - $files = []; - - if (is_file($global) === true) { - $files[] = $global; - } - - if (is_file($local) === true) { - $files[] = $local; - } - - if (count($files) > 1) { - $input = $cli->checkboxes('Which commands do you want to delete?:', $files); - $trash = $input->prompt(); - } else { - $trash = $files; - } - - foreach ($trash as $file) { - unlink($file); - } - - if (count($trash) === 1) { - $cli->success('The command has been deleted'); - } else { - $cli->success('The commands have been deleted'); - } - } -]; +return Kirby\CLI\Commands\Remove\Command::class; diff --git a/src/CLI/Commands/Remove/Command.php b/src/CLI/Commands/Remove/Command.php new file mode 100644 index 0000000..2ba6d0f --- /dev/null +++ b/src/CLI/Commands/Remove/Command.php @@ -0,0 +1,61 @@ + [ + 'description' => 'The name of the command', + ] + ]; + } + + public static function command(CLI $cli): void + { + $name = $cli->argOrPrompt('name', 'Enter a name for the command:'); + $name = str_replace(':', '/', $name); + + $global = $cli->root('commands.global') . '/' . $name . '.php'; + $local = $cli->root('commands.local') . '/' . $name . '.php'; + + $files = []; + + if (is_file($global) === true) { + $files[] = $global; + } + + if (is_file($local) === true) { + $files[] = $local; + } + + if (count($files) > 1) { + $input = $cli->checkboxes('Which commands do you want to delete?:', $files); + $trash = $input->prompt(); + } else { + $trash = $files; + } + + foreach ($trash as $file) { + unlink($file); + } + + if (count($trash) === 1) { + $cli->success('The command has been deleted'); + } else { + $cli->success('The commands have been deleted'); + } + } + + public static function description(): string|null + { + return 'Removes a custom command'; + } +} From b661d926ac1b9d3a690738e35a20a7617dc6ee9e Mon Sep 17 00:00:00 2001 From: Bastian Allgeier Date: Tue, 20 Jan 2026 18:04:52 +0100 Subject: [PATCH 2/3] test: First set of possible unit tests --- src/CLI/BufferWriter.php | 35 +++ tests/CLI/BootstrapTest.php | 48 ++- tests/CLI/CLITest.php | 12 +- tests/CLI/Commands/BackupTest.php | 25 ++ tests/CLI/Commands/HelpTest.php | 65 ++++ tests/CLI/Commands/RootsTest.php | 63 ++++ tests/CLI/Commands/SecurityTest.php | 34 +++ tests/CLI/Commands/VersionTest.php | 36 +++ tests/CLI/KirbyInstallation.php | 286 ++++++++++++++++++ tests/CLI/TestCase.php | 122 ++++++++ tests/CLI/TestableCLI.php | 28 ++ .../CLI/{ => fixtures}/bootstrap/a/index.php | 0 .../{ => fixtures}/bootstrap/b/www/index.php | 0 .../bootstrap/c/public/index.php | 0 .../bootstrap/d/public_html/index.php | 0 .../commands/invalid-action.php | 0 .../commands/invalid-format.php | 0 .../commands/nested/_templates/template.php | 0 .../commands/nested/command.php | 0 .../commands/nested/not-a-command.txt | 0 tests/CLI/{ => fixtures}/commands/test.php | 0 21 files changed, 719 insertions(+), 35 deletions(-) create mode 100644 src/CLI/BufferWriter.php create mode 100644 tests/CLI/Commands/BackupTest.php create mode 100644 tests/CLI/Commands/HelpTest.php create mode 100644 tests/CLI/Commands/RootsTest.php create mode 100644 tests/CLI/Commands/SecurityTest.php create mode 100644 tests/CLI/Commands/VersionTest.php create mode 100644 tests/CLI/KirbyInstallation.php create mode 100644 tests/CLI/TestableCLI.php rename tests/CLI/{ => fixtures}/bootstrap/a/index.php (100%) rename tests/CLI/{ => fixtures}/bootstrap/b/www/index.php (100%) rename tests/CLI/{ => fixtures}/bootstrap/c/public/index.php (100%) rename tests/CLI/{ => fixtures}/bootstrap/d/public_html/index.php (100%) rename tests/CLI/{ => fixtures}/commands/invalid-action.php (100%) rename tests/CLI/{ => fixtures}/commands/invalid-format.php (100%) rename tests/CLI/{ => fixtures}/commands/nested/_templates/template.php (100%) rename tests/CLI/{ => fixtures}/commands/nested/command.php (100%) rename tests/CLI/{ => fixtures}/commands/nested/not-a-command.txt (100%) rename tests/CLI/{ => fixtures}/commands/test.php (100%) diff --git a/src/CLI/BufferWriter.php b/src/CLI/BufferWriter.php new file mode 100644 index 0000000..985f56f --- /dev/null +++ b/src/CLI/BufferWriter.php @@ -0,0 +1,35 @@ +buffer = []; + } + + public function getLines(): array + { + return $this->buffer; + } + + public function getOutput(): string + { + return implode('', $this->buffer); + } + + public function write($content): void + { + $this->buffer[] = $content; + } +} diff --git a/tests/CLI/BootstrapTest.php b/tests/CLI/BootstrapTest.php index 032d64b..9f2d37e 100644 --- a/tests/CLI/BootstrapTest.php +++ b/tests/CLI/BootstrapTest.php @@ -1,50 +1,40 @@ assertSame($root . '/index.php', index()); $this->assertSame($root . '/index.php', bootstrap()); } - /** - * @covers bootstrap - * @covers index - */ - public function testIndexInWww() - { - chdir($root = __DIR__ . '/bootstrap/b'); - $this->assertSame($root . '/www/index.php', index()); - $this->assertSame($root . '/www/index.php', bootstrap()); - } - - /** - * @covers bootstrap - * @covers index - */ - public function testIndexInPublic() + public function testIndexInPublic(): void { - chdir($root = __DIR__ . '/bootstrap/c'); + chdir($root = __DIR__ . '/fixtures/bootstrap/c'); $this->assertSame($root . '/public/index.php', index()); $this->assertSame($root . '/public/index.php', bootstrap()); } - /** - * @covers bootstrap - * @covers index - */ - public function testIndexInPublicHtml() + public function testIndexInPublicHtml(): void { - chdir($root = __DIR__ . '/bootstrap/d'); + chdir($root = __DIR__ . '/fixtures/bootstrap/d'); $this->assertSame($root . '/public_html/index.php', index()); $this->assertSame($root . '/public_html/index.php', bootstrap()); } + + public function testIndexInWww(): void + { + chdir($root = __DIR__ . '/fixtures/bootstrap/b'); + $this->assertSame($root . '/www/index.php', index()); + $this->assertSame($root . '/www/index.php', bootstrap()); + } } diff --git a/tests/CLI/CLITest.php b/tests/CLI/CLITest.php index fb10599..2cda869 100644 --- a/tests/CLI/CLITest.php +++ b/tests/CLI/CLITest.php @@ -12,7 +12,7 @@ class CLITest extends TestCase { public function setUp(): void { - chdir(__DIR__); + chdir(__DIR__ . '/fixtures'); } /** @@ -36,7 +36,7 @@ public function testCommandsInDirectory() $this->assertSame([], $commands); // existing command directory - $commands = $cli->commandsInDirectory(__DIR__ . '/commands'); + $commands = $cli->commandsInDirectory(__DIR__ . '/fixtures/commands'); $expected = [ 'invalid-action', 'invalid-format', @@ -55,11 +55,11 @@ public function testDir() $cli = new CLI(); // current working directory - $this->assertSame(__DIR__, $cli->dir()); + $this->assertSame(__DIR__ . '/fixtures', $cli->dir()); // relative - $this->assertSame(__DIR__ . '/./commands', $cli->dir('./commands')); - $this->assertSame(__DIR__ . '/../commands', $cli->dir('../commands')); + $this->assertSame(__DIR__ . '/fixtures/./commands', $cli->dir('./commands')); + $this->assertSame(__DIR__ . '/fixtures/../commands', $cli->dir('../commands')); // absolute $this->assertSame('/test', $cli->dir('/test')); @@ -211,7 +211,7 @@ public function testRoot() $this->assertSame(dirname(__DIR__, 2) . '/commands', $cli->root('commands.core')); $this->assertSame($cli->home() . '/commands', $cli->root('commands.global')); - $this->assertSame(__DIR__ . '/commands', $cli->root('commands.local')); + $this->assertSame(__DIR__ . '/fixtures/commands', $cli->root('commands.local')); } /** diff --git a/tests/CLI/Commands/BackupTest.php b/tests/CLI/Commands/BackupTest.php new file mode 100644 index 0000000..60f6bb1 --- /dev/null +++ b/tests/CLI/Commands/BackupTest.php @@ -0,0 +1,25 @@ +assertArrayHasKey('root', $args); + $this->assertSame('Selects the kirby root, which should be backuped', $args['root']['description']); + } + + public function testDescription(): void + { + $this->assertSame('Creates backup of application files', Backup::description()); + } +} diff --git a/tests/CLI/Commands/HelpTest.php b/tests/CLI/Commands/HelpTest.php new file mode 100644 index 0000000..c6940c9 --- /dev/null +++ b/tests/CLI/Commands/HelpTest.php @@ -0,0 +1,65 @@ +assertSame([], Help::args()); + } + + public function testCommand(): void + { + $cli = $this->createCLI(); + $this->setupOutputCapture(); + + Help::command($cli); + + $this->assertOutputContains('Kirby CLI'); + $this->assertOutputContains('Core commands:'); + $this->assertOutputContains('Have fun with the Kirby CLI!'); + } + + public function testCommandShowsCoreCommands(): void + { + $cli = $this->createCLI(); + $this->setupOutputCapture(); + + Help::command($cli); + + // Should list some core commands + $this->assertOutputContains('kirby help'); + $this->assertOutputContains('kirby version'); + $this->assertOutputContains('kirby install'); + } + + public function testCommandShowsVersionNumber(): void + { + $cli = $this->createCLI(); + $this->setupOutputCapture(); + + Help::command($cli); + + // Should show CLI version (matches semver pattern) + $output = $this->getOutput(); + $this->assertMatchesRegularExpression('/Kirby CLI \d+\.\d+\.\d+/', $output); + } + + public function testDescription(): void + { + $this->assertSame('Prints help for the Kirby CLI', Help::description()); + } +} diff --git a/tests/CLI/Commands/RootsTest.php b/tests/CLI/Commands/RootsTest.php new file mode 100644 index 0000000..0e6d4a5 --- /dev/null +++ b/tests/CLI/Commands/RootsTest.php @@ -0,0 +1,63 @@ +assertSame([], Roots::args()); + } + + public function testCommand(): void + { + $cli = $this->createCLI(); + $this->setupOutputCapture(); + + Roots::command($cli); + + // Should output the commands roots + $this->assertOutputContains('commands.core'); + $this->assertOutputContains('commands.global'); + $this->assertOutputContains('commands.local'); + } + + public function testCommandWithCustomRoots(): void + { + $customRoots = [ + 'custom' => '/path/to/custom' + ]; + + $cli = $this->createCLI(roots: $customRoots); + $this->setupOutputCapture(); + + Roots::command($cli); + + $this->assertOutputContains('custom'); + $this->assertOutputContains('/path/to/custom'); + } + + public function testCommandWithKirbyRoots(): void + { + $cli = $this->createCLIWithKirby(); + $this->setupOutputCapture(); + + Roots::command($cli); + + // Should include Kirby roots + $this->assertOutputContains('index'); + $this->assertOutputContains('content'); + $this->assertOutputContains('site'); + } + + public function testDescription(): void + { + $this->assertSame('Shows a list with all configured roots', Roots::description()); + } +} diff --git a/tests/CLI/Commands/SecurityTest.php b/tests/CLI/Commands/SecurityTest.php new file mode 100644 index 0000000..aa1a55e --- /dev/null +++ b/tests/CLI/Commands/SecurityTest.php @@ -0,0 +1,34 @@ +assertSame([], Security::args()); + } + + public function testCommand(): void + { + $cli = $this->createCLIWithKirby(); + $this->setupOutputCapture(); + + Security::command($cli); + + // Should output something (either success or security messages) + $output = $this->getOutput(); + $this->assertNotEmpty($output); + } + + public function testDescription(): void + { + $this->assertSame('Performs security checks of the site', Security::description()); + } +} diff --git a/tests/CLI/Commands/VersionTest.php b/tests/CLI/Commands/VersionTest.php new file mode 100644 index 0000000..2445c55 --- /dev/null +++ b/tests/CLI/Commands/VersionTest.php @@ -0,0 +1,36 @@ +assertSame([], Version::args()); + } + + public function testCommand(): void + { + $cli = $this->createCLIWithKirby(); + $this->setupOutputCapture(); + + Version::command($cli); + + // Should output the Kirby version (format: x.x.x or x.x.x-xxx) + $output = $this->getOutput(); + + $this->assertMatchesRegularExpression('/\d+\.\d+\.\d+/', $output); + $this->assertOutputContains($output, $cli->kirby()->version()); + } + + public function testDescription(): void + { + $this->assertSame('Prints the Kirby version', Version::description()); + } +} diff --git a/tests/CLI/KirbyInstallation.php b/tests/CLI/KirbyInstallation.php new file mode 100644 index 0000000..be4cbfe --- /dev/null +++ b/tests/CLI/KirbyInstallation.php @@ -0,0 +1,286 @@ + content) + */ + public function __construct( + string $version = 'main', + array $content = [] + ) { + $this->version = $version; + + $this->ensureBaseDir(); + $this->ensureKirbyDownloaded(); + $this->ensureBootstrapped(); + $this->tempDir = $this->createTempInstallation($content); + $this->createApp(); + } + + /** + * Returns the App instance + */ + public function app(): \Kirby\Cms\App + { + return $this->app; + } + + /** + * Cleans up the temporary installation + */ + public function cleanup(): void + { + // Remove temp directory + if (is_dir($this->tempDir) === true) { + $this->removeDirectory($this->tempDir); + } + + // Destroy the Kirby App instance + if ($this->app !== null) { + \Kirby\Cms\App::destroy(); + $this->app = null; + } + } + + /** + * Clears the entire Kirby cache (useful for CI or manual cleanup) + */ + public static function clearCache(): void + { + if (static::$baseDir !== null && is_dir(static::$baseDir) === true) { + static::removeDirectory(static::$baseDir); + static::$baseDir = null; + static::$downloadedVersions = []; + static::$bootstrappedVersion = null; + } + } + + /** + * Creates the Kirby App instance with temp roots + */ + protected function createApp(): void + { + $this->app = new \Kirby\Cms\App([ + 'roots' => [ + 'index' => $this->tempDir, + 'content' => $this->tempDir . '/content', + 'site' => $this->tempDir . '/site', + 'kirby' => $this->kirbyDir(), + ] + ]); + } + + /** + * Creates a temporary directory for content and site + */ + protected function createTempInstallation(array $content = []): string + { + $tempDir = sys_get_temp_dir() . '/kirby-cli-test-' . uniqid(); + mkdir($tempDir, 0755, true); + + // Create required directories + mkdir($tempDir . '/content', 0755, true); + mkdir($tempDir . '/site', 0755, true); + mkdir($tempDir . '/site/templates', 0755, true); + + // Create a basic site.txt for the home page + mkdir($tempDir . '/content/home', 0755, true); + file_put_contents($tempDir . '/content/home/default.txt', "Title: Home\n----\n"); + + // Create a default template + file_put_contents( + $tempDir . '/site/templates/default.php', + 'title() ?>' + ); + + // Apply custom content + foreach ($content as $path => $data) { + $fullPath = $tempDir . '/content/' . $path; + $dir = dirname($fullPath); + if (is_dir($dir) === false) { + mkdir($dir, 0755, true); + } + file_put_contents($fullPath, $data); + } + + return $tempDir; + } + + /** + * Downloads a specific Kirby version to the cache directory + */ + protected function downloadKirby(): void + { + $kirbyDir = $this->kirbyDir(); + + if (is_dir($kirbyDir) === true) { + static::$downloadedVersions[$this->version] = true; + return; + } + + // Build download URL based on version + if ($this->version === 'main') { + $zipUrl = 'https://github.com/getkirby/kirby/archive/refs/heads/main.zip'; + $extractedName = 'kirby-main'; + } else { + $zipUrl = 'https://github.com/getkirby/kirby/archive/refs/tags/' . $this->version . '.zip'; + $extractedName = 'kirby-' . $this->version; + } + + $zipFile = static::$baseDir . '/kirby-' . $this->version . '.zip'; + + // Download + $content = file_get_contents($zipUrl); + if ($content === false) { + throw new Exception('Failed to download Kirby ' . $this->version . ' from ' . $zipUrl); + } + file_put_contents($zipFile, $content); + + // Extract + $zip = new \ZipArchive(); + if ($zip->open($zipFile) !== true) { + throw new Exception('Failed to open Kirby zip file'); + } + + $zip->extractTo(static::$baseDir); + $zip->close(); + + // Rename extracted directory to version-specific name + $extractedDir = static::$baseDir . '/' . $extractedName; + if (is_dir($extractedDir) === true) { + rename($extractedDir, $kirbyDir); + } + + // Cleanup zip file + unlink($zipFile); + + static::$downloadedVersions[$this->version] = true; + } + + /** + * Ensures the base cache directory exists + */ + protected function ensureBaseDir(): void + { + if (static::$baseDir === null) { + static::$baseDir = sys_get_temp_dir() . '/kirby-cli-cache'; + if (is_dir(static::$baseDir) === false) { + mkdir(static::$baseDir, 0755, true); + } + } + } + + /** + * Bootstraps Kirby once per version from the cache directory + */ + protected function ensureBootstrapped(): void + { + // Already bootstrapped this version + if (static::$bootstrappedVersion === $this->version) { + return; + } + + // Cannot switch versions once bootstrapped (autoloader conflict) + if (static::$bootstrappedVersion !== null) { + throw new Exception( + 'Cannot switch Kirby versions within the same test run. ' . + 'Already bootstrapped version: ' . static::$bootstrappedVersion . ', ' . + 'requested version: ' . $this->version + ); + } + + $bootstrapFile = $this->kirbyDir() . '/bootstrap.php'; + + if (file_exists($bootstrapFile) === false) { + throw new Exception('Kirby bootstrap.php not found at ' . $bootstrapFile); + } + + require_once $bootstrapFile; + static::$bootstrappedVersion = $this->version; + } + + /** + * Ensures the Kirby version is downloaded + */ + protected function ensureKirbyDownloaded(): void + { + if (isset(static::$downloadedVersions[$this->version]) === false) { + $this->downloadKirby(); + } + } + + /** + * Returns the path to the cached Kirby directory for this version + */ + protected function kirbyDir(): string + { + return static::$baseDir . '/kirby-' . $this->version; + } + + /** + * Removes a directory recursively (static version) + */ + protected static function removeDirectory(string $dir): void + { + if (is_dir($dir) === false) { + return; + } + + $iterator = new RecursiveIteratorIterator( + new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS), + RecursiveIteratorIterator::CHILD_FIRST + ); + + foreach ($iterator as $item) { + if ($item->isDir() === true) { + rmdir($item->getPathname()); + } else { + unlink($item->getPathname()); + } + } + + rmdir($dir); + } + + /** + * Returns the path to the temp installation + */ + public function root(): string + { + return $this->tempDir; + } + + /** + * Returns the Kirby version being used + */ + public function version(): string + { + return $this->version; + } +} diff --git a/tests/CLI/TestCase.php b/tests/CLI/TestCase.php index 3e3645b..f66ff4d 100644 --- a/tests/CLI/TestCase.php +++ b/tests/CLI/TestCase.php @@ -1,9 +1,131 @@ getOutput(); + $this->assertStringContainsString( + $expected, + $output, + $message ?: "Expected output to contain '{$expected}'. Actual output: {$output}" + ); + } + + /** + * Asserts that the captured output does not contain the expected string + */ + protected function assertOutputNotContains(string $expected, string $message = ''): void + { + $output = $this->getOutput(); + $this->assertStringNotContainsString( + $expected, + $output, + $message ?: "Expected output not to contain '{$expected}'. Actual output: {$output}" + ); + } + + /** + * Creates a TestableCLI instance with optional Kirby App + */ + protected function createCLI( + object|null $kirby = null, + array $roots = [] + ): TestableCLI { + $this->cli = new TestableCLI($kirby, $roots); + return $this->cli; + } + + /** + * Creates a TestableCLI instance with a real Kirby installation + */ + protected function createCLIWithKirby( + string $version = 'main', + array $content = [] + ): TestableCLI { + $kirby = $this->kirby($version, $content); + return $this->createCLI($kirby); + } + + /** + * Gets the captured output + */ + protected function getOutput(): string + { + if ($this->outputBuffer === null) { + throw new \RuntimeException('Output capture not set up. Call setupOutputCapture() first.'); + } + + return $this->outputBuffer->getOutput(); + } + + /** + * Creates and returns a real Kirby App instance from a temp installation + */ + protected function kirby( + string $version = 'main', + array $content = [] + ): object { + $this->kirbyInstallation = new KirbyInstallation($version, $content); + return $this->kirbyInstallation->app(); + } + + /** + * Returns the path to the temp Kirby installation + */ + protected function kirbyRoot(): string + { + if ($this->kirbyInstallation === null) { + throw new \RuntimeException('No Kirby fixture. Call kirby() first.'); + } + + return $this->kirbyInstallation->root(); + } + + /** + * Sets up output capturing for the CLI instance + */ + protected function setupOutputCapture(TestableCLI|null $cli = null): BufferWriter + { + $cli ??= $this->cli; + + if ($cli === null) { + throw new \RuntimeException('No CLI instance available. Create one first with createCLI()'); + } + + $this->outputBuffer = new BufferWriter(); + $cli->climate()->output->add('buffer', $this->outputBuffer); + $cli->climate()->output->defaultTo('buffer'); + + return $this->outputBuffer; + } + + protected function tearDown(): void + { + // Clean up any Kirby fixture + if ($this->kirbyInstallation !== null) { + $this->kirbyInstallation->cleanup(); + $this->kirbyInstallation = null; + + // Kirby registers error handlers, restore to default + restore_error_handler(); + restore_exception_handler(); + } + + $this->cli = null; + $this->outputBuffer = null; + } } diff --git a/tests/CLI/TestableCLI.php b/tests/CLI/TestableCLI.php new file mode 100644 index 0000000..c218d57 --- /dev/null +++ b/tests/CLI/TestableCLI.php @@ -0,0 +1,28 @@ +climate = new CLImate(); + $this->roots = $roots; + + if ($kirby !== null) { + $this->kirby = $kirby; + $this->roots = array_merge($kirby->roots()->toArray(), $roots); + } + + $this->createCommandRoots(); + } +} diff --git a/tests/CLI/bootstrap/a/index.php b/tests/CLI/fixtures/bootstrap/a/index.php similarity index 100% rename from tests/CLI/bootstrap/a/index.php rename to tests/CLI/fixtures/bootstrap/a/index.php diff --git a/tests/CLI/bootstrap/b/www/index.php b/tests/CLI/fixtures/bootstrap/b/www/index.php similarity index 100% rename from tests/CLI/bootstrap/b/www/index.php rename to tests/CLI/fixtures/bootstrap/b/www/index.php diff --git a/tests/CLI/bootstrap/c/public/index.php b/tests/CLI/fixtures/bootstrap/c/public/index.php similarity index 100% rename from tests/CLI/bootstrap/c/public/index.php rename to tests/CLI/fixtures/bootstrap/c/public/index.php diff --git a/tests/CLI/bootstrap/d/public_html/index.php b/tests/CLI/fixtures/bootstrap/d/public_html/index.php similarity index 100% rename from tests/CLI/bootstrap/d/public_html/index.php rename to tests/CLI/fixtures/bootstrap/d/public_html/index.php diff --git a/tests/CLI/commands/invalid-action.php b/tests/CLI/fixtures/commands/invalid-action.php similarity index 100% rename from tests/CLI/commands/invalid-action.php rename to tests/CLI/fixtures/commands/invalid-action.php diff --git a/tests/CLI/commands/invalid-format.php b/tests/CLI/fixtures/commands/invalid-format.php similarity index 100% rename from tests/CLI/commands/invalid-format.php rename to tests/CLI/fixtures/commands/invalid-format.php diff --git a/tests/CLI/commands/nested/_templates/template.php b/tests/CLI/fixtures/commands/nested/_templates/template.php similarity index 100% rename from tests/CLI/commands/nested/_templates/template.php rename to tests/CLI/fixtures/commands/nested/_templates/template.php diff --git a/tests/CLI/commands/nested/command.php b/tests/CLI/fixtures/commands/nested/command.php similarity index 100% rename from tests/CLI/commands/nested/command.php rename to tests/CLI/fixtures/commands/nested/command.php diff --git a/tests/CLI/commands/nested/not-a-command.txt b/tests/CLI/fixtures/commands/nested/not-a-command.txt similarity index 100% rename from tests/CLI/commands/nested/not-a-command.txt rename to tests/CLI/fixtures/commands/nested/not-a-command.txt diff --git a/tests/CLI/commands/test.php b/tests/CLI/fixtures/commands/test.php similarity index 100% rename from tests/CLI/commands/test.php rename to tests/CLI/fixtures/commands/test.php From 90695d8571a7f446add16a4c74ffd859b377ec99 Mon Sep 17 00:00:00 2001 From: Bastian Allgeier Date: Wed, 21 Jan 2026 16:15:27 +0100 Subject: [PATCH 3/3] test: Add more basic unit tests --- tests/CLI/Commands/Clean/ContentTest.php | 26 +++++++++++++ tests/CLI/Commands/Clear/CacheTest.php | 25 +++++++++++++ tests/CLI/Commands/Clear/LockTest.php | 22 +++++++++++ tests/CLI/Commands/Clear/LoginsTest.php | 22 +++++++++++ tests/CLI/Commands/Clear/MediaTest.php | 22 +++++++++++ tests/CLI/Commands/Clear/SessionsTest.php | 22 +++++++++++ tests/CLI/Commands/DownloadTest.php | 30 +++++++++++++++ tests/CLI/Commands/Install/KitTest.php | 28 ++++++++++++++ tests/CLI/Commands/Install/RepoTest.php | 35 ++++++++++++++++++ tests/CLI/Commands/InstallTest.php | 26 +++++++++++++ tests/CLI/Commands/License/InfoTest.php | 27 ++++++++++++++ tests/CLI/Commands/License/RenewalTest.php | 28 ++++++++++++++ tests/CLI/Commands/Make/BlueprintTest.php | 25 +++++++++++++ tests/CLI/Commands/Make/CollectionTest.php | 25 +++++++++++++ tests/CLI/Commands/Make/CommandTest.php | 31 ++++++++++++++++ tests/CLI/Commands/Make/ConfigTest.php | 25 +++++++++++++ tests/CLI/Commands/Make/ControllerTest.php | 25 +++++++++++++ tests/CLI/Commands/Make/LanguageTest.php | 34 +++++++++++++++++ tests/CLI/Commands/Make/ModelTest.php | 25 +++++++++++++ tests/CLI/Commands/Make/PluginTest.php | 25 +++++++++++++ tests/CLI/Commands/Make/SnippetTest.php | 25 +++++++++++++ tests/CLI/Commands/Make/TemplateTest.php | 25 +++++++++++++ tests/CLI/Commands/Make/UserTest.php | 37 +++++++++++++++++++ .../Commands/Migrate/To/PublicFolderTest.php | 22 +++++++++++ .../Commands/Migrate/To/RootFolderTest.php | 22 +++++++++++ tests/CLI/Commands/Plugin/InstallTest.php | 30 +++++++++++++++ tests/CLI/Commands/Plugin/RemoveTest.php | 26 +++++++++++++ tests/CLI/Commands/Plugin/UpgradeTest.php | 30 +++++++++++++++ tests/CLI/Commands/RegisterTest.php | 32 ++++++++++++++++ tests/CLI/Commands/Remove/CommandTest.php | 25 +++++++++++++ tests/CLI/Commands/UUID/DuplicatesTest.php | 26 +++++++++++++ tests/CLI/Commands/UUID/GenerateTest.php | 22 +++++++++++ tests/CLI/Commands/UUID/PopulateTest.php | 22 +++++++++++ tests/CLI/Commands/UUID/RemoveTest.php | 22 +++++++++++ tests/CLI/Commands/UnzipTest.php | 30 +++++++++++++++ tests/CLI/Commands/UpgradeTest.php | 26 +++++++++++++ 36 files changed, 950 insertions(+) create mode 100644 tests/CLI/Commands/Clean/ContentTest.php create mode 100644 tests/CLI/Commands/Clear/CacheTest.php create mode 100644 tests/CLI/Commands/Clear/LockTest.php create mode 100644 tests/CLI/Commands/Clear/LoginsTest.php create mode 100644 tests/CLI/Commands/Clear/MediaTest.php create mode 100644 tests/CLI/Commands/Clear/SessionsTest.php create mode 100644 tests/CLI/Commands/DownloadTest.php create mode 100644 tests/CLI/Commands/Install/KitTest.php create mode 100644 tests/CLI/Commands/Install/RepoTest.php create mode 100644 tests/CLI/Commands/InstallTest.php create mode 100644 tests/CLI/Commands/License/InfoTest.php create mode 100644 tests/CLI/Commands/License/RenewalTest.php create mode 100644 tests/CLI/Commands/Make/BlueprintTest.php create mode 100644 tests/CLI/Commands/Make/CollectionTest.php create mode 100644 tests/CLI/Commands/Make/CommandTest.php create mode 100644 tests/CLI/Commands/Make/ConfigTest.php create mode 100644 tests/CLI/Commands/Make/ControllerTest.php create mode 100644 tests/CLI/Commands/Make/LanguageTest.php create mode 100644 tests/CLI/Commands/Make/ModelTest.php create mode 100644 tests/CLI/Commands/Make/PluginTest.php create mode 100644 tests/CLI/Commands/Make/SnippetTest.php create mode 100644 tests/CLI/Commands/Make/TemplateTest.php create mode 100644 tests/CLI/Commands/Make/UserTest.php create mode 100644 tests/CLI/Commands/Migrate/To/PublicFolderTest.php create mode 100644 tests/CLI/Commands/Migrate/To/RootFolderTest.php create mode 100644 tests/CLI/Commands/Plugin/InstallTest.php create mode 100644 tests/CLI/Commands/Plugin/RemoveTest.php create mode 100644 tests/CLI/Commands/Plugin/UpgradeTest.php create mode 100644 tests/CLI/Commands/RegisterTest.php create mode 100644 tests/CLI/Commands/Remove/CommandTest.php create mode 100644 tests/CLI/Commands/UUID/DuplicatesTest.php create mode 100644 tests/CLI/Commands/UUID/GenerateTest.php create mode 100644 tests/CLI/Commands/UUID/PopulateTest.php create mode 100644 tests/CLI/Commands/UUID/RemoveTest.php create mode 100644 tests/CLI/Commands/UnzipTest.php create mode 100644 tests/CLI/Commands/UpgradeTest.php diff --git a/tests/CLI/Commands/Clean/ContentTest.php b/tests/CLI/Commands/Clean/ContentTest.php new file mode 100644 index 0000000..e487083 --- /dev/null +++ b/tests/CLI/Commands/Clean/ContentTest.php @@ -0,0 +1,26 @@ +assertArrayHasKey('dry-run', $args); + $this->assertSame('Run the command without actually updating content', $args['dry-run']['description']); + $this->assertTrue($args['dry-run']['noValue']); + } + + public function testDescription(): void + { + $this->assertSame('Deletes all fields from page, file or user content files that are not defined in the blueprint, no matter if they contain content or not.', Content::description()); + } +} diff --git a/tests/CLI/Commands/Clear/CacheTest.php b/tests/CLI/Commands/Clear/CacheTest.php new file mode 100644 index 0000000..cf75d6d --- /dev/null +++ b/tests/CLI/Commands/Clear/CacheTest.php @@ -0,0 +1,25 @@ +assertArrayHasKey('name', $args); + $this->assertSame('The name of the cache', $args['name']['description']); + } + + public function testDescription(): void + { + $this->assertSame('Clears the cache', Cache::description()); + } +} diff --git a/tests/CLI/Commands/Clear/LockTest.php b/tests/CLI/Commands/Clear/LockTest.php new file mode 100644 index 0000000..1b42b31 --- /dev/null +++ b/tests/CLI/Commands/Clear/LockTest.php @@ -0,0 +1,22 @@ +assertSame([], Lock::args()); + } + + public function testDescription(): void + { + $this->assertSame('Deletes the content `.lock` files', Lock::description()); + } +} diff --git a/tests/CLI/Commands/Clear/LoginsTest.php b/tests/CLI/Commands/Clear/LoginsTest.php new file mode 100644 index 0000000..cdd6c4c --- /dev/null +++ b/tests/CLI/Commands/Clear/LoginsTest.php @@ -0,0 +1,22 @@ +assertSame([], Logins::args()); + } + + public function testDescription(): void + { + $this->assertSame('Deletes the users `.logins` file', Logins::description()); + } +} diff --git a/tests/CLI/Commands/Clear/MediaTest.php b/tests/CLI/Commands/Clear/MediaTest.php new file mode 100644 index 0000000..0932f48 --- /dev/null +++ b/tests/CLI/Commands/Clear/MediaTest.php @@ -0,0 +1,22 @@ +assertSame([], Media::args()); + } + + public function testDescription(): void + { + $this->assertSame('Deletes the media folder', Media::description()); + } +} diff --git a/tests/CLI/Commands/Clear/SessionsTest.php b/tests/CLI/Commands/Clear/SessionsTest.php new file mode 100644 index 0000000..beb0f97 --- /dev/null +++ b/tests/CLI/Commands/Clear/SessionsTest.php @@ -0,0 +1,22 @@ +assertSame([], Sessions::args()); + } + + public function testDescription(): void + { + $this->assertSame('Destroys all sessions', Sessions::description()); + } +} diff --git a/tests/CLI/Commands/DownloadTest.php b/tests/CLI/Commands/DownloadTest.php new file mode 100644 index 0000000..15ca0cb --- /dev/null +++ b/tests/CLI/Commands/DownloadTest.php @@ -0,0 +1,30 @@ +assertArrayHasKey('url', $args); + $this->assertSame('The URL to the file', $args['url']['description']); + $this->assertTrue($args['url']['required']); + + $this->assertArrayHasKey('file', $args); + $this->assertSame('Where to save the download', $args['file']['description']); + $this->assertTrue($args['file']['required']); + } + + public function testDescription(): void + { + $this->assertSame('Downloads a file via URL', Download::description()); + } +} diff --git a/tests/CLI/Commands/Install/KitTest.php b/tests/CLI/Commands/Install/KitTest.php new file mode 100644 index 0000000..10fdaf7 --- /dev/null +++ b/tests/CLI/Commands/Install/KitTest.php @@ -0,0 +1,28 @@ +assertArrayHasKey('kit', $args); + $this->assertSame('The name of the kit (starterkit, demokit, plainkit)', $args['kit']['description']); + + $this->assertArrayHasKey('folder', $args); + $this->assertSame('The name of folder the kit should be installed into', $args['folder']['description']); + } + + public function testDescription(): void + { + $this->assertSame('Installs a Kirby Kit in a subfolder', Kit::description()); + } +} diff --git a/tests/CLI/Commands/Install/RepoTest.php b/tests/CLI/Commands/Install/RepoTest.php new file mode 100644 index 0000000..0347f1f --- /dev/null +++ b/tests/CLI/Commands/Install/RepoTest.php @@ -0,0 +1,35 @@ +assertArrayHasKey('repo', $args); + $this->assertSame('The Github repo path (i.e. getkirby/kirby)', $args['repo']['description']); + $this->assertTrue($args['repo']['required']); + + $this->assertArrayHasKey('folder', $args); + $this->assertSame('The name of folder the repo should be installed into', $args['folder']['description']); + + $this->assertArrayHasKey('version', $args); + $this->assertSame('The version corresponding with the tag name in the repo', $args['version']['description']); + $this->assertSame('v', $args['version']['prefix']); + $this->assertSame('version', $args['version']['longPrefix']); + $this->assertSame('latest', $args['version']['defaultValue']); + } + + public function testDescription(): void + { + $this->assertSame('Downloads a repository from the getkirby org on Github', Repo::description()); + } +} diff --git a/tests/CLI/Commands/InstallTest.php b/tests/CLI/Commands/InstallTest.php new file mode 100644 index 0000000..aa2c79d --- /dev/null +++ b/tests/CLI/Commands/InstallTest.php @@ -0,0 +1,26 @@ +assertArrayHasKey('version', $args); + $this->assertSame('The version corresponding with the tag name in the repo', $args['version']['description']); + $this->assertSame('latest', $args['version']['defaultValue']); + } + + public function testDescription(): void + { + $this->assertSame('Installs the kirby folder', Install::description()); + } +} diff --git a/tests/CLI/Commands/License/InfoTest.php b/tests/CLI/Commands/License/InfoTest.php new file mode 100644 index 0000000..64ec803 --- /dev/null +++ b/tests/CLI/Commands/License/InfoTest.php @@ -0,0 +1,27 @@ +assertArrayHasKey('format', $args); + $this->assertSame('Output format: table or json.', $args['format']['description']); + $this->assertSame('f', $args['format']['prefix']); + $this->assertSame('format', $args['format']['longPrefix']); + } + + public function testDescription(): void + { + $this->assertSame('Displays Kirby license information in table or JSON format.', Info::description()); + } +} diff --git a/tests/CLI/Commands/License/RenewalTest.php b/tests/CLI/Commands/License/RenewalTest.php new file mode 100644 index 0000000..4c9e413 --- /dev/null +++ b/tests/CLI/Commands/License/RenewalTest.php @@ -0,0 +1,28 @@ +assertArrayHasKey('format', $args); + $this->assertSame('The format for the renewal date (any format supported by PHP\'s `date()` function) or "timestamp"', $args['format']['description']); + $this->assertSame('f', $args['format']['prefix']); + $this->assertSame('format', $args['format']['longPrefix']); + $this->assertSame('Y-m-d', $args['format']['defaultValue']); + } + + public function testDescription(): void + { + $this->assertSame('Show the renewal date of the activated Kirby license.', Renewal::description()); + } +} diff --git a/tests/CLI/Commands/Make/BlueprintTest.php b/tests/CLI/Commands/Make/BlueprintTest.php new file mode 100644 index 0000000..e113004 --- /dev/null +++ b/tests/CLI/Commands/Make/BlueprintTest.php @@ -0,0 +1,25 @@ +assertArrayHasKey('name', $args); + $this->assertSame('The name of the blueprint', $args['name']['description']); + } + + public function testDescription(): void + { + $this->assertSame('Creates a new blueprint file in site/blueprints', Blueprint::description()); + } +} diff --git a/tests/CLI/Commands/Make/CollectionTest.php b/tests/CLI/Commands/Make/CollectionTest.php new file mode 100644 index 0000000..813ec7c --- /dev/null +++ b/tests/CLI/Commands/Make/CollectionTest.php @@ -0,0 +1,25 @@ +assertArrayHasKey('name', $args); + $this->assertSame('The name of the collection', $args['name']['description']); + } + + public function testDescription(): void + { + $this->assertSame('Creates a new collection in site/collections', Collection::description()); + } +} diff --git a/tests/CLI/Commands/Make/CommandTest.php b/tests/CLI/Commands/Make/CommandTest.php new file mode 100644 index 0000000..e67b873 --- /dev/null +++ b/tests/CLI/Commands/Make/CommandTest.php @@ -0,0 +1,31 @@ +assertArrayHasKey('name', $args); + $this->assertSame('The name of the command', $args['name']['description']); + + $this->assertArrayHasKey('global', $args); + $this->assertSame('Install the command globally', $args['global']['description']); + $this->assertSame('g', $args['global']['prefix']); + $this->assertSame('global', $args['global']['longPrefix']); + $this->assertTrue($args['global']['noValue']); + } + + public function testDescription(): void + { + $this->assertSame('Creates a new local command for the Kirby CLI', Command::description()); + } +} diff --git a/tests/CLI/Commands/Make/ConfigTest.php b/tests/CLI/Commands/Make/ConfigTest.php new file mode 100644 index 0000000..70f6f2a --- /dev/null +++ b/tests/CLI/Commands/Make/ConfigTest.php @@ -0,0 +1,25 @@ +assertArrayHasKey('domain', $args); + $this->assertSame('An optional domain for a multi-environment config', $args['domain']['description']); + } + + public function testDescription(): void + { + $this->assertSame('Creates a new config file in site/config', Config::description()); + } +} diff --git a/tests/CLI/Commands/Make/ControllerTest.php b/tests/CLI/Commands/Make/ControllerTest.php new file mode 100644 index 0000000..71912b6 --- /dev/null +++ b/tests/CLI/Commands/Make/ControllerTest.php @@ -0,0 +1,25 @@ +assertArrayHasKey('name', $args); + $this->assertSame('The name of the controller', $args['name']['description']); + } + + public function testDescription(): void + { + $this->assertSame('Creates a new template controller in site/controllers', Controller::description()); + } +} diff --git a/tests/CLI/Commands/Make/LanguageTest.php b/tests/CLI/Commands/Make/LanguageTest.php new file mode 100644 index 0000000..d5adb8d --- /dev/null +++ b/tests/CLI/Commands/Make/LanguageTest.php @@ -0,0 +1,34 @@ +assertArrayHasKey('code', $args); + $this->assertSame('The code of the language', $args['code']['description']); + + $this->assertArrayHasKey('name', $args); + $this->assertSame('The name of the language', $args['name']['description']); + + $this->assertArrayHasKey('locale', $args); + $this->assertSame('The locale of the language', $args['locale']['description']); + + $this->assertArrayHasKey('direction', $args); + $this->assertSame('The direction of the language', $args['direction']['description']); + } + + public function testDescription(): void + { + $this->assertSame('Creates a new language', Language::description()); + } +} diff --git a/tests/CLI/Commands/Make/ModelTest.php b/tests/CLI/Commands/Make/ModelTest.php new file mode 100644 index 0000000..d914b52 --- /dev/null +++ b/tests/CLI/Commands/Make/ModelTest.php @@ -0,0 +1,25 @@ +assertArrayHasKey('name', $args); + $this->assertSame('The name of the model', $args['name']['description']); + } + + public function testDescription(): void + { + $this->assertSame('Creates a new page model in site/models', Model::description()); + } +} diff --git a/tests/CLI/Commands/Make/PluginTest.php b/tests/CLI/Commands/Make/PluginTest.php new file mode 100644 index 0000000..a2e59bf --- /dev/null +++ b/tests/CLI/Commands/Make/PluginTest.php @@ -0,0 +1,25 @@ +assertArrayHasKey('name', $args); + $this->assertSame('The name of the plugin (`vendor/plugin`)', $args['name']['description']); + } + + public function testDescription(): void + { + $this->assertSame('Creates a new plugin in site/plugins', Plugin::description()); + } +} diff --git a/tests/CLI/Commands/Make/SnippetTest.php b/tests/CLI/Commands/Make/SnippetTest.php new file mode 100644 index 0000000..03c0dbd --- /dev/null +++ b/tests/CLI/Commands/Make/SnippetTest.php @@ -0,0 +1,25 @@ +assertArrayHasKey('name', $args); + $this->assertSame('The name of the snippet', $args['name']['description']); + } + + public function testDescription(): void + { + $this->assertSame('Creates a new snippet in site/snippets', Snippet::description()); + } +} diff --git a/tests/CLI/Commands/Make/TemplateTest.php b/tests/CLI/Commands/Make/TemplateTest.php new file mode 100644 index 0000000..fbc45ec --- /dev/null +++ b/tests/CLI/Commands/Make/TemplateTest.php @@ -0,0 +1,25 @@ +assertArrayHasKey('name', $args); + $this->assertSame('The name of the template', $args['name']['description']); + } + + public function testDescription(): void + { + $this->assertSame('Creates a new template in site/templates', Template::description()); + } +} diff --git a/tests/CLI/Commands/Make/UserTest.php b/tests/CLI/Commands/Make/UserTest.php new file mode 100644 index 0000000..7d9c86b --- /dev/null +++ b/tests/CLI/Commands/Make/UserTest.php @@ -0,0 +1,37 @@ +assertArrayHasKey('email', $args); + $this->assertSame('The email of the user', $args['email']['description']); + + $this->assertArrayHasKey('role', $args); + $this->assertSame('The role of the user', $args['role']['description']); + + $this->assertArrayHasKey('name', $args); + $this->assertSame('The name of the user', $args['name']['description']); + + $this->assertArrayHasKey('language', $args); + $this->assertSame('The language of the user', $args['language']['description']); + + $this->assertArrayHasKey('password', $args); + $this->assertSame('The password of the user', $args['password']['description']); + } + + public function testDescription(): void + { + $this->assertSame('Creates a new user', User::description()); + } +} diff --git a/tests/CLI/Commands/Migrate/To/PublicFolderTest.php b/tests/CLI/Commands/Migrate/To/PublicFolderTest.php new file mode 100644 index 0000000..70a4cf9 --- /dev/null +++ b/tests/CLI/Commands/Migrate/To/PublicFolderTest.php @@ -0,0 +1,22 @@ +assertSame([], PublicFolder::args()); + } + + public function testDescription(): void + { + $this->assertSame('Switch to a public folder setup', PublicFolder::description()); + } +} diff --git a/tests/CLI/Commands/Migrate/To/RootFolderTest.php b/tests/CLI/Commands/Migrate/To/RootFolderTest.php new file mode 100644 index 0000000..0e54356 --- /dev/null +++ b/tests/CLI/Commands/Migrate/To/RootFolderTest.php @@ -0,0 +1,22 @@ +assertSame([], RootFolder::args()); + } + + public function testDescription(): void + { + $this->assertSame('Switch to a root folder setup', RootFolder::description()); + } +} diff --git a/tests/CLI/Commands/Plugin/InstallTest.php b/tests/CLI/Commands/Plugin/InstallTest.php new file mode 100644 index 0000000..945fe9c --- /dev/null +++ b/tests/CLI/Commands/Plugin/InstallTest.php @@ -0,0 +1,30 @@ +assertArrayHasKey('repo', $args); + $this->assertSame('The Github repo path (i.e. getkirby/kql)', $args['repo']['description']); + $this->assertTrue($args['repo']['required']); + + $this->assertArrayHasKey('version', $args); + $this->assertSame('The version corresponding with the tag name in the repo', $args['version']['description']); + $this->assertSame('latest', $args['version']['defaultValue']); + } + + public function testDescription(): void + { + $this->assertSame('Installs a Kirby plugin repository from Github', Install::description()); + } +} diff --git a/tests/CLI/Commands/Plugin/RemoveTest.php b/tests/CLI/Commands/Plugin/RemoveTest.php new file mode 100644 index 0000000..8be5bf0 --- /dev/null +++ b/tests/CLI/Commands/Plugin/RemoveTest.php @@ -0,0 +1,26 @@ +assertArrayHasKey('repo', $args); + $this->assertSame('The Kirby plugin registry name (i.e. getkirby/kql)', $args['repo']['description']); + $this->assertTrue($args['repo']['required']); + } + + public function testDescription(): void + { + $this->assertSame('Removes a Kirby plugin', Remove::description()); + } +} diff --git a/tests/CLI/Commands/Plugin/UpgradeTest.php b/tests/CLI/Commands/Plugin/UpgradeTest.php new file mode 100644 index 0000000..e946fc8 --- /dev/null +++ b/tests/CLI/Commands/Plugin/UpgradeTest.php @@ -0,0 +1,30 @@ +assertArrayHasKey('repo', $args); + $this->assertSame('The Kirby plugin registry name (i.e. getkirby/kql)', $args['repo']['description']); + $this->assertTrue($args['repo']['required']); + + $this->assertArrayHasKey('version', $args); + $this->assertSame('The version corresponding with the tag name in the repo', $args['version']['description']); + $this->assertSame('latest', $args['version']['defaultValue']); + } + + public function testDescription(): void + { + $this->assertSame('Upgrades a Kirby plugin', Upgrade::description()); + } +} diff --git a/tests/CLI/Commands/RegisterTest.php b/tests/CLI/Commands/RegisterTest.php new file mode 100644 index 0000000..f0db534 --- /dev/null +++ b/tests/CLI/Commands/RegisterTest.php @@ -0,0 +1,32 @@ +assertArrayHasKey('email', $args); + $this->assertSame('e', $args['email']['prefix']); + $this->assertSame('email', $args['email']['longPrefix']); + $this->assertSame('The email address you\'ve used to purchase the license', $args['email']['description']); + + $this->assertArrayHasKey('license', $args); + $this->assertSame('l', $args['license']['prefix']); + $this->assertSame('license', $args['license']['longPrefix']); + $this->assertSame('Your Kirby 3 license key', $args['license']['description']); + } + + public function testDescription(): void + { + $this->assertSame('Registers the installation', Register::description()); + } +} diff --git a/tests/CLI/Commands/Remove/CommandTest.php b/tests/CLI/Commands/Remove/CommandTest.php new file mode 100644 index 0000000..b3ad38b --- /dev/null +++ b/tests/CLI/Commands/Remove/CommandTest.php @@ -0,0 +1,25 @@ +assertArrayHasKey('name', $args); + $this->assertSame('The name of the command', $args['name']['description']); + } + + public function testDescription(): void + { + $this->assertSame('Removes a custom command', Command::description()); + } +} diff --git a/tests/CLI/Commands/UUID/DuplicatesTest.php b/tests/CLI/Commands/UUID/DuplicatesTest.php new file mode 100644 index 0000000..e344a83 --- /dev/null +++ b/tests/CLI/Commands/UUID/DuplicatesTest.php @@ -0,0 +1,26 @@ +assertArrayHasKey('fix', $args); + $this->assertSame('Fix duplicate UUIDs by generating new ones', $args['fix']['description']); + $this->assertTrue($args['fix']['noValue']); + } + + public function testDescription(): void + { + $this->assertSame('Find and optionally fix duplicate UUIDs', Duplicates::description()); + } +} diff --git a/tests/CLI/Commands/UUID/GenerateTest.php b/tests/CLI/Commands/UUID/GenerateTest.php new file mode 100644 index 0000000..85e5a86 --- /dev/null +++ b/tests/CLI/Commands/UUID/GenerateTest.php @@ -0,0 +1,22 @@ +assertSame([], Generate::args()); + } + + public function testDescription(): void + { + $this->assertSame('Creates all missing UUIDs', Generate::description()); + } +} diff --git a/tests/CLI/Commands/UUID/PopulateTest.php b/tests/CLI/Commands/UUID/PopulateTest.php new file mode 100644 index 0000000..d92dab6 --- /dev/null +++ b/tests/CLI/Commands/UUID/PopulateTest.php @@ -0,0 +1,22 @@ +assertSame([], Populate::args()); + } + + public function testDescription(): void + { + $this->assertSame('Populates cache for all UUIDs', Populate::description()); + } +} diff --git a/tests/CLI/Commands/UUID/RemoveTest.php b/tests/CLI/Commands/UUID/RemoveTest.php new file mode 100644 index 0000000..39adfab --- /dev/null +++ b/tests/CLI/Commands/UUID/RemoveTest.php @@ -0,0 +1,22 @@ +assertSame([], Remove::args()); + } + + public function testDescription(): void + { + $this->assertSame('Removes all UUIDs', Remove::description()); + } +} diff --git a/tests/CLI/Commands/UnzipTest.php b/tests/CLI/Commands/UnzipTest.php new file mode 100644 index 0000000..ebb63a9 --- /dev/null +++ b/tests/CLI/Commands/UnzipTest.php @@ -0,0 +1,30 @@ +assertArrayHasKey('file', $args); + $this->assertSame('The file to unzip', $args['file']['description']); + $this->assertTrue($args['file']['required']); + + $this->assertArrayHasKey('to', $args); + $this->assertSame('The place to extract the zip to', $args['to']['description']); + $this->assertTrue($args['to']['required']); + } + + public function testDescription(): void + { + $this->assertSame('Extracts a zip file', Unzip::description()); + } +} diff --git a/tests/CLI/Commands/UpgradeTest.php b/tests/CLI/Commands/UpgradeTest.php new file mode 100644 index 0000000..2698698 --- /dev/null +++ b/tests/CLI/Commands/UpgradeTest.php @@ -0,0 +1,26 @@ +assertArrayHasKey('version', $args); + $this->assertSame('The version corresponding with tag name in the kirby repo', $args['version']['description']); + $this->assertSame('latest', $args['version']['defaultValue']); + } + + public function testDescription(): void + { + $this->assertSame('Upgrades the Kirby core', Upgrade::description()); + } +}