You are here

public function ChainedPlaceholderStrategyTest::testProcessPlaceholdersWithRoguePlaceholderStrategy in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Render/Placeholder/ChainedPlaceholderStrategyTest.php \Drupal\Tests\Core\Render\Placeholder\ChainedPlaceholderStrategyTest::testProcessPlaceholdersWithRoguePlaceholderStrategy()

@covers ::processPlaceholders

File

core/tests/Drupal/Tests/Core/Render/Placeholder/ChainedPlaceholderStrategyTest.php, line 139

Class

ChainedPlaceholderStrategyTest
@coversDefaultClass \Drupal\Core\Render\Placeholder\ChainedPlaceholderStrategy @group Render

Namespace

Drupal\Tests\Core\Render\Placeholder

Code

public function testProcessPlaceholdersWithRoguePlaceholderStrategy() {

  // Placeholders but no strategies defined.
  $placeholders = [
    'assert-me' => [
      '#markup' => 'llama',
    ],
  ];
  $result = [
    'assert-me' => [
      '#markup' => 'llama',
    ],
    'new-placeholder' => [
      '#markup' => 'rogue llama',
    ],
  ];
  $prophecy = $this
    ->prophesize('\\Drupal\\Core\\Render\\Placeholder\\PlaceholderStrategyInterface');
  $prophecy
    ->processPlaceholders($placeholders)
    ->willReturn($result);
  $rogue_strategy = $prophecy
    ->reveal();
  $chained_placeholder_strategy = new ChainedPlaceholderStrategy();
  $chained_placeholder_strategy
    ->addPlaceholderStrategy($rogue_strategy);
  $this
    ->expectException(\AssertionError::class);
  $this
    ->expectExceptionMessage('Processed placeholders must be a subset of all placeholders.');
  $chained_placeholder_strategy
    ->processPlaceholders($placeholders);
}