Updated to Drupal 8.6.4, which is PHP 7.3 friendly. Also updated HTMLaw library....
[yaffs-website] / web / core / modules / migrate / tests / src / Unit / process / CallbackTest.php
1 <?php
2
3 namespace Drupal\Tests\migrate\Unit\process;
4
5 use Drupal\migrate\Plugin\migrate\process\Callback;
6
7 /**
8  * Tests the callback process plugin.
9  *
10  * @group migrate
11  */
12 class CallbackTest extends MigrateProcessTestCase {
13
14   /**
15    * Test callback with valid "callable".
16    *
17    * @dataProvider providerCallback
18    */
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);
24   }
25
26   /**
27    * Data provider for ::testCallback().
28    */
29   public function providerCallback() {
30     return [
31       'function' => ['strtolower'],
32       'class method' => [[self::class, 'strtolower']],
33     ];
34   }
35
36   /**
37    * Test callback exceptions.
38    *
39    * @dataProvider providerCallbackExceptions
40    */
41   public function testCallbackExceptions($message, $configuration) {
42     $this->setExpectedException(\InvalidArgumentException::class, $message);
43     $this->plugin = new Callback($configuration, 'map', []);
44   }
45
46   /**
47    * Data provider for ::testCallbackExceptions().
48    */
49   public function providerCallbackExceptions() {
50     return [
51       'not set' => [
52         'message' => 'The "callable" must be set.',
53         'configuration' => [],
54       ],
55       'invalid method' => [
56         'message' => 'The "callable" must be a valid function or method.',
57         'configuration' => ['callable' => 'nonexistent_callable'],
58       ],
59     ];
60   }
61
62   /**
63    * Makes a string lowercase for testing purposes.
64    *
65    * @param string $string
66    *   The input string.
67    *
68    * @return string
69    *   The lowercased string.
70    *
71    * @see \Drupal\Tests\migrate\Unit\process\CallbackTest::providerCallback()
72    */
73   public static function strToLower($string) {
74     return mb_strtolower($string);
75   }
76
77 }