From 7d1176c02492ad7b4bc7573acacd4e155c4f0535 Mon Sep 17 00:00:00 2001 From: Karsten Nowak Date: Tue, 30 Jul 2024 19:13:44 +0200 Subject: [PATCH] [TASK] Add functional test for createTestDataCommand Related #1120 --- .../Command/CreateTestDataCommandTest.php | 106 ++++++++++++++++++ .../Command/Fixtures/Database/OtherTeas.csv | 6 + .../Command/Fixtures/Database/Pages.csv | 4 + .../Command/Fixtures/Database/Teas.csv | 4 + .../Fixtures/Database/TeasAfterDelete.csv | 4 + 5 files changed, 124 insertions(+) create mode 100644 Tests/Functional/Command/CreateTestDataCommandTest.php create mode 100644 Tests/Functional/Command/Fixtures/Database/OtherTeas.csv create mode 100644 Tests/Functional/Command/Fixtures/Database/Pages.csv create mode 100644 Tests/Functional/Command/Fixtures/Database/Teas.csv create mode 100644 Tests/Functional/Command/Fixtures/Database/TeasAfterDelete.csv diff --git a/Tests/Functional/Command/CreateTestDataCommandTest.php b/Tests/Functional/Command/CreateTestDataCommandTest.php new file mode 100644 index 0000000..30bdb09 --- /dev/null +++ b/Tests/Functional/Command/CreateTestDataCommandTest.php @@ -0,0 +1,106 @@ +importCSVDataSet(__DIR__ . '/Fixtures/Database/Pages.csv'); + $this->subject = new CreateTestDataCommand(self::COMMAND_NAME); + $application = new Application(); + $application->add($this->subject); + + $command = $application->find('tea:createtestdata'); + $this->commandTester = new CommandTester($command); + } + + /** + * @test + */ + public function isConsoleCommand(): void + { + self::assertInstanceOf(Command::class, $this->subject); + } + + /** + * @test + */ + public function hasDescription(): void + { + $expected = 'Create test data for the tea extension in an already existing page (sysfolder).'; + self::assertSame($expected, $this->subject->getHelp()); + } + + /** + * @test + */ + public function hasHelpText(): void + { + $expected = 'Create test data for the tea extension in an already existing page (sysfolder).'; + self::assertSame($expected, $this->subject->getHelp()); + } + + /** + * @test + */ + public function runReturnsSuccessStatus(): void + { + $result = $this->commandTester->execute( + [ + 'pageUid' => '1', + ], + ); + + self::assertSame(Command::SUCCESS, $result); + } + + /** + * @test + */ + public function testDataGetsCreated(): void + { + $this->commandTester->execute([ + 'pageUid' => '1', + ]); + + self::assertCSVDataSet(__DIR__ . '/Fixtures/Database/Teas.csv'); + } + + /** + * @test + */ + public function testDataGetsDeletedBeforeNewDataCreated(): void + { + $this->importCSVDataSet(__DIR__ . '/Fixtures/Database/Teas.csv'); + $this->commandTester->execute( + [ + 'pageUid' => '1', + '--delete-data-before' => true, + ] + ); + + self::assertCSVDataSet(__DIR__ . '/Fixtures/Database/TeasAfterDelete.csv'); + } + +} diff --git a/Tests/Functional/Command/Fixtures/Database/OtherTeas.csv b/Tests/Functional/Command/Fixtures/Database/OtherTeas.csv new file mode 100644 index 0000000..fab4071 --- /dev/null +++ b/Tests/Functional/Command/Fixtures/Database/OtherTeas.csv @@ -0,0 +1,6 @@ +"tx_tea_domain_model_tea" +,"uid","pid","title","description","deleted" +,3,1,"Darjeeling","I love that tea!","0" +,4,1,"Earl Grey","A nice tea!","0" +,1,2,"Black tea","I hate that.","0" +,2,2,"Green tea","Is ok.","0" diff --git a/Tests/Functional/Command/Fixtures/Database/Pages.csv b/Tests/Functional/Command/Fixtures/Database/Pages.csv new file mode 100644 index 0000000..f4878eb --- /dev/null +++ b/Tests/Functional/Command/Fixtures/Database/Pages.csv @@ -0,0 +1,4 @@ +"pages",,,,,,,,, +,"uid","pid","sorting","deleted","t3_origuid","title",,, +,1,0,256,0,0,"Tea data",,, +,2,0,512,0,0,"Other tea data",,, diff --git a/Tests/Functional/Command/Fixtures/Database/Teas.csv b/Tests/Functional/Command/Fixtures/Database/Teas.csv new file mode 100644 index 0000000..40e686b --- /dev/null +++ b/Tests/Functional/Command/Fixtures/Database/Teas.csv @@ -0,0 +1,4 @@ +"tx_tea_domain_model_tea" +,"uid","pid","title","description","deleted" +,1,1,"Darjeeling","I love that tea!",0 +,2,1,"Earl Grey","A nice tea!",0 diff --git a/Tests/Functional/Command/Fixtures/Database/TeasAfterDelete.csv b/Tests/Functional/Command/Fixtures/Database/TeasAfterDelete.csv new file mode 100644 index 0000000..3967dcd --- /dev/null +++ b/Tests/Functional/Command/Fixtures/Database/TeasAfterDelete.csv @@ -0,0 +1,4 @@ +"tx_tea_domain_model_tea" +,"uid","pid","title","description","deleted" +,3,1,"Darjeeling","I love that tea!",0 +,4,1,"Earl Grey","A nice tea!",0