Skip to content

Commit

Permalink
Fix null pages
Browse files Browse the repository at this point in the history
Added tests
  • Loading branch information
RicLeP committed May 15, 2023
1 parent 0ed41bb commit 1b5e1ee
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@ public function views(): array
$themeViews = $views;

$themeViews = array_filter(array_map(function($view) {
$theme = $this->page()->block()->component();
$theme = $this->page()?->block()->component();

if (!strpos($view, $theme)) {
return str_replace('blocks.', 'pages.' . $theme . '.blocks.', $view);
}
Expand Down
10 changes: 9 additions & 1 deletion tests/BlockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,15 @@ public function can_get_views()
{
$page = $this->makePage('ep16.json');

$this->assertEquals(['blocks.layout_2-sections.text--titled', 'blocks.feature.text--titled', 'blocks.episode.text--titled', 'blocks.page.text--titled', 'blocks.text--titled'], $page->block()->features[0]->body[3]->section_1[0]->views());
$this->assertEquals([
'pages.episode.blocks.layout_2-sections.text--titled',
'pages.episode.blocks.feature.text--titled',
'pages.episode.blocks.text--titled',
'blocks.layout_2-sections.text--titled',
'blocks.feature.text--titled',
'blocks.episode.text--titled',
'blocks.text--titled'
], $page->block()->features[0]->body[3]->section_1[0]->views());
}

/** @test */
Expand Down

0 comments on commit 1b5e1ee

Please sign in to comment.