You are here

class NameUnicodeExtrasTest in Name Field 8

Tests the unicode additional functions.

@group name

Hierarchy

Expanded class hierarchy of NameUnicodeExtrasTest

File

tests/src/Unit/NameUnicodeExtrasTest.php, line 13

Namespace

Drupal\Tests\name\Unit
View source
class NameUnicodeExtrasTest extends UnitTestCase {

  /**
   * {@inheritdoc}
   */
  public static function getInfo() {
    return [
      'name' => 'NameUnicodeExtras Test',
      'description' => 'Test NameUnicodeExtras additional functions',
      'group' => 'Name',
    ];
  }

  /**
   * Convert names() to PHPUnit compatible format.
   *
   * @return array
   *   An array of names.
   */
  public function patternDataProvider() {
    $data = [];
    foreach ($this
      ->languageStrings() as $language => $info) {
      $data[] = [
        $language,
        $info['string'],
        $info['count'],
        $info['initials'],
      ];
    }
    return $data;
  }

  /**
   * Test NameUnicodeExtras functions.
   *
   * @dataProvider patternDataProvider
   */
  public function testNameUnicodeExtras($language, $text, $count, $expected_initials) {
    $parts = NameUnicodeExtras::explode($text);
    $initials = NameUnicodeExtras::initials($text);
    $this
      ->assertEquals(count($parts), $count, 'Count parts for ' . $language . ' explode match.');
    $this
      ->assertEquals($initials, $expected_initials, 'Initials for ' . $language . ' explode match. ' . $initials . ' ');
  }

  /**
   * Helper function to provide data for the tests.
   *
   * @return array
   *   A keyed array of test data in misc languages.
   */
  protected function languageStrings() {
    return [
      'english' => [
        'string' => 'A fat cat sat on the mat',
        'count' => 7,
        'initials' => 'AFCSOTM',
      ],
      'greek' => [
        'string' => 'Σὲ γνωρίζω ἀπὸ τὴν κόψη',
        'count' => 5,
        'initials' => 'ΣΓἈΤΚ',
      ],
      'georgian' => [
        'string' => 'გთხოვთ ახლავე გაიაროთ რეგისტრაცია',
        'count' => 4,
        'initials' => 'გაგრ',
      ],
      'russian' => [
        'string' => 'Зарегистрируйтесь сейчас на Десятую Международную Конференцию',
        'count' => 6,
        'initials' => 'ЗСНДМК',
      ],
      'ethiopian' => [
        'string' => 'ሰማይ አይታረስ ንጉሥ አይከሰስ',
        'count' => 4,
        'initials' => 'ሰአንአ',
      ],
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
NameUnicodeExtrasTest::getInfo public static function
NameUnicodeExtrasTest::languageStrings protected function Helper function to provide data for the tests.
NameUnicodeExtrasTest::patternDataProvider public function Convert names() to PHPUnit compatible format.
NameUnicodeExtrasTest::testNameUnicodeExtras public function Test NameUnicodeExtras functions.
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.
UnitTestCase::setUp protected function 340