Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/EventSubscriber/PageHeaderSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function setPageHeader(PageHeaderDisplayEvent $event) {
if ($overview instanceof NodeInterface) {
$overview = $this->entityRepository->getTranslationFromContext($overview);
$event->setTitle($overview->getTitle());
if ($overview->get('body')->summary) {
if ($overview->hasField('body') && $overview->get('body')->summary) {
$event->setLede([
'#type' => 'html_tag',
'#tag' => 'p',
Expand Down
22 changes: 22 additions & 0 deletions tests/src/Functional/PageHeaderBlockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ public function testGuidePageHeaderBlock() {
'title' => $overview_title,
'type' => 'localgov_guides_overview',
'status' => NodeInterface::PUBLISHED,
'body' => [
'summary' => 'Lede to show',
'value' => '',
],
]);

$page_title = 'Guide page - ' . $this->randomMachineName(8);
Expand All @@ -84,6 +88,7 @@ public function testGuidePageHeaderBlock() {
$query = $this->xpath('.//h1[contains(concat(" ",normalize-space(@class)," ")," header ")]');
$found_title = $query[0]->getText();
$this->assertEquals($found_title, $overview_title);
$this->assertSession()->responseContains('Lede to show');

$this->drupalGet($page->toUrl()->toString());
$query = $this->xpath('.//h1[contains(concat(" ",normalize-space(@class)," ")," header ")]');
Expand All @@ -106,6 +111,23 @@ public function testGuidePageHeaderBlock() {
$query = $this->xpath('.//h1[contains(concat(" ",normalize-space(@class)," ")," header ")]');
$found_title = $query[0]->getText();
$this->assertEquals($found_title, $new_overview_title);

// Check lede.
$this->drupalGet($page->toUrl()->toString());
$this->assertSession()->responseContains('Lede to show');
// Remove body field, check title and no lede.
$field_definitions = \Drupal::service('entity_field.manager')->getFieldDefinitions('node', 'localgov_guides_overview');
$field_definitions['body']->delete();
$this->drupalGet($overview->toUrl()->toString());
$this->assertSession()->responseNotContains('Lede to show');
// @todo remove this.
// Issue https://github.com/localgovdrupal/localgov_core/issues/290
drupal_flush_all_caches();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test adds checks lede shows in the first place and confirms it works when the field is removed.

However it needs the cache clear, so I'll create a follow-up issue about the caching of the block (guessing it wants cache metadata, rather than just cache tags).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$this->drupalGet($page->toUrl()->toString());
$this->assertSession()->responseNotContains('Lede to show');
$query = $this->xpath('.//h1[contains(concat(" ",normalize-space(@class)," ")," header ")]');
$found_title = $query[0]->getText();
$this->assertEquals($found_title, $new_overview_title);
}

}
Loading