Skip to content

Commit

Permalink
Add test cases for WorkflowDataMapper
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasnatter committed May 20, 2020
1 parent 938a7fa commit f2b1460
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private function setPublishedToLiveDimension(WorkflowInterface $object, array $d
$published = $data['published'] ?? null;

if (!$published) {
return;
throw new \RuntimeException('Expected "published" to be set in the data array.');
}

$object->setWorkflowPublished(new \DateTimeImmutable($published));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function testMapLocalizedNoWorkflow(): void
$workflowMapper->map($data, $dimensionContent->reveal(), $localizedDimensionContent->reveal());
}

public function testMapUnlocalizedWorkflow(): void
public function testMapUnlocalizedDraft(): void
{
$workflowMapper = $this->createWorkflowDataMapperInstance();

Expand All @@ -71,15 +71,17 @@ public function testMapUnlocalizedWorkflow(): void
$dimensionContent = $this->prophesize(DimensionContentInterface::class);
$dimensionContent->willImplement(WorkflowInterface::class);
$dimension = $this->prophesize(DimensionInterface::class);
$dimension->getStage()->willReturn(DimensionInterface::STAGE_LIVE);
$dimension->getStage()->willReturn(DimensionInterface::STAGE_DRAFT);
$dimensionContent->getDimension()->willReturn($dimension->reveal());
$dimensionContent->getWorkflowPlace()->willReturn(null);

$dimensionContent->setWorkflowPublished(Argument::cetera())->shouldBeCalled();
$dimensionContent->setWorkflowPlace(WorkflowInterface::WORKFLOW_PLACE_UNPUBLISHED)->shouldBeCalled();
$dimensionContent->setWorkflowPublished(Argument::cetera())->shouldNotBeCalled();

$workflowMapper->map($data, $dimensionContent->reveal());
}

public function testMapLocalizedWorkflow(): void
public function testMapUnlocalizedDraftPlaceAlreadySet(): void
{
$workflowMapper = $this->createWorkflowDataMapperInstance();

Expand All @@ -89,20 +91,58 @@ public function testMapLocalizedWorkflow(): void

$dimensionContent = $this->prophesize(DimensionContentInterface::class);
$dimensionContent->willImplement(WorkflowInterface::class);
$dimension = $this->prophesize(DimensionInterface::class);
$dimension->getStage()->willReturn(DimensionInterface::STAGE_DRAFT);
$dimensionContent->getDimension()->willReturn($dimension->reveal());
$dimensionContent->getWorkflowPlace()->willReturn(WorkflowInterface::WORKFLOW_PLACE_UNPUBLISHED);

$localizedDimensionContent = $this->prophesize(DimensionContentInterface::class);
$localizedDimensionContent->willImplement(WorkflowInterface::class);
$dimensionContent->setWorkflowPlace(Argument::cetera())->shouldNotBeCalled();
$dimensionContent->setWorkflowPublished(Argument::cetera())->shouldNotBeCalled();

$workflowMapper->map($data, $dimensionContent->reveal());
}

public function testMapUnlocalizedLive(): void
{
$workflowMapper = $this->createWorkflowDataMapperInstance();

$data = [
'published' => (new \DateTime())->format('c'),
];

$dimensionContent = $this->prophesize(DimensionContentInterface::class);
$dimensionContent->willImplement(WorkflowInterface::class);
$dimension = $this->prophesize(DimensionInterface::class);
$dimension->getStage()->willReturn(DimensionInterface::STAGE_LIVE);
$localizedDimensionContent->getDimension()->willReturn($dimension->reveal());
$dimensionContent->getDimension()->willReturn($dimension->reveal());

$dimensionContent->setWorkflowPublished(Argument::any())->shouldNotBeCalled();
$localizedDimensionContent->setWorkflowPublished(Argument::cetera())->shouldBeCalled();
$dimensionContent->setWorkflowPlace(Argument::cetera())->shouldNotBeCalled();
$dimensionContent->setWorkflowPublished(Argument::type(\DateTimeInterface::class))->shouldBeCalled();

$workflowMapper->map($data, $dimensionContent->reveal(), $localizedDimensionContent->reveal());
$workflowMapper->map($data, $dimensionContent->reveal());
}

public function testMapUnlocalizedLivePublishedNotSet(): void
{
$workflowMapper = $this->createWorkflowDataMapperInstance();

$data = [];

$dimensionContent = $this->prophesize(DimensionContentInterface::class);
$dimensionContent->willImplement(WorkflowInterface::class);
$dimension = $this->prophesize(DimensionInterface::class);
$dimension->getStage()->willReturn(DimensionInterface::STAGE_LIVE);
$dimensionContent->getDimension()->willReturn($dimension->reveal());

$dimensionContent->setWorkflowPlace(Argument::cetera())->shouldNotBeCalled();
$dimensionContent->setWorkflowPublished(Argument::cetera())->shouldNotBeCalled();

$this->expectException(\RuntimeException::class);

$workflowMapper->map($data, $dimensionContent->reveal());
}

public function testMapUnlocalizedDraftWorkflow(): void
public function testMapLocalizedDraft(): void
{
$workflowMapper = $this->createWorkflowDataMapperInstance();

Expand All @@ -112,16 +152,24 @@ public function testMapUnlocalizedDraftWorkflow(): void

$dimensionContent = $this->prophesize(DimensionContentInterface::class);
$dimensionContent->willImplement(WorkflowInterface::class);

$localizedDimensionContent = $this->prophesize(DimensionContentInterface::class);
$localizedDimensionContent->willImplement(WorkflowInterface::class);
$dimension = $this->prophesize(DimensionInterface::class);
$dimension->getStage()->willReturn(DimensionInterface::STAGE_DRAFT);
$dimensionContent->getDimension()->willReturn($dimension->reveal());
$localizedDimensionContent->getDimension()->willReturn($dimension->reveal());
$localizedDimensionContent->getWorkflowPlace()->willReturn(null);

$dimensionContent->setWorkflowPublished(Argument::any())->shouldNotBeCalled();
$dimensionContent->setWorkflowPlace(Argument::cetera())->shouldNotBeCalled();
$dimensionContent->setWorkflowPublished(Argument::cetera())->shouldNotBeCalled();

$workflowMapper->map($data, $dimensionContent->reveal());
$localizedDimensionContent->setWorkflowPlace(WorkflowInterface::WORKFLOW_PLACE_UNPUBLISHED)->shouldBeCalled();
$localizedDimensionContent->setWorkflowPublished(Argument::cetera())->shouldNotBeCalled();

$workflowMapper->map($data, $dimensionContent->reveal(), $localizedDimensionContent->reveal());
}

public function testMapLocalizedDraftWorkflow(): void
public function testMapLocalizedDraftPlaceAlreadySet(): void
{
$workflowMapper = $this->createWorkflowDataMapperInstance();

Expand All @@ -137,44 +185,66 @@ public function testMapLocalizedDraftWorkflow(): void
$dimension = $this->prophesize(DimensionInterface::class);
$dimension->getStage()->willReturn(DimensionInterface::STAGE_DRAFT);
$localizedDimensionContent->getDimension()->willReturn($dimension->reveal());
$localizedDimensionContent->getWorkflowPlace()->willReturn(WorkflowInterface::WORKFLOW_PLACE_UNPUBLISHED);

$dimensionContent->setWorkflowPlace(Argument::cetera())->shouldNotBeCalled();
$dimensionContent->setWorkflowPublished(Argument::cetera())->shouldNotBeCalled();

$dimensionContent->setWorkflowPublished(Argument::any())->shouldNotBeCalled();
$localizedDimensionContent->setWorkflowPublished(Argument::any())->shouldNotBeCalled();
$localizedDimensionContent->setWorkflowPlace(Argument::cetera())->shouldNotBeCalled();
$localizedDimensionContent->setWorkflowPublished(Argument::cetera())->shouldNotBeCalled();

$workflowMapper->map($data, $dimensionContent->reveal(), $localizedDimensionContent->reveal());
}

public function testMapPublishedNotExists(): void
public function testMapLocalizedLive(): void
{
$workflowMapper = $this->createWorkflowDataMapperInstance();

$data = [];
$data = [
'published' => (new \DateTime())->format('c'),
];

$dimensionContent = $this->prophesize(DimensionContentInterface::class);
$dimensionContent->willImplement(WorkflowInterface::class);

$localizedDimensionContent = $this->prophesize(DimensionContentInterface::class);
$localizedDimensionContent->willImplement(WorkflowInterface::class);
$dimension = $this->prophesize(DimensionInterface::class);
$dimension->getStage()->willReturn(DimensionInterface::STAGE_LIVE);
$dimensionContent->getDimension()->willReturn($dimension->reveal());
$localizedDimensionContent->getDimension()->willReturn($dimension->reveal());

$dimensionContent->setWorkflowPublished(Argument::any())->shouldNotBeCalled();
$dimensionContent->setWorkflowPlace(Argument::cetera())->shouldNotBeCalled();
$dimensionContent->setWorkflowPublished(Argument::cetera())->shouldNotBeCalled();

$workflowMapper->map($data, $dimensionContent->reveal());
$localizedDimensionContent->setWorkflowPlace(Argument::cetera())->shouldNotBeCalled();
$localizedDimensionContent->setWorkflowPublished(Argument::type(\DateTimeInterface::class))->shouldBeCalled();

$workflowMapper->map($data, $dimensionContent->reveal(), $localizedDimensionContent->reveal());
}

public function testMapPublishedNull(): void
public function testMapLocalizedLivePublishedNotSet(): void
{
$workflowMapper = $this->createWorkflowDataMapperInstance();

$data = [];

$dimensionContent = $this->prophesize(DimensionContentInterface::class);
$dimensionContent->willImplement(WorkflowInterface::class);

$localizedDimensionContent = $this->prophesize(DimensionContentInterface::class);
$localizedDimensionContent->willImplement(WorkflowInterface::class);
$dimension = $this->prophesize(DimensionInterface::class);
$dimension->getStage()->willReturn(DimensionInterface::STAGE_LIVE);
$dimensionContent->getDimension()->willReturn($dimension->reveal());
$localizedDimensionContent->getDimension()->willReturn($dimension->reveal());

$dimensionContent->setWorkflowPublished(Argument::any())->shouldNotBeCalled();
$dimensionContent->setWorkflowPlace(Argument::cetera())->shouldNotBeCalled();
$dimensionContent->setWorkflowPublished(Argument::cetera())->shouldNotBeCalled();

$workflowMapper->map($data, $dimensionContent->reveal());
$localizedDimensionContent->setWorkflowPlace(Argument::cetera())->shouldNotBeCalled();
$localizedDimensionContent->setWorkflowPublished(Argument::cetera())->shouldNotBeCalled();

$this->expectException(\RuntimeException::class);

$workflowMapper->map($data, $dimensionContent->reveal(), $localizedDimensionContent->reveal());
}
}
2 changes: 1 addition & 1 deletion Tests/Unit/Content/Domain/Model/WorkflowTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected function getWorkflowInstance(): WorkflowInterface
public function testGetWorkflowPlace(): void
{
$workflow = $this->getWorkflowInstance();
$this->assertSame('unpublished', $workflow->getWorkflowPlace());
$this->assertNull($workflow->getWorkflowPlace());
}

public function testSetWorkflowPlaceReview(): void
Expand Down

0 comments on commit f2b1460

Please sign in to comment.