X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fmigrate%2Ftests%2Fsrc%2FUnit%2Fprocess%2FCallbackTest.php;fp=web%2Fcore%2Fmodules%2Fmigrate%2Ftests%2Fsrc%2FUnit%2Fprocess%2FCallbackTest.php;h=6d894c09c269e5ae4c4331dbbefce27ef7b08909;hp=91eb2e7603e559fd2ff300383953309c0f4ce535;hb=0bf8d09d2542548982e81a441b1f16e75873a04f;hpb=74df008bdbb3a11eeea356744f39b802369bda3c diff --git a/web/core/modules/migrate/tests/src/Unit/process/CallbackTest.php b/web/core/modules/migrate/tests/src/Unit/process/CallbackTest.php index 91eb2e760..6d894c09c 100644 --- a/web/core/modules/migrate/tests/src/Unit/process/CallbackTest.php +++ b/web/core/modules/migrate/tests/src/Unit/process/CallbackTest.php @@ -1,10 +1,5 @@ plugin = new TestCallback(); - parent::setUp(); + public function testCallback($callable) { + $configuration = ['callable' => $callable]; + $this->plugin = new Callback($configuration, 'map', []); + $value = $this->plugin->transform('FooBar', $this->migrateExecutable, $this->row, 'destinationproperty'); + $this->assertSame('foobar', $value); } /** - * Test callback with a function as callable. + * Data provider for ::testCallback(). */ - public function testCallbackWithFunction() { - $this->plugin->setCallable('strtolower'); - $value = $this->plugin->transform('FooBar', $this->migrateExecutable, $this->row, 'destinationproperty'); - $this->assertSame('foobar', $value); + public function providerCallback() { + return [ + 'function' => ['strtolower'], + 'class method' => [[self::class, 'strtolower']], + ]; } /** - * Test callback with a class method as callable. + * Test callback exceptions. + * + * @dataProvider providerCallbackExceptions */ - public function testCallbackWithClassMethod() { - $this->plugin->setCallable(['\Drupal\Component\Utility\Unicode', 'strtolower']); - $value = $this->plugin->transform('FooBar', $this->migrateExecutable, $this->row, 'destinationproperty'); - $this->assertSame('foobar', $value); + public function testCallbackExceptions($message, $configuration) { + $this->setExpectedException(\InvalidArgumentException::class, $message); + $this->plugin = new Callback($configuration, 'map', []); } -} - -class TestCallback extends Callback { - public function __construct() { + /** + * Data provider for ::testCallbackExceptions(). + */ + public function providerCallbackExceptions() { + return [ + 'not set' => [ + 'message' => 'The "callable" must be set.', + 'configuration' => [], + ], + 'invalid method' => [ + 'message' => 'The "callable" must be a valid function or method.', + 'configuration' => ['callable' => 'nonexistent_callable'], + ], + ]; } - public function setCallable($callable) { - $this->configuration['callable'] = $callable; + /** + * Makes a string lowercase for testing purposes. + * + * @param string $string + * The input string. + * + * @return string + * The lowercased string. + * + * @see \Drupal\Tests\migrate\Unit\process\CallbackTest::providerCallback() + */ + public static function strToLower($string) { + return mb_strtolower($string); } }