3 namespace Drupal\Tests\migrate\Unit\process;
5 use Drupal\migrate\Plugin\migrate\process\Callback;
8 * Tests the callback process plugin.
12 class CallbackTest extends MigrateProcessTestCase {
15 * Test callback with valid "callable".
17 * @dataProvider providerCallback
19 public function testCallback($callable) {
20 $configuration = ['callable' => $callable];
21 $this->plugin = new Callback($configuration, 'map', []);
22 $value = $this->plugin->transform('FooBar', $this->migrateExecutable, $this->row, 'destinationproperty');
23 $this->assertSame('foobar', $value);
27 * Data provider for ::testCallback().
29 public function providerCallback() {
31 'function' => ['strtolower'],
32 'class method' => [[self::class, 'strtolower']],
37 * Test callback exceptions.
39 * @dataProvider providerCallbackExceptions
41 public function testCallbackExceptions($message, $configuration) {
42 $this->setExpectedException(\InvalidArgumentException::class, $message);
43 $this->plugin = new Callback($configuration, 'map', []);
47 * Data provider for ::testCallbackExceptions().
49 public function providerCallbackExceptions() {
52 'message' => 'The "callable" must be set.',
53 'configuration' => [],
56 'message' => 'The "callable" must be a valid function or method.',
57 'configuration' => ['callable' => 'nonexistent_callable'],
63 * Makes a string lowercase for testing purposes.
65 * @param string $string
69 * The lowercased string.
71 * @see \Drupal\Tests\migrate\Unit\process\CallbackTest::providerCallback()
73 public static function strToLower($string) {
74 return mb_strtolower($string);