You are here

public function PanelizerUserFunctionalTest::testMigrationToLayoutBuilder in Panelizer 8.5

Tests migration of the entity view display data to Layout Builder.

File

tests/src/Functional/PanelizerUserFunctionalTest.php, line 157

Class

PanelizerUserFunctionalTest
Basic functional tests of using Panelizer with user entities.

Namespace

Drupal\Tests\panelizer\Functional

Code

public function testMigrationToLayoutBuilder() {
  $page = $this
    ->getSession()
    ->getPage();
  $assert_session = $this
    ->assertSession();

  // Create a custom block to add to the custom layout.
  $block_content = BlockContent::create([
    'type' => 'test',
    'info' => $this
      ->randomString(),
    'body' => $this
      ->getRandomGenerator()
      ->sentences(8),
  ]);
  $block_content
    ->save();

  /** @var \Drupal\panelizer\PanelizerInterface $panelizer */
  $panelizer = $this->container
    ->get('panelizer');

  // Create a user account that explicitly uses the default layout, to ensure
  // it does not break the migration.
  $default_layout_account = $this
    ->drupalCreateUser();
  $panelizer
    ->setPanelsDisplay($default_layout_account, 'full', '__bundle_default__');

  // Create a user account with a custom layout.
  $account = $this
    ->drupalCreateUser();

  /** @var \Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant $panels_display */
  $panels_display = $panelizer
    ->getPanelsDisplay($account, 'full');
  $this
    ->assertInstanceOf(PanelsDisplayVariant::class, $panels_display);

  // Add the block to the custom layout.
  $panels_display
    ->addBlock([
    'id' => 'block_content:' . $block_content
      ->uuid(),
    'label' => $block_content
      ->label(),
    'region' => 'content',
    'weight' => 1,
  ]);
  $panelizer
    ->setPanelsDisplay($account, 'full', NULL, $panels_display);
  $this
    ->drupalGet($default_layout_account
    ->toUrl());
  $assert_session
    ->statusCodeEquals(200);
  $assert_session
    ->pageTextContains('The context value is 42, brought to you by the letter Juliet.');
  $this
    ->drupalGet($account
    ->toUrl());
  $assert_session
    ->statusCodeEquals(200);
  $assert_session
    ->pageTextContains($block_content
    ->label());
  $assert_session
    ->pageTextContains($block_content->body->value);
  $this->container
    ->get('module_installer')
    ->install([
    'layout_builder',
  ]);
  $this
    ->drupalGet('/admin/config/people/accounts/display');
  $page
    ->checkField('User account');
  $page
    ->clickLink('User account');
  $assert_session
    ->checkboxChecked('Panelize this view mode');
  $assert_session
    ->checkboxChecked('Allow users to select which display to use');
  $assert_session
    ->checkboxChecked('Allow each user to have its display customized');
  $assert_session
    ->checkboxNotChecked('Use Layout Builder');
  $assert_session
    ->checkboxNotChecked('Allow each user to have its layout customized.');
  $page
    ->pressButton('Migrate to Layout Builder');
  $assert_session
    ->statusCodeEquals(200);
  $assert_session
    ->pageTextContains('Hold your horses, cowpoke.');
  $page
    ->pressButton('I understand the risks and have backed up my database. Proceed!');
  $this
    ->checkForMetaRefresh();
  $assert_session
    ->checkboxChecked('Use Layout Builder');
  $assert_session
    ->checkboxChecked('Allow content editors to use stored layouts');
  $assert_session
    ->checkboxChecked('Allow each user to have its layout customized.');
  $assert_session
    ->fieldNotExists('Panelize this view mode');
  $assert_session
    ->fieldNotExists('Allow users to select which display to use');
  $assert_session
    ->fieldNotExists('Allow each user to have its display customized');
  $page
    ->clickLink('Manage layout');
  $page
    ->pressButton('Save layout');
  $this
    ->drupalGet($default_layout_account
    ->toUrl());
  $assert_session
    ->statusCodeEquals(200);
  $assert_session
    ->pageTextContains('The context value is 42, brought to you by the letter Juliet.');
  $this
    ->drupalGet($account
    ->toUrl());
  $assert_session
    ->statusCodeEquals(200);
  $assert_session
    ->pageTextContains($block_content
    ->label());
  $assert_session
    ->pageTextContains($block_content->body->value);
  $assert_session
    ->pageTextContains('The context value is 42, brought to you by the letter Juliet.');
  $account = $this
    ->createUser();
  $this
    ->drupalGet($account
    ->toUrl());
  $assert_session
    ->statusCodeEquals(200);
  $assert_session
    ->pageTextContains($account
    ->getDisplayName());
  $assert_session
    ->pageTextNotContains('Powered by Drupal');
  $assert_session
    ->pageTextNotContains($this->blockContent
    ->label());
  $assert_session
    ->pageTextNotContains($this->blockContent->body->value);
  $assert_session
    ->pageTextContains('The context value is 42, brought to you by the letter Juliet.');
  $this
    ->drupalGet($account
    ->toUrl('edit-form'));
  $assert_session
    ->statusCodeEquals(200);
  $page
    ->selectFieldOption('Layout', 'Alpha');
  $page
    ->pressButton('Save');
  $assert_session
    ->statusCodeEquals(200);
  $this
    ->drupalGet($account
    ->toUrl());
  $assert_session
    ->statusCodeEquals(200);
  $assert_session
    ->pageTextContains($account
    ->getDisplayName());
  $assert_session
    ->pageTextContains('Powered by Drupal');
  $assert_session
    ->pageTextContains($this->blockContent
    ->label());
  $assert_session
    ->pageTextContains($this->blockContent->body->value);
  $assert_session
    ->pageTextContains('The context value is 99, brought to you by the letter X-ray.');
}