Commit eb93c68b authored by webchick's avatar webchick
Browse files

Issue #2573895 by johnstorey, phenaproxima, svendecabooter, benjy:...

Issue #2573895 by johnstorey, phenaproxima, svendecabooter, benjy: ConvertTokens.php cannot handle NULL values
parent ef8e66d3
......@@ -40,6 +40,13 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
'!password' => '',
);
// Given that our source is a database column that could hold a NULL
// value, sometimes that filters down to here. str_replace() cannot
// handle NULLs as the subject, so we reset to an empty string.
if (is_null($value)) {
$value = '';
}
if (is_string($value)) {
return str_replace(array_keys($tokens), $tokens, $value);
}
......
<?php
/**
* @file
* Contains \Drupal\Tests\user\Unit\Plugin\migrate\process\ConvertTokensTest.
*/
namespace Drupal\Tests\user\Unit\Plugin\migrate\process;
use Drupal\user\Plugin\migrate\process\ConvertTokens;
use Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase;
/**
* Tests the ConvertTokens plugin.
*
* @group user
*/
class ConvertTokensTest extends MigrateProcessTestCase {
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->plugin = new ConvertTokens([], 'convert_tokens', []);
}
/**
* Tests conversion of user tokens.
*/
public function testConvertTokens() {
$value = $this->plugin->transform('Account details for !username at !site', $this->migrateExecutable, $this->row, 'destinationproperty');
$this->assertEquals('Account details for [user:name] at [site:name]', $value);
}
/**
* Tests conversion of user tokens with a NULL value.
*/
public function testConvertTokensNull() {
$value = $this->plugin->transform(NULL, $this->migrateExecutable, $this->row, 'destinationproperty');
$this->assertEquals('', $value);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment