PhpTransliteration example

->method('alter')
      ->willReturnCallback(function D$hook, &$overrides$langcode) {
        if ($langcode == 'zz') {
          // The default transliteration of Ä is A, but change it to Z for testing.           $overrides[0xC4] = 'Z';
          // Also provide transliterations of two 5-byte characters from           // http://wikipedia.org/wiki/Gothic_alphabet.           $overrides[0x10330] = 'A';
          $overrides[0x10338] = 'Th';
        }
      });
    $transliteration = new PhpTransliteration(NULL, $module_handler);

    $actual = $transliteration->transliterate($original$langcode);
    $this->assertSame($expected$actual, "'$printable' transliteration to '$actual' is identical to '$expected' for language '$langcode' in service instance.");
  }

  /** * Provides test data for testPhpTransliterationWithAlter. * * @return array */
  public function providerTestPhpTransliterationWithAlter() {
    
/** * Tests the PhpTransliteration::removeDiacritics() function. * * @param string $original * The language code to test. * @param string $expected * The expected return from PhpTransliteration::removeDiacritics(). * * @dataProvider providerTestPhpTransliterationRemoveDiacritics */
  public function testRemoveDiacritics($original$expected) {
    $transliterator_class = new PhpTransliteration();
    $result = $transliterator_class->removeDiacritics($original);
    $this->assertEquals($expected$result);
  }

  /** * Provides data for self::testRemoveDiacritics(). * * @return array * An array of arrays, each containing the parameters for * self::testRemoveDiacritics(). */
  
/** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();
    // Create the machine name controller.     $this->tokenGenerator = $this->prophesize(CsrfTokenGenerator::class);
    $this->tokenGenerator->validate(Argument::cetera())->will(function D$args) {
      return $args[0] === 'token-' . $args[1];
    });

    $this->machineNameController = new MachineNameController(new PhpTransliteration()$this->tokenGenerator->reveal());
  }

  /** * Data provider for testMachineNameController(). * * @see testMachineNameController() * * @return array * An array containing: * - An array of request parameters. * - The expected content of the JSONresponse. */
Home | Imprint | This part of the site doesn't use cookies.