class SubstrTest in Drupal 10
Same name and namespace in other branches
- 8 core/modules/migrate/tests/src/Unit/process/SubstrTest.php \Drupal\Tests\migrate\Unit\process\SubstrTest
- 9 core/modules/migrate/tests/src/Unit/process/SubstrTest.php \Drupal\Tests\migrate\Unit\process\SubstrTest
Tests the substr plugin.
@coversDefaultClass \Drupal\migrate\Plugin\migrate\process\Substr
@group migrate
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, PhpUnitWarnings
- class \Drupal\Tests\migrate\Unit\MigrateTestCase
- class \Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase
- class \Drupal\Tests\migrate\Unit\process\SubstrTest
- class \Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase
- class \Drupal\Tests\migrate\Unit\MigrateTestCase
Expanded class hierarchy of SubstrTest
File
- core/
modules/ migrate/ tests/ src/ Unit/ process/ SubstrTest.php, line 17
Namespace
Drupal\Tests\migrate\Unit\processView source
class SubstrTest extends MigrateProcessTestCase {
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
}
/**
* Tests Substr plugin based on providerTestSubstr() values.
*
* @dataProvider providerTestSubstr
*/
public function testSubstr($start = NULL, $length = NULL, $expected = NULL) {
$configuration['start'] = $start;
$configuration['length'] = $length;
$this->plugin = new Substr($configuration, 'map', []);
$value = $this->plugin
->transform('Captain Janeway', $this->migrateExecutable, $this->row, 'destination_property');
$this
->assertSame($expected, $value);
}
/**
* Data provider for testSubstr().
*/
public function providerTestSubstr() {
return [
// Tests with valid start and length values.
[
0,
7,
'Captain',
],
// Tests with valid start > 0 and valid length.
[
6,
3,
'n J',
],
// Tests with valid start < 0 and valid length.
[
-7,
4,
'Jane',
],
// Tests without start value and valid length value.
[
NULL,
7,
'Captain',
],
// Tests with valid start value and no length value.
[
1,
NULL,
'aptain Janeway',
],
// Tests without both start and length values.
[
NULL,
NULL,
'Captain Janeway',
],
];
}
/**
* Tests invalid input type.
*/
public function testSubstrFail() {
$configuration = [];
$this->plugin = new Substr($configuration, 'map', []);
$this
->expectException(MigrateException::class);
$this
->expectExceptionMessage('The input value must be a string.');
$this->plugin
->transform([
'Captain Janeway',
], $this->migrateExecutable, $this->row, 'destination_property');
}
/**
* Tests that the start parameter is an integer.
*/
public function testStartIsString() {
$configuration['start'] = '2';
$this->plugin = new Substr($configuration, 'map', []);
$this
->expectException(MigrateException::class);
$this
->expectExceptionMessage('The start position configuration value should be an integer. Omit this key to capture from the beginning of the string.');
$this->plugin
->transform([
'foo',
], $this->migrateExecutable, $this->row, 'destination_property');
}
/**
* Tests that the length parameter is an integer.
*/
public function testLengthIsString() {
$configuration['length'] = '1';
$this->plugin = new Substr($configuration, 'map', []);
$this
->expectException(MigrateException::class);
$this
->expectExceptionMessage('The character length configuration value should be an integer. Omit this key to capture from the start position to the end of the string.');
$this->plugin
->transform([
'foo',
], $this->migrateExecutable, $this->row, 'destination_property');
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
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. | 5 |
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. | |
SubstrTest:: |
public | function | Data provider for testSubstr(). | |
SubstrTest:: |
protected | function |
Overrides MigrateProcessTestCase:: |
|
SubstrTest:: |
public | function | Tests that the length parameter is an integer. | |
SubstrTest:: |
public | function | Tests that the start parameter is an integer. | |
SubstrTest:: |
public | function | Tests Substr plugin based on providerTestSubstr() values. | |
SubstrTest:: |
public | function | Tests invalid input type. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 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. | |
UnitTestCase:: |
public static | function |