class MenuLinkParentTest in Drupal 8
Same name and namespace in other branches
- 9 core/modules/migrate/tests/src/Unit/process/MenuLinkParentTest.php \Drupal\Tests\migrate\Unit\process\MenuLinkParentTest
Tests the menu link parent process plugin.
@coversDefaultClass \Drupal\migrate\Plugin\migrate\process\MenuLinkParent @group migrate
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\migrate\Unit\MigrateTestCase
- class \Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase
- class \Drupal\Tests\migrate\Unit\process\MenuLinkParentTest
- class \Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase
- class \Drupal\Tests\migrate\Unit\MigrateTestCase
Expanded class hierarchy of MenuLinkParentTest
File
- core/
modules/ migrate/ tests/ src/ Unit/ process/ MenuLinkParentTest.php, line 22
Namespace
Drupal\Tests\migrate\Unit\processView source
class MenuLinkParentTest extends MigrateProcessTestCase {
/**
* A MigrationInterface prophecy.
*
* @var \Prophecy\Prophecy\ObjectProphecy
*/
protected $migration;
/**
* A MigrateLookupInterface prophecy.
*
* @var \Prophecy\Prophecy\ObjectProphecy
*/
protected $migrateLookup;
/**
* A MigrationInterface prophecy.
*
* @var \Prophecy\Prophecy\ObjectProphecy
*/
protected $menuLinkManager;
/**
* A MigrationInterface prophecy.
*
* @var \Prophecy\Prophecy\ObjectProphecy
*/
protected $menuLinkStorage;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->migration = $this
->prophesize(MigrationInterface::class);
$this->migrateLookup = $this
->prophesize(MigrateLookupInterface::class);
$this->migrateLookup
->lookup(NULL, [
1,
])
->willReturn([]);
$this->menuLinkManager = $this
->prophesize(MenuLinkManagerInterface::class);
$this->menuLinkStorage = $this
->prophesize(EntityStorageInterface::class);
$container = new ContainerBuilder();
$container
->set('migrate.lookup', $this->migrateLookup
->reveal());
\Drupal::setContainer($container);
}
/**
* @covers ::transform
*/
public function testTransformException() {
$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 '1' in menu 'admin'.");
$plugin
->transform([
1,
'admin',
NULL,
], $this->migrateExecutable, $this->row, 'destination_property');
}
/**
* Tests the plugin when the parent is an external link.
*
* @covers ::transform
*/
public function testTransformExternal() {
$menu_link_content = $this
->prophesize(MenuLinkContentInterface::class);
$menu_link_content
->getPluginId()
->willReturn('menu_link_content:fe151460-dfa2-4133-8864-c1746f28ab27');
$this->menuLinkStorage
->loadByProperties([
'link__uri' => 'http://example.com',
])
->willReturn([
9054 => $menu_link_content,
]);
$plugin = $this
->prophesize(PluginInspectionInterface::class);
$this->menuLinkManager
->createInstance('menu_link_content:fe151460-dfa2-4133-8864-c1746f28ab27')
->willReturn($plugin
->reveal());
$plugin = new MenuLinkParent([], 'map', [], $this->migrateLookup
->reveal(), $this->menuLinkManager
->reveal(), $this->menuLinkStorage
->reveal(), $this->migration
->reveal());
$result = $plugin
->transform([
1,
'admin',
'http://example.com',
], $this->migrateExecutable, $this->row, 'destination_property');
$this
->assertEquals('menu_link_content:fe151460-dfa2-4133-8864-c1746f28ab27', $result);
}
/**
* Tests the plugin when the parent is an external link.
*
* @covers ::transform
*
* @group legacy
*
* @expectedDeprecation Passing a migration process plugin as the fourth argument to Drupal\migrate\Plugin\migrate\process\MenuLinkParent::__construct is deprecated in drupal:8.8.0 and will throw an error in drupal:9.0.0. Pass the migrate.lookup service instead. See https://www.drupal.org/node/3047268
*/
public function testLegacyTransformExternal() {
$migration_plugin = $this
->prophesize(MigrateProcessInterface::class);
$menu_link_manager = $this
->prophesize(MenuLinkManagerInterface::class);
$menu_link_storage = $this
->prophesize(EntityStorageInterface::class);
$menu_link_content = $this
->prophesize(MenuLinkContentInterface::class);
$menu_link_content
->getPluginId()
->willReturn('menu_link_content:fe151460-dfa2-4133-8864-c1746f28ab27');
$menu_link_storage
->loadByProperties([
'link__uri' => 'http://example.com',
])
->willReturn([
9054 => $menu_link_content,
]);
$plugin = $this
->prophesize(PluginInspectionInterface::class);
$menu_link_manager
->createInstance('menu_link_content:fe151460-dfa2-4133-8864-c1746f28ab27')
->willReturn($plugin
->reveal());
$plugin = new MenuLinkParent([], 'map', [], $migration_plugin
->reveal(), $menu_link_manager
->reveal(), $menu_link_storage
->reveal());
$result = $plugin
->transform([
1,
'admin',
'http://example.com',
], $this->migrateExecutable, $this->row, 'destinationproperty');
$this
->assertEquals('menu_link_content:fe151460-dfa2-4133-8864-c1746f28ab27', $result);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MenuLinkParentTest:: |
protected | property | A MigrationInterface prophecy. | |
MenuLinkParentTest:: |
protected | property | A MigrationInterface prophecy. | |
MenuLinkParentTest:: |
protected | property | A MigrateLookupInterface prophecy. | |
MenuLinkParentTest:: |
protected | property | A MigrationInterface prophecy. | |
MenuLinkParentTest:: |
protected | function |
Overrides MigrateProcessTestCase:: |
|
MenuLinkParentTest:: |
public | function | Tests the plugin when the parent is an external link. | |
MenuLinkParentTest:: |
public | function | @covers ::transform | |
MenuLinkParentTest:: |
public | function | Tests the plugin when the parent is an external link. | |
MigrateProcessTestCase:: |
protected | property | ||
MigrateProcessTestCase:: |
protected | property | ||
MigrateProcessTestCase:: |
protected | property | ||
MigrateTestCase:: |
protected | property | The migration ID map. | |
MigrateTestCase:: |
protected | property | An array of migration configuration values. | 16 |
MigrateTestCase:: |
protected | property | Local store for mocking setStatus()/getStatus(). | |
MigrateTestCase:: |
protected | function | Generates a table schema from a row. | |
MigrateTestCase:: |
protected | function | Gets an SQLite database connection object for use in tests. | |
MigrateTestCase:: |
protected | function | Retrieves a mocked migration. | 1 |
MigrateTestCase:: |
protected | function | Gets the value on a row for a given key. | 1 |
MigrateTestCase:: |
public | function | Tests a query. | |
MigrateTestCase:: |
protected | function | Asserts tested values during test retrieval. | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |