From a3dbd413a8ff91976b80597d5da02c16bee65353 Mon Sep 17 00:00:00 2001 From: Sergey Bleih Date: Thu, 20 Jun 2019 19:59:44 +0300 Subject: [PATCH] Day 16: Delete action test --- tests/Controller/JobControllerTest.php | 36 ++++++++++++++++++++------ 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/tests/Controller/JobControllerTest.php b/tests/Controller/JobControllerTest.php index 55d0700..cf7f02d 100644 --- a/tests/Controller/JobControllerTest.php +++ b/tests/Controller/JobControllerTest.php @@ -190,8 +190,34 @@ public function testSubmittingEditFormSavesChangesAndRedirects(): void public function testPublishActionPublishesJob(): void { - $this->markTestSkipped('It seems publishing is not working properly!'); + $job = $this->createTestJob(); + + $client = $this->getClient(); + $client->request('GET', '/job/' . $job->getToken()); + $client->submitForm('Publish'); + $em = $this->getContainer()->get('doctrine.orm.entity_manager'); + $em->refresh($job); + + $this->assertTrue($job->isActivated()); + } + + public function testDeleteActionDeletesTheJob(): void + { + $job = $this->createTestJob(); + + $client = $this->getClient(); + $client->request('GET', '/job/' . $job->getToken()); + $client->submitForm('Delete'); + + $em = $this->getContainer()->get('doctrine.orm.entity_manager'); + $job = $em->getRepository(Job::class)->findOneBy(['id' => $job->getId()]); + + $this->assertNull($job); + } + + private function createTestJob(): Job + { $em = $this->getContainer()->get('doctrine.orm.entity_manager'); $category = (new Category()) @@ -214,13 +240,7 @@ public function testPublishActionPublishesJob(): void $em->persist($job); $em->flush($job); - $this->assertFalse($job->isActivated()); - $this->assertFalse($job->isPublic()); - - $this->getClient()->request('POST', '/job/' . $job->getToken() . '/publish'); - - $em->refresh($job); - $this->assertTrue($job->isActivated()); + return $job; } private function getJobTokenFromRequest(): string