X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fblock%2Ftests%2Fsrc%2FFunctional%2FBlockRenderOrderTest.php;fp=web%2Fcore%2Fmodules%2Fblock%2Ftests%2Fsrc%2FFunctional%2FBlockRenderOrderTest.php;h=2fd1ab8925d76e8f0ad4378fc2f612f346a50b9b;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hp=0000000000000000000000000000000000000000;hpb=aea91e65e895364e460983b890e295aa5d5540a5;p=yaffs-website diff --git a/web/core/modules/block/tests/src/Functional/BlockRenderOrderTest.php b/web/core/modules/block/tests/src/Functional/BlockRenderOrderTest.php new file mode 100644 index 000000000..2fd1ab892 --- /dev/null +++ b/web/core/modules/block/tests/src/Functional/BlockRenderOrderTest.php @@ -0,0 +1,80 @@ +drupalCreateUser([ + 'access content', + ]); + $this->drupalLogin($end_user); + } + + /** + * Tests the render order of the blocks. + */ + public function testBlockRenderOrder() { + // Enable test blocks and place them in the same region. + $region = 'header'; + $test_blocks = [ + 'stark_powered' => [ + 'weight' => '-3', + 'id' => 'stark_powered', + 'label' => 'Test block A', + ], + 'stark_by' => [ + 'weight' => '3', + 'id' => 'stark_by', + 'label' => 'Test block C', + ], + 'stark_drupal' => [ + 'weight' => '3', + 'id' => 'stark_drupal', + 'label' => 'Test block B', + ], + ]; + + // Place the test blocks. + foreach ($test_blocks as $test_block) { + $this->drupalPlaceBlock('system_powered_by_block', [ + 'label' => $test_block['label'], + 'region' => $region, + 'weight' => $test_block['weight'], + 'id' => $test_block['id'], + ]); + } + + $this->drupalGet(''); + $test_content = $this->getRawContent(''); + + $controller = $this->container->get('entity_type.manager')->getStorage('block'); + foreach ($controller->loadMultiple() as $return_block) { + $id = $return_block->id(); + if ($return_block_weight = $return_block->getWeight()) { + $this->assertTrue($test_blocks[$id]['weight'] == $return_block_weight, 'Block weight is set as "' . $return_block_weight . '" for ' . $id . ' block.'); + $position[$id] = strpos($test_content, Html::getClass('block-' . $test_blocks[$id]['id'])); + } + } + $this->assertTrue($position['stark_powered'] < $position['stark_by'], 'Blocks with different weight are rendered in the correct order.'); + $this->assertTrue($position['stark_drupal'] < $position['stark_by'], 'Blocks with identical weight are rendered in alphabetical order.'); + } + +}