placeBlock example


  protected $helpBlock;

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();
    $this->helpBlock = $this->placeBlock('help_block');
  }

  /** * Logs in users, tests help pages. */
  public function testHelp() {
    $this->drupalGet('help_page_test/has_help');
    $this->assertSession()->pageTextContains('I have help!');
    $this->assertSession()->pageTextContains($this->helpBlock->label());

    $this->drupalGet('help_page_test/no_help');
    
class DisplayPathTest extends UITestBase {

  use AssertPageCacheContextsAndTagsTrait;
  use SchemaCheckTestTrait;

  /** * {@inheritdoc} */
  protected function setUp($import_test_views = TRUE, $modules = ['views_test_config']): void {
    parent::setUp($import_test_views$modules);

    $this->placeBlock('page_title_block');
  }

  /** * {@inheritdoc} */
  protected $defaultTheme = 'stark';

  /** * Views used by this test. * * @var array */
/** * Tests blocks with overridden related configuration removed when overridden. */
  public function testOverriddenConfigurationRemoved() {
    $web_assert = $this->assertSession();
    $page = $this->getSession()->getPage();
    $this->grantPermissions(Role::load(Role::AUTHENTICATED_ID)['administer site configuration', 'administer menu']);

    // Confirm the branding block does include 'site_information' section when     // the site name is not overridden.     $branding_block = $this->placeBlock('system_branding_block');
    $this->drupalGet('user');
    $this->enableEditMode();
    $this->openBlockForm($this->getBlockSelector($branding_block));
    $web_assert->fieldExists('settings[site_information][site_name]');
    // Confirm the branding block does not include 'site_information' section     // when the site name is overridden.     $this->container->get('state')->set('settings_tray_override_test.site_name', TRUE);
    $this->drupalGet('user');
    $this->openBlockForm($this->getBlockSelector($branding_block));
    $web_assert->fieldNotExists('settings[site_information][site_name]');
    $page->pressButton('Save Site branding');
    

  protected function setUpFixtures() {
    // Install the themes used for this test.     $this->container->get('theme_installer')->install(['olivero']);
    $this->container->get('config.factory')->getEditable('system.theme')->set('default', 'olivero')->save();

    $this->installEntitySchema('user');
    $this->installEntitySchema('entity_test');
    $this->installConfig(['entity_test']);

    $this->placeBlock('system_main_block', ['id' => 'test_block']);

    parent::setUpFixtures();
  }

  /** * Tests views data for entity area handlers. */
  public function testEntityAreaData() {
    $data = $this->container->get('views.views_data')->get('views');
    $entity_types = $this->container->get('entity_type.manager')->getDefinitions();

    
/** * Tests unpublishing of block_content entities. */
  public function testViewShowsCorrectStates() {
    $block_content = BlockContent::create([
      'info' => 'Test block',
      'type' => 'basic',
    ]);
    $block_content->save();

    $block = $this->placeBlock('block_content:' . $block_content->uuid());

    $this->drupalGet('<front>');
    $page = $this->getSession()->getPage();
    $this->assertTrue($page->has('css', '#block-' . $block->id()));

    $block_content->setUnpublished();
    $block_content->save();

    $this->drupalGet('<front>');
    $page = $this->getSession()->getPage();
    $this->assertFalse($page->has('css', '#block-' . $block->id()));
  }

  protected $defaultTheme = 'stark';

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    $this->drupalLogin($this->createUser(['access contextual links']));
    $this->placeBlock('system_branding_block', [
      'id' => 'branding',
    ]);
  }

  /** * Tests the visibility of contextual links. */
  public function testContextualLinksVisibility() {
    $this->drupalGet('user');
    $contextualLinks = $this->assertSession()->waitForElement('css', '.contextual button');
    $this->assertEmpty($contextualLinks);

    

  public static $testViews = ['test_view_empty', 'test_view_broken', 'node', 'test_node_view'];

  /** * {@inheritdoc} */
  protected function setUp($import_test_views = TRUE, $modules = ['views_test_config']): void {
    parent::setUp($import_test_views$modules);

    $this->placeBlock('page_title_block');
    ViewTestData::createTestViews(static::class['node_test_views']);
  }

  /** * Overrides \Drupal\views\Tests\ViewTestBase::schemaDefinition(). * * Adds a uid column to test the relationships. * * @internal */
  protected function schemaDefinition() {
    


  /** * Tests access to block forms with related configuration is correct. */
  public function testBlockConfigAccess() {
    $page = $this->getSession()->getPage();
    $web_assert = $this->assertSession();

    // Confirm that System Branding block does not expose Site Name field     // without permission.     $block = $this->placeBlock('system_branding_block');
    $this->drupalGet('user');
    $this->enableEditMode();
    $this->openBlockForm($this->getBlockSelector($block));
    // The site name field should not appear because the user doesn't have     // permission.     $web_assert->fieldNotExists('settings[site_information][site_name]');
    $page->pressButton('Save Site branding');
    $this->waitForOffCanvasToClose();
    $this->assertElementVisibleAfterWait('css', 'div:contains(The block configuration has been saved)');
    $web_assert->assertWaitOnAjaxRequest();
    // Confirm we did not save changes to the configuration.

  protected $blockId;

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    $this->blockId = $this->defaultTheme . '_powered';
    $this->placeBlock('system_powered_by_block', [
      'id' => $this->blockId,
      'region' => 'content',
    ]);
  }

  /** * Test to ensure that remove contextual link is present in the block. */
  public function testBlockContextualRemoveLinks() {
    // Ensure that contextual filter links are visible on the page.     $this->drupalLogin($this->rootUser);
    
if ($permissions) {
      $this->grantPermissions(Role::load(Role::AUTHENTICATED_ID)$permissions);
    }
    if ($new_page_text) {
      // Some asserts can be based on this value, so it should not be the same       // for different blocks, because it can be saved in the site config.       $new_page_text = $new_page_text . ' ' . $theme . ' ' . $block_plugin;
    }
    $web_assert = $this->assertSession();
    $page = $this->getSession()->getPage();
    $this->enableTheme($theme);
    $block = $this->placeBlock($block_plugin);
    $block_selector = $this->getBlockSelector($block);
    $block_id = $block->id();
    $this->drupalGet('user');

    $link = $web_assert->waitForElement('css', "$block_selector .contextual-links li a");
    $this->assertEquals('Quick edit', $link->getHtml(), "'Quick edit' is the first contextual link for the block.");
    $destination = (string) $this->loggedInUser->toUrl()->toString();
    $this->assertStringContainsString("/admin/structure/block/manage/$block_id/settings-tray?destination=$destination", $link->getAttribute('href'));

    if (isset($toolbar_item)) {
      // Check that you can open a toolbar tray and it will be closed after
parent::setUp();

    // These tests rely on some markup from the 'stark' theme and we test theme     // provided help topics.     \Drupal::service('theme_installer')->install(['help_topics_test_theme']);

    // Place various blocks.     $settings = [
      'theme' => 'stark',
      'region' => 'help',
    ];
    $this->placeBlock('help_block', $settings);
    $this->placeBlock('local_tasks_block', $settings);
    $this->placeBlock('local_actions_block', $settings);
    $this->placeBlock('page_title_block', $settings);
    $this->placeBlock('system_breadcrumb_block', $settings);

    // Create users.     $this->adminUser = $this->createUser([
      'access administration pages',
      'view the administration theme',
      'administer permissions',
      'administer site configuration',
      
/** * {@inheritdoc} */
  protected $defaultTheme = 'stark';

  /** * Tests contextual links. */
  public function testBlockContentContextualLinks() {
    $block_content = $this->createBlockContent();

    $block = $this->placeBlock('block_content:' . $block_content->uuid());

    $user = $this->drupalCreateUser([
      'administer blocks',
      'access contextual links',
    ]);
    $this->drupalLogin($user);

    $this->drupalGet('<front>');
    $this->assertSession()->elementAttributeContains('css', 'div[data-contextual-id]', 'data-contextual-id', 'block:block=' . $block->id() . ':langcode=en|block_content:block_content=' . $block_content->id() . ':');
  }

}
return Workspace::load($id);
  }

  /** * Adds the workspace switcher block to the site. * * This is necessary for switchToWorkspace() to function correctly. */
  protected function setupWorkspaceSwitcherBlock() {
    // Add the block to the sidebar.     $this->placeBlock('workspace_switcher', [
      'id' => 'workspaceswitcher',
      'region' => 'sidebar_first',
      'label' => 'Workspace switcher',
    ]);

    // Confirm the block shows on the front page.     $this->drupalGet('<front>');
    $page = $this->getSession()->getPage();

    $this->assertTrue($page->hasContent('Workspace switcher'));
    $this->switcherBlockConfigured = TRUE;
  }
$custom_data['configuration']['message'] = 'Granny Smith';
    $this->assertConfigUpdateImport($name$original_data$custom_data);

  }

  /** * Tests updating a block during import. */
  protected function doBlockUpdate() {
    // Create a test block with a known label.     $name = 'block.block.apple';
    $block = $this->placeBlock('system_powered_by_block', [
      'id' => 'apple',
      'label' => 'Red Delicious',
      'theme' => 'olivero',
    ]);

    $this->checkSinglePluginConfigSync($block, 'settings', 'label', 'Red Delicious');

    // Read the existing data, and prepare an altered version in sync.     $custom_data = $original_data = $this->container->get('config.storage')->read($name);
    $custom_data['settings']['label'] = 'Granny Smith';
    $this->assertConfigUpdateImport($name$original_data$custom_data);
  }
'title' => 'test title 2',
      'type' => $node_type->id(),
    ]);
    $node->save();
    $this->nodes[] = $node;
  }

  /** * Tests rendering caching of a views block with arguments. */
  public function testEmptyView() {
    $this->placeBlock('views_block:node_id_argument-block_1', ['region' => 'header']);
    $this->drupalGet('<front>');
    $this->assertEquals([]$this->cssSelect('div.region-header div.views-field-title'));

    $this->drupalGet($this->nodes[0]->toUrl());
    $result = $this->cssSelect('div.region-header div.views-field-title')[0]->getText();
    $this->assertEquals('test title 1', $result);

    $this->drupalGet($this->nodes[1]->toUrl());
    $result = $this->cssSelect('div.region-header div.views-field-title')[0]->getText();
    $this->assertEquals('test title 2', $result);

    
Home | Imprint | This part of the site doesn't use cookies.