loadPathAliasByConditions example

/** * Tests the URL alias migration. */
  public function testUrlAlias() {
    $id_map = $this->getMigration('d6_url_alias')->getIdMap();
    // Test that the field exists.     $conditions = [
      'path' => '/node/1',
      'alias' => '/alias-one',
      'langcode' => 'af',
    ];
    $path_alias = $this->loadPathAliasByConditions($conditions);
    $this->assertPath(1, $conditions$path_alias);
    $this->assertSame([['1']]$id_map->lookupDestinationIds([$path_alias->id()]), "Test IdMap");

    $conditions = [
      'path' => '/node/2',
      'alias' => '/alias-two',
      'langcode' => 'en',
    ];
    $path_alias = $this->loadPathAliasByConditions($conditions);
    $this->assertPath(2, $conditions$path_alias);

    
$this->executeMigrations([
      'd7_node_translation',
      'd7_url_alias',
    ]);
  }

  /** * Tests the URL alias migration with translated nodes. */
  public function testUrlAliasWithTranslatedNodes() {
    // Alias for the 'The thing about Deep Space 9' node in English.     $path_alias = $this->loadPathAliasByConditions(['alias' => '/deep-space-9']);
    $this->assertSame('/node/2', $path_alias->getPath());
    $this->assertSame('en', $path_alias->get('langcode')->value);

    // Alias for the 'The thing about Deep Space 9' Icelandic translation,     // which should now point to node/2 instead of node/3.     $path_alias = $this->loadPathAliasByConditions(['alias' => '/deep-space-9-is']);
    $this->assertSame('/node/2', $path_alias->getPath());
    $this->assertSame('is', $path_alias->get('langcode')->value);

    // Alias for the 'The thing about Firefly' node in Icelandic.     $path_alias = $this->loadPathAliasByConditions(['alias' => '/firefly-is']);
    
$this->migrateContentTypes();
    $this->executeMigrations([
      'language',
      'd7_node',
    ]);
  }

  /** * Tests the URL alias migration. */
  public function testUrlAlias() {
    $path_alias = $this->loadPathAliasByConditions([
      'path' => '/taxonomy/term/4',
      'alias' => '/term33',
      'langcode' => 'und',
    ]);
    $this->assertSame('/taxonomy/term/4', $path_alias->getPath());
    $this->assertSame('/term33', $path_alias->getAlias());
    $this->assertSame('und', $path_alias->language()->getId());

    // Alias with no slash.     $path_alias = $this->loadPathAliasByConditions(['alias' => '/source-noSlash']);
    $this->assertSame('/admin', $path_alias->getPath());
    
Home | Imprint | This part of the site doesn't use cookies.