View source
<?php
namespace Drupal\Tests\tamper\Unit\Plugin\Tamper;
use Drupal\tamper\Exception\TamperException;
use Drupal\tamper\Plugin\Tamper\Explode;
class ExplodeTest extends TamperPluginTestBase {
protected function instantiatePlugin() {
return $this
->getPluginDefaultConfig();
}
public function testExplodeWithSingleValue() {
$original = 'foo,bar,baz,zip';
$expected = [
'foo',
'bar',
'baz',
'zip',
];
$this
->assertArrayEquals($expected, $this
->getPluginDefaultConfig()
->tamper($original));
}
public function testExplodeWithMultipleValues() {
$this
->expectException(TamperException::class);
$this
->expectExceptionMessage('Input should be a string.');
$original = [
'foo,bar',
'baz,zip',
];
$this
->getPluginDefaultConfig()
->tamper($original);
}
public function testExplodeWithSingleValueAndLimit() {
$original = 'foo,bar,baz,zip';
$expected = [
'foo',
'bar,baz,zip',
];
$this
->assertArrayEquals($expected, $this
->getPluginWithLimit()
->tamper($original));
}
public function testExplodeWithMultipleValuesAndLimit() {
$this
->expectException(TamperException::class);
$this
->expectExceptionMessage('Input should be a string.');
$original = [
'foo,bar,baz,zip',
'fizz,bang,boop',
];
$this
->getPluginWithLimit()
->tamper($original);
}
protected function getPluginDefaultConfig() {
return new Explode([], 'explode', [], $this
->getMockSourceDefinition());
}
protected function getPluginWithLimit() {
$config = [
Explode::SETTING_LIMIT => 2,
];
return new Explode($config, 'explode', [], $this
->getMockSourceDefinition());
}
}