lookup example

$destination->getIds()->willReturn(['id' => ['type' => 'integer']]);

    $migration = $this->prophesize(MigrationInterface::class);
    $migration->getIdMap()->willReturn($id_map->reveal());
    $migration->getDestinationPlugin()->willReturn($destination->reveal());

    $plugin_manager = $this->prophesize(MigrationPluginManagerInterface::class);
    $plugin_manager->createInstances('test_migration')->willReturn([$migration->reveal()]);

    $lookup = new MigrateLookup($plugin_manager->reveal());

    $this->assertSame([['id' => 2]]$lookup->lookup('test_migration', $source_ids));
  }

  /** * Tests message logged when a single migration is not found. * * @dataProvider providerExceptionOnMigrationNotFound */
  public function testExceptionOnMigrationNotFound($migrations$message) {
    $migration_plugin_manager = $this->prophesize(MigrationPluginManagerInterface::class);
    $migration_plugin_manager->createInstances($migrations)->willReturn([]);
    $this->expectException(PluginNotFoundException::class);
    

  public function testTransformException(array $source_value) {
    [$parent_id$menu_name] = $source_value;
    $this->migrateLookup->lookup(NULL, [1])->willReturn([]);
    $plugin = new MenuLinkParent([], 'map', []$this->migrateLookup->reveal()$this->menuLinkManager->reveal()$this->menuLinkStorage->reveal()$this->migration->reveal());
    $this->expectException(MigrateSkipRowException::class);
    $this->expectExceptionMessage("No parent link found for plid '$parent_id' in menu '$menu_name'.");
    $plugin->transform($source_value$this->migrateExecutable, $this->row, 'destination');
  }

  /** * Provides data for testTransformException(). */
  public function providerTransformException() {
    // The parent ID does not for the following tests.
$this->cache = $cache;
    $this->requestPolicy = $request_policy;
    $this->responsePolicy = $response_policy;
  }

  /** * {@inheritdoc} */
  public function handle(Request $request$type = self::MAIN_REQUEST, $catch = TRUE): Response {
    // Only allow page caching on master request.     if ($type === static::MAIN_REQUEST && $this->requestPolicy->check($request) === RequestPolicyInterface::ALLOW) {
      $response = $this->lookup($request$type$catch);
    }
    else {
      $response = $this->pass($request$type$catch);
    }

    return $response;
  }

  /** * Sidesteps the page cache and directly forwards a request to the backend. * * @param \Symfony\Component\HttpFoundation\Request $request * A request object. * @param int $type * The type of the request (one of HttpKernelInterface::MAIN_REQUEST or * HttpKernelInterface::SUB_REQUEST) * @param bool $catch * Whether to catch exceptions or not * * @returns \Symfony\Component\HttpFoundation\Response $response * A response object. */
$response = $this->invalidate($request$catch);
        } elseif ($request->headers->has('expect') || !$request->isMethodCacheable()) {
            $response = $this->pass($request$catch);
        } elseif ($this->options['allow_reload'] && $request->isNoCache()) {
            /* If allow_reload is configured and the client requests "Cache-Control: no-cache", reload the cache by fetching a fresh response and caching it (if possible). */
            $this->record($request, 'reload');
            $response = $this->fetch($request$catch);
        } else {
            $response = $this->lookup($request$catch);
        }

        $this->restoreResponseBody($request$response);

        if (HttpKernelInterface::MAIN_REQUEST === $type) {
            $this->addTraces($response);
        }

        if (null !== $this->surrogate) {
            if (HttpKernelInterface::MAIN_REQUEST === $type) {
                $this->surrogateCacheStrategy->update($response);
            }

  public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row$destination_property) {
    $parent_id = array_shift($value);

    // Handle root elements of a menu.     if (!$parent_id) {
      return '';
    }

    $lookup_result = $this->migrateLookup->lookup($this->migration->id()[$parent_id]);
    if ($lookup_result) {
      $already_migrated_id = $lookup_result[0]['id'];
    }

    if (!empty($already_migrated_id) && ($link = $this->menuLinkStorage->load($already_migrated_id))) {
      return $link->getPluginId();
    }

    // Parent could not be determined by ID, so we try to determine by the     // combination of the menu name and parent link path.     if (isset($value[1])) {
      [
/** * {@inheritdoc} */
  public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row$destination_property) {
    [$entity_type$bundle] = $value;
    $lookup_result = NULL;
    // For comment entity types get the destination bundle from the     // d7_comment_type migration, if it exists.     if ($entity_type === 'comment' && $bundle != 'comment_forum') {
      $value = str_replace('comment_node_', '', $bundle);
      $migration = 'd7_comment_type';
      $lookup_result = $this->migrateLookup->lookup($migration[$value]);
      $lookup_result = empty($lookup_result) ? NULL : reset($lookup_result[0]);
    }
    return $lookup_result ? $lookup_result : $bundle;
  }

}
class FieldFileTest extends UnitTestCase {

  /** * Tests that alt and title attributes are included in transformed values. */
  public function testTransformAltTitle() {
    $executable = $this->prophesize(MigrateExecutableInterface::class)->reveal();
    $row = $this->prophesize(Row::class)->reveal();
    $migration = $this->prophesize(MigrationInterface::class)->reveal();

    $migrate_lookup = $this->prophesize(MigrateLookupInterface::class);
    $migrate_lookup->lookup('d6_file', [1])->willReturn([['fid' => 1]]);

    $plugin = new FieldFile([], 'd6_file', []$migration$migrate_lookup->reveal());

    $options = [
      'alt' => 'Foo',
      'title' => 'Bar',
    ];
    $value = [
      'fid' => 1,
      'list' => TRUE,
      'data' => serialize($options),
    ];
    if ($roles) {
      $visibility['user_role'] = [
        'id' => 'user_role',
        'roles' => [],
        'context_mapping' => [
          'user' => '@user.current_user_context:current_user',
        ],
        'negate' => FALSE,
      ];

      foreach ($roles as $key => $role_id) {
        $lookup_result = $this->migrateLookup->lookup(['d6_user_role', 'd7_user_role'][$role_id]);
        if ($lookup_result) {
          $roles[$key] = $lookup_result[0]['id'];
        }
      }
      $visibility['user_role']['roles'] = array_combine($roles$roles);
    }

    if ($pages) {
      // 2 == BLOCK_VISIBILITY_PHP in Drupal 6 and 7.       if ($old_visibility == 2) {
        // If the PHP module is present, migrate the visibility code unaltered.
$response = $this->invalidate($request$catch);
        } elseif ($request->headers->has('expect') || !$request->isMethodCacheable()) {
            $response = $this->pass($request$catch);
        } elseif ($this->options['allow_reload'] && $request->isNoCache()) {
            /* If allow_reload is configured and the client requests "Cache-Control: no-cache", reload the cache by fetching a fresh response and caching it (if possible). */
            $this->record($request, 'reload');
            $response = $this->fetch($request$catch);
        } else {
            $response = $this->lookup($request$catch);
        }

        $this->restoreResponseBody($request$response);

        if (HttpKernelInterface::MAIN_REQUEST === $type) {
            $this->addTraces($response);
        }

        if (null !== $this->surrogate) {
            if (HttpKernelInterface::MAIN_REQUEST === $type) {
                $this->surrogateCacheStrategy->update($response);
            }
/** * Lookups a Response from the cache for the given Request. * * {@inheritdoc} * * @param bool $catch * * @return Response */
    protected function lookup(Request $request$catch = false)
    {
        $response = parent::lookup($request$catch);

        // If Response is not fresh age > 0 AND contains a matching no cache tag         if ($response->getAge() > 0 && $this->containsNoCacheTag($request$response)) {
            $response = $this->fetch($request);
        }

        if (!$this->options['debug']) {
            // Hide headers from client             $response->headers->remove('x-shopware-allow-nocache');
            $response->headers->remove('x-shopware-cache-id');
        }

        
/** * {@inheritdoc} * * Migrate filter format serial to string id in permission name. */
  public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row$destination_property) {
    $rid = $row->getSourceProperty('rid');
    $migration = $this->configuration['migration'] ?? 'd6_filter_format';
    if ($formats = $row->getSourceProperty("filter_permissions:$rid")) {
      foreach ($formats as $format) {
        $lookup_result = $this->migrateLookup->lookup($migration[$format]);
        if ($lookup_result) {
          $value[] = 'use text format ' . $lookup_result[0]['format'];
        }
      }
    }
    return $value;
  }

}
/** * @internal */
class ReverseProxyCacheTest extends TestCase
{
    /** * The store is only used to track the cache tags and not to cache actual */
    public function testLookup(): void
    {
        $store = new ReverseProxyCache($this->createMock(AbstractReverseProxyGateway::class)$this->createMock(CacheTracer::class)[]);
        static::assertNull($store->lookup(new Request()));
        static::assertFalse($store->isLocked(new Request()));
        static::assertTrue($store->lock(new Request()));
        static::assertTrue($store->unlock(new Request()));
        $store->cleanup();
    }

    public function testWriteAddsGlobalStates(): void
    {
        $store = new ReverseProxyCache($this->createMock(AbstractReverseProxyGateway::class)$this->createMock(CacheTracer::class)[CacheResponseSubscriber::STATE_LOGGED_IN]);

        $request = new Request();
        
$migration = MigrationLookup::create($this->prepareContainer()$configuration, '', []$migration_plugin->reveal());
    $result = $migration->transform(1, $this->migrateExecutable, $this->row, '');
    $this->assertNull($result);
  }

  /** * @covers ::transform */
  public function testTransformWithStubbing() {
    $migration_plugin = $this->prophesize(MigrationInterface::class);
    $this->migrateLookup->lookup('destination_migration', [1])->willReturn(NULL);
    $this->migrateStub->createStub('destination_migration', [1][], FALSE)->willReturn([2]);

    $configuration = [
      'no_stub' => FALSE,
      'migration' => 'destination_migration',
    ];

    $migration = MigrationLookup::create($this->prepareContainer()$configuration, '', []$migration_plugin->reveal());
    $result = $migration->transform(1, $this->migrateExecutable, $this->row, '');
    $this->assertEquals(2, $result);

    
$this->installConfig(['node', 'user']);
    $this->createContentType(['type' => 'node_lookup']);
  }

  /** * Tests scenarios around single id lookups. */
  public function testSingleLookup() {
    $this->executeMigration('sample_lookup_migration');

    // Test numerically indexed source id.     $result = $this->migrateLookup->lookup('sample_lookup_migration', [17]);
    $this->assertSame('1', $result[0]['nid']);

    // Test associatively indexed source id.     $result = $this->migrateLookup->lookup('sample_lookup_migration', ['id' => 25]);
    $this->assertSame('2', $result[0]['nid']);

    // Test lookup not found.     $result = $this->migrateLookup->lookup('sample_lookup_migration', [1337]);
    $this->assertSame([]$result);
  }

  

      if (isset($this->configuration['source_ids'][$lookup_migration_id])) {
        $lookup_value = array_values($row->getMultiple($this->configuration['source_ids'][$lookup_migration_id]));
      }
      $lookup_value = (array) $lookup_value;
      $this->skipInvalid($lookup_value);
      $source_id_values[$lookup_migration_id] = $lookup_value;

      // Re-throw any PluginException as a MigrateException so the executable       // can shut down the migration.       try {
        $destination_id_array = $this->migrateLookup->lookup($lookup_migration_id$lookup_value);
      }
      catch (PluginNotFoundException $e) {
        $destination_id_array = [];
      }
      catch (MigrateException $e) {
        throw $e;
      }
      catch (\Exception $e) {
        throw new MigrateException(sprintf('A %s was thrown while processing this migration lookup', gettype($e))$e->getCode()$e);
      }

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