function LazyBuilderPlaceholderTest::assertStringOrder
Asserts the order of an array of strings inside a string.
@todo use a generic assertion once available.
Parameters
array $items: The array of strings.
array $haystack: The string that should contain $items in order.
See also
https://www.drupal.org/project/drupal/issues/2817657
1 call to LazyBuilderPlaceholderTest::assertStringOrder()
- LazyBuilderPlaceholderTest::testNestedLazyBuilderPlaceholders in core/
tests/ Drupal/ KernelTests/ Core/ Render/ LazyBuilderPlaceholderTest.php - Tests Fiber::suspend() during twig rendering via placeholders.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Render/ LazyBuilderPlaceholderTest.php, line 60
Class
- LazyBuilderPlaceholderTest
- Tests Fiber suspension within Twig templates during placeholder rendering.
Namespace
Drupal\KernelTests\Core\RenderCode
protected function assertStringOrder(array $items, string $haystack) : void {
$strings = [];
foreach ($items as $item) {
if (($pos = strpos($haystack, $item)) === FALSE) {
$this->fail("Cannot find '{$item}' in the page");
}
$strings[$pos] = $item;
}
ksort($strings);
$ordered = implode(', ', array_map(function ($item) {
return "'{$item}'";
}, $items));
$this->assertSame($items, array_values($strings), "Found strings, ordered as: {$ordered}.");
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.