You are here

public function LayoutBuilderMigrationTest::testMigrateEntityWithInvalidLayout in Panelizer 8.5

Tests migrating an entity with an invalid layout plugin ID.

File

tests/src/Functional/LayoutBuilderMigrationTest.php, line 33

Class

LayoutBuilderMigrationTest
@coversDefaultClass \Drupal\panelizer\LayoutBuilderMigration

Namespace

Drupal\Tests\panelizer\Functional

Code

public function testMigrateEntityWithInvalidLayout() {
  $this
    ->drupalCreateContentType([
    'type' => 'page',
  ]);

  /** @var \Drupal\panelizer\PanelizerInterface $panelizer */
  $panelizer = $this->container
    ->get('panelizer');
  $panelizer
    ->setPanelizerSettings('node', 'page', 'full', [
    'enable' => TRUE,
    'allow' => FALSE,
    'custom' => TRUE,
    'default' => 'default',
  ]);
  $node = $this
    ->drupalCreateNode([
    'type' => 'page',
  ]);
  $display = $panelizer
    ->getPanelsDisplay($node, 'full');
  $panelizer
    ->setPanelsDisplay($node, 'full', NULL, $display);
  $layout_manager = $this->container
    ->get('plugin.manager.core.layout');
  $this->container
    ->set('plugin.manager.core.layout', new class($this->container
    ->get('container.namespaces'), $this->container
    ->get('cache.backend.memory')
    ->get('foo'), $this->container
    ->get('module_handler'), $this->container
    ->get('theme_handler')) extends LayoutPluginManager {

    /**
     * {@inheritdoc}
     */
    public function getDefinition($plugin_id, $exception_on_invalid = TRUE) {
      if ($plugin_id === 'onecol') {
        $plugin_id = 'layout_onecol';
      }
      return parent::getDefinition($plugin_id, $exception_on_invalid);
    }

  });
  $configuration = $node->panelizer->panels_display;
  $configuration['layout'] = 'onecol';
  $node->panelizer->panels_display = $configuration;
  $node
    ->save();
  $this->container
    ->set('plugin.manager.core.layout', $layout_manager);
  $this->container
    ->get('entity_display.repository')
    ->getViewDisplay('node', 'page', 'full')
    ->enableLayoutBuilder()
    ->setOverridable()
    ->save();
  LayoutBuilderMigration::processEntity('node', $node
    ->getRevisionId());
}