Handle unavailable skills and skillsets in backend and frontend

Show an error message in backend, to allow editors to spot the issue.
Hide issues in frontend to not break frontend.

Relates: #1, #2
This commit is contained in:
Daniel Siepmann 2020-10-05 09:40:54 +02:00
parent 101d2fb3e4
commit a1dda725a0
Signed by: Daniel Siepmann
GPG key ID: 33D6629915560EF4
8 changed files with 210 additions and 7 deletions

View file

@ -74,7 +74,11 @@ class Preview implements PageLayoutViewDrawItemHookInterface
$skills = GeneralUtility::intExplode(',', $row['skilldisplay_skills'], true); $skills = GeneralUtility::intExplode(',', $row['skilldisplay_skills'], true);
foreach ($skills as $skillId) { foreach ($skills as $skillId) {
try {
$row['skills'][] = $this->skillApi->getById($skillId); $row['skills'][] = $this->skillApi->getById($skillId);
} catch (\Exception $e) {
$row['skills'][]['error'] = $e->getMessage();
}
} }
return $row; return $row;
@ -85,7 +89,11 @@ class Preview implements PageLayoutViewDrawItemHookInterface
$skillSets = GeneralUtility::intExplode(',', $row['skilldisplay_skillset'], true); $skillSets = GeneralUtility::intExplode(',', $row['skilldisplay_skillset'], true);
foreach ($skillSets as $skillSetId) { foreach ($skillSets as $skillSetId) {
try {
$row['skillSets'][] = $this->skillSetApi->getById($skillSetId); $row['skillSets'][] = $this->skillSetApi->getById($skillSetId);
} catch (\Exception $e) {
$row['skillSets'][]['error'] = $e->getMessage();
}
} }
return $row; return $row;

View file

@ -54,7 +54,11 @@ class SkillSets implements DataProcessorInterface
$skillSets = []; $skillSets = [];
foreach ($skillSetIds as $skillSetId) { foreach ($skillSetIds as $skillSetId) {
try {
$skillSets[] = $this->skillSetApi->getById($skillSetId); $skillSets[] = $this->skillSetApi->getById($skillSetId);
} catch (\Exception $e) {
continue;
}
} }
$processedData[$as] = $skillSets; $processedData[$as] = $skillSets;

View file

@ -54,7 +54,11 @@ class Skills implements DataProcessorInterface
$skills = []; $skills = [];
foreach ($skillIds as $skillId) { foreach ($skillIds as $skillId) {
try {
$skills[] = $this->skillApi->getById($skillId); $skills[] = $this->skillApi->getById($skillId);
} catch (\Exception $e) {
continue;
}
} }
$processedData[$as] = $skills; $processedData[$as] = $skills;

View file

@ -10,8 +10,15 @@
<ol> <ol>
<f:for each="{skills}" as="skill"> <f:for each="{skills}" as="skill">
<li> <li>
<f:if condition="{skill.error}">
<f:then>
<f:be.infobox state="2">{skill.error}</f:be.infobox>
</f:then>
<f:else>
<strong>{skill.title}</strong><br> <strong>{skill.title}</strong><br>
{sd:verification.url(skill: skill.id)} {sd:verification.url(skill: skill.id)}
</f:else>
</f:if>
</li> </li>
</f:for> </f:for>
</ol> </ol>

View file

@ -10,7 +10,15 @@
<ol> <ol>
<f:for each="{skillSets}" as="skillSet"> <f:for each="{skillSets}" as="skillSet">
<li> <li>
<strong>{skillSet.name}</strong><br> <f:if condition="{skillSet.error}">
<f:then>
<f:be.infobox state="2">{skillSet.error}</f:be.infobox>
</f:then>
<f:else>
<strong>{skillSet.title}</strong><br>
{sd:verification.url(skillSet: skillSet.id)}
</f:else>
</f:if>
</li> </li>
</f:for> </f:for>
</ol> </ol>

View file

@ -188,4 +188,106 @@ class PreviewTest extends TestCase
], ],
], $row); ], $row);
} }
/**
* @test
*/
public function addsExceptionMessageForSkills(): void
{
$skillApi = $this->prophesize(Skill::class);
$skillSetApi = $this->prophesize(SkillSet::class);
$pageLayoutView = $this->prophesize(PageLayoutView::class);
$exception = new \Exception('Some helpfull message');
$skill10 = $this->prophesize(SkillEntity::class);
$skillApi->getById(10)->willThrow($exception);
$skill20 = $this->prophesize(SkillEntity::class);
$skillApi->getById(20)->willReturn($skill20->reveal());
$subject = new Preview(
$skillApi->reveal(),
$skillSetApi->reveal()
);
$revealedPageLayoutView = $pageLayoutView->reveal();
$drawItem = false;
$headerContent = '';
$itemContent = '';
$row = [
'skilldisplay_skills' => '10, 20,,',
'skilldisplay_skillset' => '0',
];
$subject->preProcess(
$revealedPageLayoutView,
$drawItem,
$headerContent,
$itemContent,
$row
);
static::assertFalse($drawItem);
static::assertEmpty($headerContent);
static::assertEmpty($itemContent);
static::assertSame([
'skilldisplay_skills' => '10, 20,,',
'skilldisplay_skillset' => '0',
'skills' => [
[
'error' => 'Some helpfull message',
],
$skill20->reveal(),
],
'skillSets' => [],
], $row);
}
/**
* @test
*/
public function addsExceptionMessageForSkillSets(): void
{
$skillApi = $this->prophesize(Skill::class);
$skillSetApi = $this->prophesize(SkillSet::class);
$pageLayoutView = $this->prophesize(PageLayoutView::class);
$exception = new \Exception('Some helpfull message');
$skillSetApi->getById(10)->willThrow($exception);
$subject = new Preview(
$skillApi->reveal(),
$skillSetApi->reveal()
);
$revealedPageLayoutView = $pageLayoutView->reveal();
$drawItem = false;
$headerContent = '';
$itemContent = '';
$row = [
'skilldisplay_skills' => '',
'skilldisplay_skillset' => '10',
];
$subject->preProcess(
$revealedPageLayoutView,
$drawItem,
$headerContent,
$itemContent,
$row
);
static::assertFalse($drawItem);
static::assertEmpty($headerContent);
static::assertEmpty($itemContent);
static::assertSame([
'skilldisplay_skills' => '',
'skilldisplay_skillset' => '10',
'skills' => [],
'skillSets' => [
[
'error' => 'Some helpfull message',
],
],
], $row);
}
} }

View file

@ -106,4 +106,39 @@ class SkillSetsTest extends TestCase
], ],
], $processedData); ], $processedData);
} }
/**
* @test
*/
public function skillsSkillSetInCaseOfException(): void
{
$skillApi = $this->prophesize(SkillSet::class);
$skillSet10 = $this->prophesize(SkillSetEntity::class);
$skillApi->getById(10)->willReturn($skillSet10->reveal());
$skillSet20 = $this->prophesize(SkillSetEntity::class);
$skillApi->getById(20)->willThrow(new \Exception());
$cObj = $this->prophesize(ContentObjectRenderer::class);
$cObj->stdWrapValue('as', [], 'skillSets')->willReturn('skillSets');
$cObj->stdWrapValue('skillSets', [], '')->willReturn('10, 20,,');
$subject = new SkillSets(
$skillApi->reveal()
);
$processedData = $subject->process(
$cObj->reveal(),
[],
[],
[
'skillSets' => '10, 20,,',
]
);
static::assertEquals([
'skillSets' => [
$skillSet10->reveal(),
],
], $processedData);
}
} }

View file

@ -106,4 +106,39 @@ class SkillsTest extends TestCase
], ],
], $processedData); ], $processedData);
} }
/**
* @test
*/
public function skillsSkillSetInCaseOfException(): void
{
$skillApi = $this->prophesize(Skill::class);
$skill10 = $this->prophesize(SkillEntity::class);
$skillApi->getById(10)->willReturn($skill10->reveal());
$skill20 = $this->prophesize(SkillEntity::class);
$skillApi->getById(20)->willThrow(new \Exception());
$cObj = $this->prophesize(ContentObjectRenderer::class);
$cObj->stdWrapValue('as', [], 'skills')->willReturn('skills');
$cObj->stdWrapValue('skills', [], '')->willReturn('10, 20,,');
$subject = new Skills(
$skillApi->reveal()
);
$processedData = $subject->process(
$cObj->reveal(),
[],
[],
[
'skills' => '10, 20,,',
]
);
static::assertEquals([
'skills' => [
$skill10->reveal(),
],
], $processedData);
}
} }