Skip to content
Snippets Groups Projects
Commit 14f105fc authored by Sonny Kieu's avatar Sonny Kieu Committed by Jo Fitzgerald
Browse files

Issue #3280023 Added "Lowercase plugin" and unit test.

parent 46dbcbd1
No related branches found
No related tags found
1 merge request!1Issue #3280023 Added "Lowercase plugin" and unit test.
<?php
namespace Drupal\token_modifier\Plugin\token_modifier;
use Drupal\token_modifier\Plugin\TokenModifierPluginBase;
/**
* Makes all characters of the token lowercase.
*
* @TokenModifier(
* id = "lowercase",
* name = @Translation("Lowercase"),
* description = @Translation("Lowercase the returned string.")
* )
*/
class Lowercase extends TokenModifierPluginBase {
/**
* {@inheritdoc}
*/
public function transform(string $text, array $data = [], array $options = []) {
return strtolower($this->token->replace($text, $data, $options));
}
}
<?php
namespace Drupal\Tests\token_modifier\Unit;
use Drupal\token_modifier\Plugin\token_modifier\Lowercase;
class LowercaseTest extends TokenModifierTestCase {
/**
* Tests the Lowercase token modifier.
*
* @param string $value
* The source value for the modifier.
* @param string $expected
* The expected result.
*
* @covers ::transform
*
* @dataProvider providerTestTransform
*/
public function testTransform(string $value, string $expected) {
$plugin = new Lowercase([], 'lowercase', [], $this->token);
$actual = $plugin->transform($value);
$this->assertSame($expected, $actual);
}
/**
* Provides data for testTransform.
*/
public function providerTestTransform(): array {
$data['basic'] = ['Hello World!', 'hello world!'];
$data['already lowercased'] = ['working?', 'working?'];
$data['capitalised'] = ['CAPITALISED', 'capitalised'];
return $data;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment