Chris@0: drupalCreateUser([ Chris@0: 'access content', Chris@0: ]); Chris@0: $this->drupalLogin($end_user); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests the render order of the blocks. Chris@0: */ Chris@0: public function testBlockRenderOrder() { Chris@0: // Enable test blocks and place them in the same region. Chris@0: $region = 'header'; Chris@0: $test_blocks = [ Chris@0: 'stark_powered' => [ Chris@0: 'weight' => '-3', Chris@0: 'id' => 'stark_powered', Chris@0: 'label' => 'Test block A', Chris@0: ], Chris@0: 'stark_by' => [ Chris@0: 'weight' => '3', Chris@0: 'id' => 'stark_by', Chris@0: 'label' => 'Test block C', Chris@0: ], Chris@0: 'stark_drupal' => [ Chris@0: 'weight' => '3', Chris@0: 'id' => 'stark_drupal', Chris@0: 'label' => 'Test block B', Chris@0: ], Chris@0: ]; Chris@0: Chris@0: // Place the test blocks. Chris@0: foreach ($test_blocks as $test_block) { Chris@0: $this->drupalPlaceBlock('system_powered_by_block', [ Chris@0: 'label' => $test_block['label'], Chris@0: 'region' => $region, Chris@0: 'weight' => $test_block['weight'], Chris@0: 'id' => $test_block['id'], Chris@0: ]); Chris@0: } Chris@0: Chris@0: $this->drupalGet(''); Chris@17: $test_content = $this->getSession()->getPage()->getContent(); Chris@0: Chris@0: $controller = $this->container->get('entity_type.manager')->getStorage('block'); Chris@0: foreach ($controller->loadMultiple() as $return_block) { Chris@0: $id = $return_block->id(); Chris@0: if ($return_block_weight = $return_block->getWeight()) { Chris@0: $this->assertTrue($test_blocks[$id]['weight'] == $return_block_weight, 'Block weight is set as "' . $return_block_weight . '" for ' . $id . ' block.'); Chris@0: $position[$id] = strpos($test_content, Html::getClass('block-' . $test_blocks[$id]['id'])); Chris@0: } Chris@0: } Chris@0: $this->assertTrue($position['stark_powered'] < $position['stark_by'], 'Blocks with different weight are rendered in the correct order.'); Chris@0: $this->assertTrue($position['stark_drupal'] < $position['stark_by'], 'Blocks with identical weight are rendered in alphabetical order.'); Chris@0: } Chris@0: Chris@0: }