class GateTest in Migrate Plus 8.5
Tests the gate process plugin.
@group migrate @coversDefaultClass \Drupal\migrate_plus\Plugin\migrate\process\Gate
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_plus\Unit\process\GateTest
- class \Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase
- class \Drupal\Tests\migrate\Unit\MigrateTestCase
Expanded class hierarchy of GateTest
File
- tests/
src/ Unit/ process/ GateTest.php, line 17
Namespace
Drupal\Tests\migrate_plus\Unit\processView source
class GateTest extends MigrateProcessTestCase {
/**
* Test Gate plugin.
*
* @dataProvider gateProvider
*/
public function testGate($row_data, $destination_data, $configuration, $message) : void {
$row = new Row($row_data);
if (!empty($destination_data)) {
foreach ($destination_data as $key => $val) {
$row
->setDestinationProperty($key, $val);
}
}
if (!empty($message)) {
$this
->expectException(MigrateSkipProcessException::class);
$this
->expectExceptionMessage($message);
}
$plugin = new Gate($configuration, 'gate', []);
$value = $row_data[$configuration['source']];
$transformed = $plugin
->transform($value, $this->migrateExecutable, $row, 'destinationproperty');
if (empty($message)) {
$this
->assertSame($value, $transformed);
}
}
/**
* Row and plugin configuration for tests.
*
* @return array
*/
public function gateProvider() {
return [
'Gate does not unlock' => [
[
'state_abbr' => 'MO',
'source_data' => 'Let me through!',
],
NULL,
[
'source' => 'source_data',
'use_as_key' => 'state_abbr',
'valid_keys' => 'CO',
'key_direction' => 'unlock',
],
'Processing of destination property destinationproperty was skipped: Gate was not unlocked by property state_abbr with value MO.',
],
'Gate unlocks (with valid_keys array)' => [
[
'state_abbr' => 'Colorado',
'source_data' => 'Let me through!',
],
NULL,
[
'source' => 'source_data',
'use_as_key' => 'state_abbr',
'valid_keys' => [
'CO',
'Colorado',
],
'key_direction' => 'unlock',
],
NULL,
],
'Gate locks' => [
[
'state_abbr' => 'CO',
'source_data' => 'Let me through!',
],
NULL,
[
'source' => 'source_data',
'use_as_key' => 'state_abbr',
'valid_keys' => 'CO',
'key_direction' => 'lock',
],
'Processing of destination property destinationproperty was skipped: Gate was locked by property state_abbr with value CO.',
],
'Gate stays unlocked' => [
[
'state_abbr' => 'MO',
'source_data' => 'Let me through!',
],
NULL,
[
'source' => 'source_data',
'use_as_key' => 'state_abbr',
'valid_keys' => 'CO',
'key_direction' => 'lock',
],
NULL,
],
'Destination prop does not unlock gate' => [
[
'source_data' => 'Let me through!',
],
[
'state_abbr' => 'MO',
],
[
'source' => 'source_data',
'use_as_key' => '@state_abbr',
'valid_keys' => 'CO',
'key_direction' => 'unlock',
],
'Processing of destination property destinationproperty was skipped: Gate was not unlocked by property @state_abbr with value MO.',
],
'Destination prop unlocks gate' => [
[
'source_data' => 'Let me through!',
],
[
'state_abbr' => 'CO',
],
[
'source' => 'source_data',
'use_as_key' => '@state_abbr',
'valid_keys' => 'CO',
'key_direction' => 'unlock',
],
NULL,
],
'Destination prop locks gate' => [
[
'source_data' => 'Let me through!',
],
[
'state_abbr' => 'CO',
],
[
'source' => 'source_data',
'use_as_key' => '@state_abbr',
'valid_keys' => 'CO',
'key_direction' => 'lock',
],
'Processing of destination property destinationproperty was skipped: Gate was locked by property @state_abbr with value CO.',
],
'Gate stays unlocked with destination prop' => [
[
'source_data' => 'Let me through!',
],
[
'state_abbr' => 'MO',
],
[
'source' => 'source_data',
'use_as_key' => '@state_abbr',
'valid_keys' => 'CO',
'key_direction' => 'lock',
],
NULL,
],
];
}
/**
* Test Gate plugin with bad configuration.
*
* @dataProvider badConfigurationProvider
*/
public function testGateBadConfigration($configuration, $message) : void {
$this
->expectException(MigrateException::class);
$this
->expectExceptionMessage($message);
$plugin = new Gate($configuration, 'gate', []);
$plugin
->transform(NULL, $this->migrateExecutable, $this->row, 'destinationproperty');
}
/**
* Provider for bad configuration.
*
* @return array
*/
public function badConfigurationProvider() {
return [
'Missing use_as_key' => [
[
'source' => 'source_data',
'valid_keys' => 'CO',
'key_direction' => 'unlock',
],
'Gate plugin is missing use_as_key configuration.',
],
'Missing valid_keys' => [
[
'source' => 'source_data',
'use_as_key' => 'state_abbr',
'key_direction' => 'unlock',
],
'Gate plugin is missing valid_keys configuration.',
],
'Missing key_direction' => [
[
'source' => 'source_data',
'use_as_key' => 'state_abbr',
'valid_keys' => 'CO',
],
'Gate plugin is missing key_direction configuration.',
],
'Invalid key_direction' => [
[
'source' => 'source_data',
'use_as_key' => 'state_abbr',
'valid_keys' => 'CO',
'key_direction' => 'open',
],
'Gate plugin only accepts the following values for key_direction: lock and unlock.',
],
];
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
GateTest:: |
public | function | Provider for bad configuration. | |
GateTest:: |
public | function | Row and plugin configuration for tests. | |
GateTest:: |
public | function | Test Gate plugin. | |
GateTest:: |
public | function | Test Gate plugin with bad configuration. | |
MigrateProcessTestCase:: |
protected | property | ||
MigrateProcessTestCase:: |
protected | property | ||
MigrateProcessTestCase:: |
protected | property | ||
MigrateProcessTestCase:: |
protected | function |
Overrides UnitTestCase:: |
19 |
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. |