class ExplodeTest in Drupal 9
Same name and namespace in other branches
- 8 core/modules/migrate/tests/src/Unit/process/ExplodeTest.php \Drupal\Tests\migrate\Unit\process\ExplodeTest
Tests the Explode process plugin.
@group migrate
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, PhpUnitCompatibilityTrait, PhpUnitWarnings
- class \Drupal\Tests\migrate\Unit\MigrateTestCase
- class \Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase
- class \Drupal\Tests\migrate\Unit\process\ExplodeTest
- class \Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase
- class \Drupal\Tests\migrate\Unit\MigrateTestCase
Expanded class hierarchy of ExplodeTest
File
- core/
modules/ migrate/ tests/ src/ Unit/ process/ ExplodeTest.php, line 14
Namespace
Drupal\Tests\migrate\Unit\processView source
class ExplodeTest extends MigrateProcessTestCase {
/**
* {@inheritdoc}
*/
protected function setUp() : void {
$configuration = [
'delimiter' => ',',
];
$this->plugin = new Explode($configuration, 'map', []);
parent::setUp();
}
/**
* Tests explode transform process works.
*/
public function testTransform() {
$value = $this->plugin
->transform('foo,bar,tik', $this->migrateExecutable, $this->row, 'destination_property');
$this
->assertSame([
'foo',
'bar',
'tik',
], $value);
}
/**
* Tests explode transform process works with a limit.
*/
public function testTransformLimit() {
$plugin = new Explode([
'delimiter' => '_',
'limit' => 2,
], 'map', []);
$value = $plugin
->transform('foo_bar_tik', $this->migrateExecutable, $this->row, 'destination_property');
$this
->assertSame([
'foo',
'bar_tik',
], $value);
}
/**
* Tests if the explode process can be chained with handles_multiple process.
*/
public function testChainedTransform() {
$exploded = $this->plugin
->transform('foo,bar,tik', $this->migrateExecutable, $this->row, 'destination_property');
$concat = new Concat([], 'map', []);
$concatenated = $concat
->transform($exploded, $this->migrateExecutable, $this->row, 'destination_property');
$this
->assertSame('foobartik', $concatenated);
}
/**
* Tests explode fails properly on non-strings.
*/
public function testExplodeWithNonString() {
$this
->expectException(MigrateException::class);
$this
->expectExceptionMessage('is not a string');
$this->plugin
->transform([
'foo',
], $this->migrateExecutable, $this->row, 'destination_property');
}
/**
* Tests that explode works on non-strings but with strict set to FALSE.
*
* @dataProvider providerExplodeWithNonStrictAndEmptySource
*/
public function testExplodeWithNonStrictAndEmptySource($value, $expected) {
$plugin = new Explode([
'delimiter' => '|',
'strict' => FALSE,
], 'map', []);
$processed = $plugin
->transform($value, $this->migrateExecutable, $this->row, 'destination_property');
$this
->assertSame($expected, $processed);
}
/**
* Data provider for ::testExplodeWithNonStrictAndEmptySource().
*/
public function providerExplodeWithNonStrictAndEmptySource() {
return [
'normal_string' => [
'a|b|c',
[
'a',
'b',
'c',
],
],
'integer_cast_to_string' => [
123,
[
'123',
],
],
'zero_integer_cast_to_string' => [
0,
[
'0',
],
],
'true_cast_to_string' => [
TRUE,
[
'1',
],
],
'null_empty_array' => [
NULL,
[],
],
'false_empty_array' => [
FALSE,
[],
],
'empty_string_empty_array' => [
'',
[],
],
];
}
/**
* Tests that explode raises an exception when the value cannot be casted to
* string.
*/
public function testExplodeWithNonStrictAndNonCastable() {
$plugin = new Explode([
'delimiter' => '|',
'strict' => FALSE,
], 'map', []);
$this
->expectException(MigrateException::class);
$this
->expectExceptionMessage('cannot be casted to a string');
$processed = $plugin
->transform([
'foo',
], $this->migrateExecutable, $this->row, 'destination_property');
$this
->assertSame([
'foo',
], $processed);
}
/**
* Tests that explode with an empty string and strict check returns a
* non-empty array.
*/
public function testExplodeWithStrictAndEmptyString() {
$plugin = new Explode([
'delimiter' => '|',
], 'map', []);
$processed = $plugin
->transform('', $this->migrateExecutable, $this->row, 'destination_property');
$this
->assertSame([
'',
], $processed);
}
/**
* Tests explode fails with empty delimiter.
*/
public function testExplodeWithEmptyDelimiter() {
$this
->expectException(MigrateException::class);
$this
->expectExceptionMessage('delimiter is empty');
$plugin = new Explode([
'delimiter' => '',
], 'map', []);
$plugin
->transform('foo,bar', $this->migrateExecutable, $this->row, 'destination_property');
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ExplodeTest:: |
public | function | Data provider for ::testExplodeWithNonStrictAndEmptySource(). | |
ExplodeTest:: |
protected | function |
Overrides MigrateProcessTestCase:: |
|
ExplodeTest:: |
public | function | Tests if the explode process can be chained with handles_multiple process. | |
ExplodeTest:: |
public | function | Tests explode fails with empty delimiter. | |
ExplodeTest:: |
public | function | Tests that explode works on non-strings but with strict set to FALSE. | |
ExplodeTest:: |
public | function | Tests that explode raises an exception when the value cannot be casted to string. | |
ExplodeTest:: |
public | function | Tests explode fails properly on non-strings. | |
ExplodeTest:: |
public | function | Tests that explode with an empty string and strict check returns a non-empty array. | |
ExplodeTest:: |
public | function | Tests explode transform process works. | |
ExplodeTest:: |
public | function | Tests explode transform process works with a limit. | |
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. | 7 |
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. | |
MigrateTestCase:: |
protected | function | Gets the value on a row for a given key. | |
MigrateTestCase:: |
public | function | Tests a query. | |
MigrateTestCase:: |
protected | function | Asserts tested values during test retrieval. | |
PhpUnitWarnings:: |
private static | property | Deprecation warnings from PHPUnit to raise with @trigger_error(). | |
PhpUnitWarnings:: |
public | function | Converts PHPUnit deprecation warnings to E_USER_DEPRECATED. | |
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 | 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. | |
UnitTestCase:: |
public static | function |