You are here

public function MachineNameControllerTest::providerTestMachineNameController in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/tests/src/Unit/Transliteration/MachineNameControllerTest.php \Drupal\Tests\system\Unit\Transliteration\MachineNameControllerTest::providerTestMachineNameController()

Data provider for testMachineNameController().

Return value

array An array containing:

  • An array of request parameters.
  • The expected content of the JSONresponse.

See also

testMachineNameController()

File

core/modules/system/tests/src/Unit/Transliteration/MachineNameControllerTest.php, line 45
Contains \Drupal\Tests\system\Unit\Transliteration\MachineNameControllerTest.

Class

MachineNameControllerTest
Tests that the machine name controller can transliterate strings as expected.

Namespace

Drupal\Tests\system\Unit\Transliteration

Code

public function providerTestMachineNameController() {
  return array(
    array(
      array(
        'text' => 'Bob',
        'langcode' => 'en',
      ),
      '"Bob"',
    ),
    array(
      array(
        'text' => 'Bob',
        'langcode' => 'en',
        'lowercase' => TRUE,
      ),
      '"bob"',
    ),
    array(
      array(
        'text' => 'Bob',
        'langcode' => 'en',
        'replace' => 'Alice',
        'replace_pattern' => 'Bob',
      ),
      '"Alice"',
    ),
    array(
      array(
        'text' => 'Bob',
        'langcode' => 'en',
        'replace' => 'Alice',
        'replace_pattern' => 'Tom',
      ),
      '"Bob"',
    ),
    array(
      array(
        'text' => 'Äwesome',
        'langcode' => 'en',
        'lowercase' => TRUE,
      ),
      '"awesome"',
    ),
    array(
      array(
        'text' => 'Äwesome',
        'langcode' => 'de',
        'lowercase' => TRUE,
      ),
      '"aewesome"',
    ),
    // Tests special characters replacement in the input text.
    array(
      array(
        'text' => 'B?!"@\\/-ob@e',
        'langcode' => 'en',
        'lowercase' => TRUE,
        'replace' => '_',
        'replace_pattern' => '[^a-z0-9_.]+',
      ),
      '"b_ob_e"',
    ),
    // Tests @ character in the replace_pattern regex.
    array(
      array(
        'text' => 'Bob@e\\0',
        'langcode' => 'en',
        'lowercase' => TRUE,
        'replace' => '_',
        'replace_pattern' => '[^a-z0-9_.@]+',
      ),
      '"bob@e_0"',
    ),
    // Tests null byte in the replace_pattern regex.
    array(
      array(
        'text' => 'Bob',
        'langcode' => 'en',
        'lowercase' => TRUE,
        'replace' => 'fail()',
        'replace_pattern' => ".*@e\0",
      ),
      '"bob"',
    ),
    array(
      array(
        'text' => 'Bob@e',
        'langcode' => 'en',
        'lowercase' => TRUE,
        'replace' => 'fail()',
        'replace_pattern' => ".*@e\0",
      ),
      '"fail()"',
    ),
  );
}