function NaturalSortTest::testExplicitLangcode
Tests comparing strings with an explicit language code.
Attributes
#[RequiresPhpExtension('intl')]
File
-
core/
tests/ Drupal/ Tests/ Core/ Utility/ NaturalSortTest.php, line 28
Class
Namespace
Drupal\Tests\Core\UtilityCode
public function testExplicitLangcode() : void {
// Numbers embedded in strings are compared by their numeric value.
$this->assertGreaterThan(0, NaturalSort::strnatcasecmp('Format 100x100', 'Format 10x10', 'en'));
$this->assertLessThan(0, NaturalSort::strnatcasecmp('Format 10x10', 'Format 100x100', 'en'));
$this->assertSame(0, NaturalSort::strnatcasecmp('Format 10x10', 'Format 10x10', 'en'));
// Accented characters are sorted by their base letter, unlike
// strnatcasecmp(), which sorts them after all ASCII characters.
$this->assertLessThan(0, NaturalSort::strnatcasecmp('Émission', 'Format', 'en'));
$this->assertGreaterThan(0, NaturalSort::strnatcasecmp('Format', 'Émission', 'en'));
// Comparing is case-insensitive for different letters.
$this->assertLessThan(0, NaturalSort::strnatcasecmp('apple', 'Banana', 'en'));
$this->assertGreaterThan(0, NaturalSort::strnatcasecmp('Banana', 'apple', 'en'));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.