From d06e92ffc269617c9ccca2c19865cbf54de27a71 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 23 Apr 2023 13:22:04 +0200 Subject: [PATCH] Created CLI test for short URL importing --- .../test-cli/Command/ImportShortUrlsTest.php | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 module/CLI/test-cli/Command/ImportShortUrlsTest.php diff --git a/module/CLI/test-cli/Command/ImportShortUrlsTest.php b/module/CLI/test-cli/Command/ImportShortUrlsTest.php new file mode 100644 index 00000000..3a710af0 --- /dev/null +++ b/module/CLI/test-cli/Command/ImportShortUrlsTest.php @@ -0,0 +1,79 @@ +tempCsvFile = tempnam(sys_get_temp_dir(), 'shlink_csv'); + if (! $this->tempCsvFile) { + return; + } + + $handle = fopen($this->tempCsvFile, 'w+'); + if (! $handle) { + $this->fail('It was not possible to open the temporary file to write CSV on it'); + } + + fwrite( + $handle, + <<tempCsvFile)) { + unlink($this->tempCsvFile); + } + } + + #[Test] + public function defaultDomainIsIgnoredWhenExplicitlyProvided(): void + { + if (! $this->tempCsvFile) { + $this->fail('It was not possible to create a temporary CSV file'); + } + + [$output] = $this->exec([ImportCommand::NAME, 'csv'], [$this->tempCsvFile, ';']); + + self::assertStringContainsString('https://shlink.io: Imported', $output); + self::assertStringContainsString('https://example.com: Imported', $output); + + [$listOutput1] = $this->exec( + [ListShortUrlsCommand::NAME, '--show-domain', '--search-term', 'testing-default-domain-import-1'], + ); + self::assertStringContainsString('DEFAULT', $listOutput1); + [$listOutput1] = $this->exec( + [ListShortUrlsCommand::NAME, '--show-domain', '--search-term', 'testing-default-domain-import-2'], + ); + self::assertStringContainsString('DEFAULT', $listOutput1); + } +}