View source
<?php
namespace Drupal\Tests\tamper\Unit\Plugin\Tamper;
use Drupal\tamper\Exception\TamperException;
use Drupal\tamper\Plugin\Tamper\ConvertCase;
class ConvertCaseTest extends TamperPluginTestBase {
protected function instantiatePlugin() {
return new ConvertCase([], 'convert_case', [], $this
->getMockSourceDefinition());
}
public function testUpperCaseWithSingleValue() {
$config = [
ConvertCase::SETTING_OPERATION => 'strtoupper',
];
$plugin = new ConvertCase($config, 'convert_case', [], $this
->getMockSourceDefinition());
$this
->assertEquals('FOO BAR', $plugin
->tamper('foo bar'));
}
public function testUpperCaseWithMultipleValues() {
$this
->expectException(TamperException::class);
$this
->expectExceptionMessage('Input should be a string.');
$config = [
ConvertCase::SETTING_OPERATION => 'strtoupper',
];
$plugin = new ConvertCase($config, 'convert_case', [], $this
->getMockSourceDefinition());
$plugin
->tamper([
'foo',
'bar',
]);
}
public function testLowerCaseWithSingleValue() {
$config = [
ConvertCase::SETTING_OPERATION => 'strtolower',
];
$plugin = new ConvertCase($config, 'convert_case', [], $this
->getMockSourceDefinition());
$this
->assertEquals('foo bar', $plugin
->tamper('fOo BAR'));
}
public function testLowerCaseWithMultipleValues() {
$this
->expectException(TamperException::class);
$this
->expectExceptionMessage('Input should be a string.');
$config = [
ConvertCase::SETTING_OPERATION => 'strtolower',
];
$plugin = new ConvertCase($config, 'convert_case', [], $this
->getMockSourceDefinition());
$plugin
->tamper([
'fOo',
'BAR',
]);
}
public function testUpperCaseFirstWithSingleValue() {
$config = [
ConvertCase::SETTING_OPERATION => 'ucfirst',
];
$plugin = new ConvertCase($config, 'convert_case', [], $this
->getMockSourceDefinition());
$this
->assertEquals('Foo bar', $plugin
->tamper('foo bar'));
}
public function testUpperCaseFirstWithMultipleValues() {
$this
->expectException(TamperException::class);
$this
->expectExceptionMessage('Input should be a string.');
$config = [
ConvertCase::SETTING_OPERATION => 'ucfirst',
];
$plugin = new ConvertCase($config, 'convert_case', [], $this
->getMockSourceDefinition());
$plugin
->tamper([
'foo bar',
'baz zip',
]);
}
public function testLowerCaseFirstWithSingleValue() {
$config = [
ConvertCase::SETTING_OPERATION => 'lcfirst',
];
$plugin = new ConvertCase($config, 'convert_case', [], $this
->getMockSourceDefinition());
$this
->assertEquals('fOO BAR', $plugin
->tamper('FOO BAR'));
}
public function testLowerCaseFirstWithMultipleValues() {
$this
->expectException(TamperException::class);
$this
->expectExceptionMessage('Input should be a string.');
$config = [
ConvertCase::SETTING_OPERATION => 'lcfirst',
];
$plugin = new ConvertCase($config, 'convert_case', [], $this
->getMockSourceDefinition());
$plugin
->tamper([
'FOO',
'BAR',
]);
}
public function testUpperCaseWordsWithSingleValue() {
$config = [
ConvertCase::SETTING_OPERATION => 'ucwords',
];
$plugin = new ConvertCase($config, 'convert_case', [], $this
->getMockSourceDefinition());
$this
->assertEquals('Foo Bar', $plugin
->tamper('foo bar'));
}
public function testUpperCaseWordsWithMultipleValues() {
$this
->expectException(TamperException::class);
$this
->expectExceptionMessage('Input should be a string.');
$config = [
ConvertCase::SETTING_OPERATION => 'ucwords',
];
$plugin = new ConvertCase($config, 'convert_case', [], $this
->getMockSourceDefinition());
$plugin
->tamper([
'foo bar',
'bar foo',
]);
}
}