Skip to content

Commit

Permalink
Fixup tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pookmish committed Mar 9, 2024
1 parent 7558092 commit 296da4a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ public function buildBehaviorForm(ParagraphInterface $paragraph, array &$form, F
'#type' => 'radios',
'#title' => $this->t('Headline Behavior'),
'#options' => [
self::SHOW_HEADING => $this->t('<strong>Display heading</strong>: This displays the paragraph headline as an H2. You’ll usually want to choose this option. '),
self::HIDE_HEADING => $this->t('<strong>Visually hide heading</strong>: For improved accessibility, this keeps the headline in the page structure as an H2, but you won’t see it. '),
self::REMOVE_HEADING => $this->t('<strong>Remove heading</strong>: This completely removes the headline from the page and assumes you have placed an H2 on the page above this paragraph.'),
self::SHOW_HEADING => '<strong>' . $this->t('Display heading') . '</strong>: ' . $this->t('This displays the paragraph headline as an H2. You’ll usually want to choose this option. '),
self::HIDE_HEADING => '<strong>' . $this->t('<strong>Visually hide heading') . '</strong>: ' . $this->t('For improved accessibility, this keeps the headline in the page structure as an H2, but you won’t see it. '),
self::REMOVE_HEADING => '<strong>' . $this->t('<strong>Remove heading') . '</strong>: ' . $this->t('This completely removes the headline from the page and assumes you have placed an H2 on the page above this paragraph.'),
],
'#default_value' => $paragraph->getBehaviorSetting('list_paragraph', 'heading_behavior', self::SHOW_HEADING),
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static function isApplicable(ParagraphsTypeInterface $paragraphs_type) {
* {@inheritDoc}
*/
public function defaultConfiguration() {
return ['heading_behavior' => 'show',];
return ['heading_behavior' => 'show'];
}

/**
Expand All @@ -49,9 +49,9 @@ public function buildBehaviorForm(ParagraphInterface $paragraph, array &$form, F
'#type' => 'radios',
'#title' => $this->t('Headline Behavior'),
'#options' => [
self::SHOW_HEADING => $this->t('<strong>Display heading</strong>: This displays the paragraph headline as an H2. You’ll usually want to choose this option. '),
self::HIDE_HEADING => $this->t('<strong>Visually hide heading</strong>: For improved accessibility, this keeps the headline in the page structure as an H2, but you won’t see it. '),
self::REMOVE_HEADING => $this->t('<strong>Remove heading</strong>: This completely removes the headline from the page and assumes you have placed an H2 on the page above this paragraph.'),
self::SHOW_HEADING => '<strong>' . $this->t('Display heading') . '</strong>: ' . $this->t('This displays the paragraph headline as an H2. You’ll usually want to choose this option. '),
self::HIDE_HEADING => '<strong>' . $this->t('<strong>Visually hide heading') . '</strong>: ' . $this->t('For improved accessibility, this keeps the headline in the page structure as an H2, but you won’t see it. '),
self::REMOVE_HEADING => '<strong>' . $this->t('<strong>Remove heading') . '</strong>: ' . $this->t('This completely removes the headline from the page and assumes you have placed an H2 on the page above this paragraph.'),
],
'#default_value' => $paragraph->getBehaviorSetting('stanford_teaser', 'heading_behavior', self::SHOW_HEADING),
];
Expand All @@ -64,8 +64,12 @@ public function buildBehaviorForm(ParagraphInterface $paragraph, array &$form, F
public function view(array &$build, ParagraphInterface $paragraph, EntityViewDisplayInterface $display, $view_mode) {
$heading_behavior = $paragraph->getBehaviorSetting('stanford_teaser', 'heading_behavior', self::SHOW_HEADING);

// Heading is populated or to be removed, change the display mode of the entities.
if (isset($build['su_entity_headline'][0]) || $heading_behavior == self::REMOVE_HEADING) {
// Heading is populated or configured to be removed, change the display mode
// of the entities.
if (
isset($build['su_entity_item']) &&
(isset($build['su_entity_headline'][0]) || $heading_behavior == self::REMOVE_HEADING)
) {
foreach (Element::children($build['su_entity_item']) as $delta) {
$build['su_entity_item'][$delta]['#view_mode'] = 'stanford_h3_card';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,27 +54,29 @@ public function testApplication() {
public function testForm() {
$plugin = TeaserParagraphBehavior::create(\Drupal::getContainer(), [], '', []);
$paragraph = $this->createMock(ParagraphInterface::class);
$paragraph->method('getBehaviorSetting')->willReturn(FALSE);
$paragraph->method('getBehaviorSetting')->willReturn('show');
$form = [];
$form_state = new FormState();
$form = $plugin->buildBehaviorForm($paragraph, $form, $form_state);
$this->assertArrayHasKey('hide_heading', $form);
$this->assertFalse($form['hide_heading']['#default_value']);
$this->assertArrayHasKey('heading_behavior', $form);
$this->assertEquals('show', $form['heading_behavior']['#default_value']);
}

public function testView() {
$plugin = TeaserParagraphBehavior::create(\Drupal::getContainer(), [], '', []);
$build = ['su_entity_headline' => ['foo']];

$paragraph = $this->createMock(Paragraph::class);
$paragraph->method('getBehaviorSetting')->willReturn(TRUE);
$paragraph->method('getBehaviorSetting')->willReturn('hide');
$display = $this->createMock(EntityViewDisplayInterface::class);
$plugin->view($build, $paragraph, $display, 'foo');
// No changes with no items.
$this->assertEquals(['su_entity_headline' => ['foo']], $build);

$build['su_entity_item'][0] = [
'#view_mode' => 'foobar',
'#cache' => ['keys' => ['foobar']]
$build = [
'su_entity_headline' => ['foo'],
'su_entity_item' => [
[
'#view_mode' => 'foobar',
'#cache' => ['keys' => ['foobar']],
],
],
];
$plugin->view($build, $paragraph, $display, 'foo');
$this->assertContains('visually-hidden', $build['su_entity_headline']['#attributes']['class']);
Expand Down

0 comments on commit 296da4a

Please sign in to comment.