You are here

public function ChainedPlaceholderStrategyTest::providerProcessPlaceholders 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::providerProcessPlaceholders()

Provides a list of render strategies, placeholders and results.

Return value

array

File

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

Class

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

Namespace

Drupal\Tests\Core\Render\Placeholder

Code

public function providerProcessPlaceholders() {
  $data = [];

  // Empty placeholders.
  $data['empty placeholders'] = [
    [],
    [],
    [],
  ];

  // Placeholder removing strategy.
  $placeholders = [
    'remove-me' => [
      '#markup' => 'I-am-a-llama-that-will-be-removed-sad-face.',
    ],
  ];
  $prophecy = $this
    ->prophesize('\\Drupal\\Core\\Render\\Placeholder\\PlaceholderStrategyInterface');
  $prophecy
    ->processPlaceholders($placeholders)
    ->willReturn([]);
  $dev_null_strategy = $prophecy
    ->reveal();
  $data['placeholder removing strategy'] = [
    [
      $dev_null_strategy,
    ],
    $placeholders,
    [],
  ];

  // Fake Single Flush strategy.
  $placeholders = [
    '67890' => [
      '#markup' => 'special-placeholder',
    ],
  ];
  $prophecy = $this
    ->prophesize('\\Drupal\\Core\\Render\\Placeholder\\PlaceholderStrategyInterface');
  $prophecy
    ->processPlaceholders($placeholders)
    ->willReturn($placeholders);
  $single_flush_strategy = $prophecy
    ->reveal();
  $data['fake single flush strategy'] = [
    [
      $single_flush_strategy,
    ],
    $placeholders,
    $placeholders,
  ];

  // Fake ESI strategy.
  $placeholders = [
    '12345' => [
      '#markup' => 'special-placeholder-for-esi',
    ],
  ];
  $result = [
    '12345' => [
      '#markup' => '<esi:include src="/fragment/12345" />',
    ],
  ];
  $prophecy = $this
    ->prophesize('\\Drupal\\Core\\Render\\Placeholder\\PlaceholderStrategyInterface');
  $prophecy
    ->processPlaceholders($placeholders)
    ->willReturn($result);
  $esi_strategy = $prophecy
    ->reveal();
  $data['fake esi strategy'] = [
    [
      $esi_strategy,
    ],
    $placeholders,
    $result,
  ];

  // ESI + SingleFlush strategy (ESI replaces all).
  $prophecy = $this
    ->prophesize('\\Drupal\\Core\\Render\\Placeholder\\PlaceholderStrategyInterface');
  $prophecy
    ->processPlaceholders($placeholders)
    ->willReturn($result);
  $esi_strategy = $prophecy
    ->reveal();
  $prophecy = $this
    ->prophesize('\\Drupal\\Core\\Render\\Placeholder\\PlaceholderStrategyInterface');
  $prophecy
    ->processPlaceholders($placeholders)
    ->shouldNotBeCalled();
  $prophecy
    ->processPlaceholders($result)
    ->shouldNotBeCalled();
  $prophecy
    ->processPlaceholders([])
    ->shouldNotBeCalled();
  $single_flush_strategy = $prophecy
    ->reveal();
  $data['fake esi and single_flush strategy - esi replaces all'] = [
    [
      $esi_strategy,
      $single_flush_strategy,
    ],
    $placeholders,
    $result,
  ];

  // ESI + SingleFlush strategy (mixed).
  $placeholders = [
    '12345' => [
      '#markup' => 'special-placeholder-for-ESI',
    ],
    '67890' => [
      '#markup' => 'special-placeholder',
    ],
    'foo' => [
      '#markup' => 'bar',
    ],
  ];
  $esi_result = [
    '12345' => [
      '#markup' => '<esi:include src="/fragment/12345" />',
    ],
  ];
  $normal_result = [
    '67890' => [
      '#markup' => 'special-placeholder',
    ],
    'foo' => [
      '#markup' => 'bar',
    ],
  ];
  $result = $esi_result + $normal_result;
  $prophecy = $this
    ->prophesize('\\Drupal\\Core\\Render\\Placeholder\\PlaceholderStrategyInterface');
  $prophecy
    ->processPlaceholders($placeholders)
    ->willReturn($esi_result);
  $esi_strategy = $prophecy
    ->reveal();
  $prophecy = $this
    ->prophesize('\\Drupal\\Core\\Render\\Placeholder\\PlaceholderStrategyInterface');
  $prophecy
    ->processPlaceholders($normal_result)
    ->willReturn($normal_result);
  $single_flush_strategy = $prophecy
    ->reveal();
  $data['fake esi and single_flush strategy - mixed'] = [
    [
      $esi_strategy,
      $single_flush_strategy,
    ],
    $placeholders,
    $result,
  ];
  return $data;
}