import example

<?php
namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo;

return function DContainerConfigurator $c) {
    $c->import('basic.php');

    $s = $c->services()->defaults()
        ->public()
        ->private()
        ->autoconfigure()
        ->autowire()
        ->tag('t', ['a' => 'b'])
        ->bind(Foo::classservice('bar'))
        ->bind('iterable $foo', tagged_iterator('foo'))
        ->public();

    
    // UUIDs match.     $this->configImporter->reset();
    $expected = [
      'node.type.' . $content_type->id() . '::config_test.dynamic.' . $test_entity_id,
    ];
    $renames = $this->configImporter->getUnprocessedConfiguration('rename');
    $this->assertSame($expected$renames);

    // Try to import the configuration. We expect an exception to be thrown     // because the staged entity is of a different type.     try {
      $this->configImporter->import();
      $this->fail('Expected ConfigImporterException thrown when a renamed configuration entity does not match the existing entity type.');
    }
    catch (ConfigImporterException $e) {
      $expected = [
        new FormattableMarkup('Entity type mismatch on rename. @old_type not equal to @new_type for existing configuration @old_name and staged configuration @new_name.', ['@old_type' => 'node_type', '@new_type' => 'config_test', '@old_name' => 'node.type.' . $content_type->id(), '@new_name' => 'config_test.dynamic.' . $test_entity_id]),
      ];
      $this->assertEquals($expected$this->configImporter->getErrors());
    }
  }

  /** * Tests configuration renaming validation for simple configuration. */
$this->configImporter->reset();
    // A node type, a field, an entity view display and an entity form display     // will be recreated.     $creates = $this->configImporter->getUnprocessedConfiguration('create');
    $deletes = $this->configImporter->getUnprocessedConfiguration('delete');
    $this->assertCount(5, $creates, 'There are 5 configuration items to create.');
    $this->assertCount(5, $deletes, 'There are 5 configuration items to delete.');
    $this->assertCount(0, $this->configImporter->getUnprocessedConfiguration('update'), 'There are no configuration items to update.');
    $this->assertSame($createsarray_reverse($deletes), 'Deletes and creates contain the same configuration names in opposite orders due to dependencies.');

    $this->configImporter->import();

    // Verify that there is nothing more to import.     $this->assertFalse($this->configImporter->reset()->hasUnprocessedConfigurationChanges());
    $content_type = NodeType::load($type_name);
    $this->assertEquals('Node type one', $content_type->label());
  }

}
/** * @MigrateDestination( * id = "entity:comment_type" * ) */
class EntityCommentType extends EntityConfigBase {

  /** * {@inheritdoc} */
  public function import(Row $row, array $old_destination_id_values = []) {
    $entity_ids = parent::import($row$old_destination_id_values);
    \Drupal::service('comment.manager')->addBodyField(reset($entity_ids));
    return $entity_ids;
  }

}
/** @var \Drupal\migrate\Plugin\Migration $vocabulary_migration */
    $vocabulary_migration = \Drupal::service('plugin.manager.migration')
      ->createStubMigration($definition);
    $vocabulary_id_map = $vocabulary_migration->getIdMap();

    $this->assertTrue($vocabulary_migration->getDestinationPlugin()
      ->supportsRollback());

    // Import and validate vocabulary config entities were created.     $vocabulary_executable = new MigrateExecutable($vocabulary_migration$this);
    $vocabulary_executable->import();
    foreach ($vocabulary_data_rows as $row) {
      /** @var \Drupal\taxonomy\Entity\Vocabulary $vocabulary */
      $vocabulary = Vocabulary::load($row['id']);
      $this->assertNotEmpty($vocabulary);
      $map_row = $vocabulary_id_map->getRowBySource(['id' => $row['id']]);
      $this->assertNotNull($map_row['destid1']);
    }

    // Second, import translations of the vocabulary name property.     $vocabulary_i18n_data_rows = [
      [
        


    $this->migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition);
  }

  /** * Tests migration interruptions. */
  public function testMessagesNotTeed() {
    // We don't ask for messages to be teed, so don't expect any.     $executable = new MigrateExecutable($this->migration, $this);
    $executable->import();
    $this->assertCount(0, $this->messages);
  }

  /** * Tests migration interruptions. */
  public function testMessagesTeed() {
    // Ask to receive any messages sent to the idmap.     \Drupal::service('event_dispatcher')->addListener(MigrateEvents::IDMAP_MESSAGE,
      [$this, 'mapMessageRecorder']);
    $executable = new MigrateExecutable($this->migration, $this);
    
$this->saveMessage($msg, MigrationInterface::MESSAGE_INFORMATIONAL);
          }
          $save = FALSE;
        }

        if ($save) {
          try {
            $this->getEventDispatcher()
              ->dispatch(new MigratePreRowSaveEvent($this->migration, $this->message, $row), MigrateEvents::PRE_ROW_SAVE);
            $destination_ids = $id_map->lookupDestinationIds($this->sourceIdValues);
            $destination_id_values = $destination_ids ? reset($destination_ids) : [];
            $destination_id_values = $destination->import($row$destination_id_values);
            $this->getEventDispatcher()
              ->dispatch(new MigratePostRowSaveEvent($this->migration, $this->message, $row$destination_id_values), MigrateEvents::POST_ROW_SAVE);
            if ($destination_id_values) {
              // We do not save an idMap entry for config.               if ($destination_id_values !== TRUE) {
                $id_map->saveIdMapping($row$destination_id_values$this->sourceRowStatus, $destination->rollbackAction());
              }
            }
            else {
              $id_map->saveIdMapping($row[], MigrateIdMapInterface::STATUS_FAILED);
              if (!$id_map->messageCount()) {
                
// Brand new row.       ['id' => 4, 'langcode' => 'fr', 'action' => MigrateIdMapInterface::ROLLBACK_DELETE],
    ];
    $rollback_actions = [];

    // Import some rows.     foreach ($destination_rows as $idx => $destination_row) {
      $row = new Row();
      foreach ($destination_row as $key => $value) {
        $row->setDestinationProperty($key$value);
      }
      $this->destination->import($row);

      // Check that the rollback action is correct, and save it.       $this->assertEquals($destination_row['action']$this->destination->rollbackAction());
      $rollback_actions[$idx] = $this->destination->rollbackAction();
    }

    $this->assertTranslations(1, 'en');
    $this->assertTranslations(2, 'fr', ['en']);
    $this->assertTranslations(3, 'en', ['fr']);
    $this->assertTranslations(4, 'fr');

    
'target_bundle' => 'entity_test_mul',
      'default_langcode' => 'site_default',
      'language_alterable' => FALSE,
      'third_party_settings' => [
        'content_translation' => ['enabled' => TRUE],
      ],
    ];
    $sync->write($config_name$data);
    $this->assertTrue($sync->exists($config_name)$config_name . ' found.');

    // Import.     $this->configImporter->reset()->import();

    // Verify the values appeared.     $config = $this->config($config_name);
    $this->assertSame($config_id$config->get('id'));

    // Verify that updates were performed.     $entity_type = $this->container->get('entity_type.manager')->getDefinition($entity_type_id);
    $table = $entity_type->getDataTable();
    $db_schema = $this->container->get('database')->schema();
    $result = $db_schema->fieldExists($table, 'content_translation_source') && $db_schema->fieldExists($table, 'content_translation_outdated');
    $this->assertTrue($result, 'Content translation updates were successfully performed during config import.');
  }
/** * @MigrateDestination( * id = "entity:node_type" * ) */
class EntityNodeType extends EntityConfigBase {

  /** * {@inheritdoc} */
  public function import(Row $row, array $old_destination_id_values = []) {
    $entity_ids = parent::import($row$old_destination_id_values);
    if ($row->getDestinationProperty('create_body')) {
      $node_type = $this->storage->load(reset($entity_ids));
      node_add_body_field($node_type$row->getDestinationProperty('create_body_label'));
    }
    return $entity_ids;
  }

}
$entity = $this->prophesize(ContentEntityInterface::class);
    $entity->isValidationRequired()
      ->shouldBeCalledTimes(1);
    // Assert that save is called.     $entity->save()
      ->shouldBeCalledTimes(1);
    // Set an id for the entity     $entity->id()
      ->willReturn(5);
    $destination->setEntity($entity->reveal());
    // Ensure the id is saved entity id is returned from import.     $this->assertEquals([5]$destination->import(new Row()));
    // Assert that import set the rollback action.     $this->assertEquals(MigrateIdMapInterface::ROLLBACK_DELETE, $destination->rollbackAction());
  }

  /** * Tests row skipping when we can't get an entity to save. * * @covers ::import */
  public function testImportEntityLoadFailure() {
    $bundles = [];
    
final public function getContainerPrefix(): string
    {
        return (new CamelCaseToSnakeCaseNameConverter())->normalize($this->getName());
    }

    public function configureRoutes(RoutingConfigurator $routes, string $environment): void
    {
        $confDir = $this->getPath() . '/Resources/config';

        if (file_exists($confDir)) {
            $routes->import($confDir . '/{routes}/*' . Kernel::CONFIG_EXTS, 'glob');
            $routes->import($confDir . '/{routes}/' . $environment . '/**/*' . Kernel::CONFIG_EXTS, 'glob');
            $routes->import($confDir . '/{routes}' . Kernel::CONFIG_EXTS, 'glob');
            $routes->import($confDir . '/{routes}_' . $environment . Kernel::CONFIG_EXTS, 'glob');
        }
    }

    public function configureRouteOverwrites(RoutingConfigurator $routes, string $environment): void
    {
        $fileSystem = new Filesystem();
        $confDir = $this->getPath() . '/Resources/config';

        

      ],
      'process' => ['value' => 'data'],
      'destination' => ['plugin' => 'dummy'],
    ];

    $migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition);

    $executable = new MigrateExecutable($migration);
    // When the import runs, the first row imported will trigger an     // interruption.     $result = $executable->import();

    $this->assertEquals(MigrationInterface::RESULT_INCOMPLETE, $result);

    // The status should have been reset to IDLE.     $this->assertEquals(MigrationInterface::STATUS_IDLE, $migration->getStatus());
  }

  /** * Reacts to post-row-save event. * * @param \Drupal\migrate\Event\MigratePostRowSaveEvent $event * The migration event. * @param string $name * The event name. */

        $xpath = new \DOMXPath($xml);
        $xpath->registerNamespace('container', self::NS);

        if (false === $imports = $xpath->query('.//container:imports/container:import', $root)) {
            return;
        }

        $defaultDirectory = \dirname($file);
        foreach ($imports as $import) {
            $this->setCurrentDir($defaultDirectory);
            $this->import($import->getAttribute('resource'), XmlUtils::phpize($import->getAttribute('type')) ?: null, XmlUtils::phpize($import->getAttribute('ignore-errors')) ?: false, $file);
        }
    }

    private function parseDefinitions(\DOMDocument $xml, string $file, Definition $defaults, \DOMNode $root = null): void
    {
        $xpath = new \DOMXPath($xml);
        $xpath->registerNamespace('container', self::NS);

        if (false === $services = $xpath->query('.//container:services/container:service|.//container:services/container:prototype|.//container:services/container:stack', $root)) {
            return;
        }
        

  public function testMultipleValueExplode(array $source_data, array $expected_data) {
    $definition = $this->getDefinition();
    $definition['source']['data_rows'] = [$source_data];

    $migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition);

    $executable = new MigrateExecutable($migration);
    $result = $executable->import();

    // Migration needs to succeed before further assertions are made.     $this->assertSame(MigrationInterface::RESULT_COMPLETED, $result);

    // Compare with expected data.     $this->assertEquals($expected_data, \Drupal::config('migrate_test.settings')->get());
  }

  /** * Provides multiple source data for "extract" process plugin test. */
  
Home | Imprint | This part of the site doesn't use cookies.