public function BricksTest::testBricks in Bricks 2.x
Same name in this branch
- 2.x tests/src/Functional/BricksTest.php \Drupal\Tests\bricks\Functional\BricksTest::testBricks()
- 2.x tests/src/Kernel/BricksTest.php \Drupal\Tests\bricks\Kernel\BricksTest::testBricks()
Same name and namespace in other branches
- 8 tests/src/Kernel/BricksTest.php \Drupal\Tests\bricks\Kernel\BricksTest::testBricks()
@dataProvider getTrees
File
- tests/
src/ Kernel/ BricksTest.php, line 48
Class
- BricksTest
- Class BricksTest
Namespace
Drupal\Tests\bricks\KernelCode
public function testBricks(array $tree) {
$paragraphs = [];
$n = max(array_keys($tree));
for ($i = 1; $i <= $n; $i++) {
$string = "testplain {$i}";
$paragraph = Paragraph::create([
'type' => 'test',
'testplain' => $string,
'test' => array_intersect_key($paragraphs, $tree[$i] ?? []),
'id' => $i,
]);
$paragraph
->enforceIsNew();
$paragraph
->save();
$paragraphs[$i] = $paragraph;
}
$node = Node::create([
'type' => 'test',
'title' => 'test',
'test' => array_intersect_key($paragraphs, $tree),
]);
$node
->save();
$build = \Drupal::entityTypeManager()
->getViewBuilder('node')
->view($node);
$contents = (string) \Drupal::service('renderer')
->renderPlain($build);
$crawler = new Crawler($contents);
$bricks = $crawler
->filter('.brick--id--1')
->parents()
->children();
$total = $this
->recurseBricks($tree, $bricks);
$this
->assertSame($n, $total);
}