From c4cd275c8312b75c136a3b7c085b4f6e3a58c8aa Mon Sep 17 00:00:00 2001 From: lubiana Date: Wed, 10 Jul 2024 19:05:28 +0200 Subject: [PATCH] #29: add test for homecontroller --- tests/Controller/HomeControllerTest.php | 69 +++++++++++++++++++++++++ tests/DbWebTest.php | 4 +- 2 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 tests/Controller/HomeControllerTest.php diff --git a/tests/Controller/HomeControllerTest.php b/tests/Controller/HomeControllerTest.php new file mode 100644 index 0000000..4dcb184 --- /dev/null +++ b/tests/Controller/HomeControllerTest.php @@ -0,0 +1,69 @@ +client->request( + 'GET', + '/' + ); + + self::assertResponseStatusCodeSame(302); + self::assertResponseHeaderSame('Location', '/food/order/list'); + + } + + public function testSetUsername(): void + { + $this->client->request( + 'GET', + '/username', + ); + + self::assertResponseStatusCodeSame(200); + + $this->client->submitForm('Save', [ + 'user_name_form[username]' => 'Testing-1', + ]); + self::assertResponseStatusCodeSame(302); + self::assertResponseHeaderSame('Location', '/food/order/list'); + self::assertResponseCookieValueSame('username', 'Testing-1'); + } + + + public function testRemoveUsername(): void + { + $this->client->request( + 'GET', + '/username', + ); + + self::assertResponseStatusCodeSame(200); + + $this->client->submitForm('Save', [ + 'user_name_form[username]' => '', + ]); + self::assertResponseStatusCodeSame(302); + self::assertResponseHeaderSame('Location', '/food/order/list'); + self::assertResponseCookieValueSame('username', ''); + } + + #[Override] + public function getEntityClass(): string + { + return ''; + } +} diff --git a/tests/DbWebTest.php b/tests/DbWebTest.php index 18ef24a..218ed9a 100644 --- a/tests/DbWebTest.php +++ b/tests/DbWebTest.php @@ -28,6 +28,8 @@ abstract class DbWebTest extends WebTestCase $schemaTool->dropDatabase(); $schemaTool->updateSchema($metadata); - $this->repository = $this->manager->getRepository($this->getEntityClass()); + if ($this->getEntityClass() !== '') { + $this->repository = $this->manager->getRepository($this->getEntityClass()); + } } }