TrimTest.php in Tamper 8
File
tests/src/Unit/Plugin/Tamper/TrimTest.php
View source
<?php
namespace Drupal\Tests\tamper\Unit\Plugin\Tamper;
use Drupal\tamper\Plugin\Tamper\Trim;
class TrimTest extends TamperPluginTestBase {
protected function instantiatePlugin() {
$config = [
Trim::SETTING_CHARACTER => '',
Trim::SETTING_SIDE => 'trim',
];
return new Trim($config, 'trim', [], $this
->getMockSourceDefinition());
}
public function testTrimLeftSide() {
$config = [
Trim::SETTING_CHARACTER => '',
Trim::SETTING_SIDE => 'ltrim',
];
$plugin = new Trim($config, 'trim', [], $this
->getMockSourceDefinition());
$this
->assertEquals('asdfasf ', $plugin
->tamper(' asdfasf '));
}
public function testTrimRightSide() {
$config = [
Trim::SETTING_CHARACTER => '',
Trim::SETTING_SIDE => 'rtrim',
];
$plugin = new Trim($config, 'trim', [], $this
->getMockSourceDefinition());
$this
->assertEquals(' asdfasf', $plugin
->tamper(' asdfasf '));
}
public function testTrimBothSides() {
$this
->assertEquals('asdfasf', $this->plugin
->tamper(' asdfasf '));
}
public function testTrimWithCharacterMask() {
$config = [
Trim::SETTING_CHARACTER => '$',
Trim::SETTING_SIDE => 'trim',
];
$plugin = new Trim($config, 'trim', [], $this
->getMockSourceDefinition());
$this
->assertEquals('asdfasf', $plugin
->tamper('$$asdfasf$$'));
}
}