You are here

public function MenuLinkParentTest::testMenuLinkParent in Drupal 9

Tests the menu link content process plugin.

@dataProvider providerMenuLinkParent

Parameters

string[] $source_value: The source value(s) for the migration process plugin.

string $lookup_result: The ID value to be returned from migration_lookup.

string $plugin_id: The menu link plugin ID.

string $route_name: A route to create.

string $expected_result: The expected value(s) of the migration process plugin.

Throws

\Drupal\Component\Plugin\Exception\PluginException

\Drupal\migrate\MigrateException

\Drupal\migrate\MigrateSkipRowException

File

core/modules/migrate/tests/src/Unit/process/MenuLinkParentTest.php, line 137

Class

MenuLinkParentTest
Tests the menu link parent process plugin.

Namespace

Drupal\Tests\migrate\Unit\process

Code

public function testMenuLinkParent(array $source_value, $lookup_result, $plugin_id, $route_name, $expected_result) {
  [
    $parent_id,
    $menu_name,
    $parent_link_path,
  ] = $source_value;
  $this->migrateLookup
    ->lookup(NULL, [
    $parent_id,
  ])
    ->willReturn([
    [
      'id' => $lookup_result,
    ],
  ]);
  if ($route_name) {
    $plugin_definition = [
      'menu_name' => $menu_name,
    ];
    $static_override = $this
      ->prophesize(StaticMenuLinkOverridesInterface::class);
    $static_override = $static_override
      ->reveal();
    $menu_link = new MenuLinkDefault([], $plugin_id, $plugin_definition, $static_override);
    $this->menuLinkManager
      ->loadLinksByRoute($route_name, [], 'admin')
      ->willReturn([
      $plugin_id => $menu_link,
    ]);
    $url = new Url($route_name, [], []);
    $this->pathValidator
      ->getUrlIfValidWithoutAccessCheck($parent_link_path)
      ->willReturn($url);
  }
  $result = $this
    ->doTransform($source_value, $plugin_id);
  $this
    ->assertSame($expected_result, $result);
}