Skip to content

Commit

Permalink
Day 16: Delete action test
Browse files Browse the repository at this point in the history
  • Loading branch information
sergey-bleih authored and gregurco committed Oct 8, 2019
1 parent 6d3c591 commit a3dbd41
Showing 1 changed file with 28 additions and 8 deletions.
36 changes: 28 additions & 8 deletions tests/Controller/JobControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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
Expand Down

0 comments on commit a3dbd41

Please sign in to comment.