UtilityTest.php in Menu Item Extras 8.2
File
tests/src/Unit/UtilityTest.php
View source
<?php
namespace Drupal\Tests\menu_item_extras\Unit;
use Drupal\menu_item_extras\Utility\Utility;
use Drupal\Tests\UnitTestCase;
class UtilityTest extends UnitTestCase {
public function testSanitizeMachineName() {
$matrix = [
'test_1_suggestion_' => 'test-1.suggestion ',
'test__2__suggestion' => 'test -2- suggestion*',
'test__3__suggestion' => 'tes!t_-_-_ @# - -3- =%---/ suggestion*',
];
foreach ($matrix as $expected => $input) {
$this
->assertEquals($expected, Utility::sanitizeMachineName($input), "\"{$input}\" sanitized not properly");
}
}
public function testSuggestion() {
$this
->assertEquals('one__two__three', Utility::suggestion('one', 'two', 'three'));
$this
->assertEquals('one', Utility::suggestion('one'));
}
public function testSanitizedSuggestion() {
$this
->assertEquals('one__two__three', Utility::suggestion(Utility::sanitizeMachineName('one!@#$!#'), Utility::sanitizeMachineName('t!@#$w!@#$@!o_'), Utility::sanitizeMachineName('___three')));
}
}