validateHostname example


  public static function findSitePath(Request $request$require_settings = TRUE, $app_root = NULL) {
    if (static::validateHostname($request) === FALSE) {
      throw new BadRequestHttpException();
    }

    if ($app_root === NULL) {
      $app_root = static::guessApplicationRoot();
    }

    // Check for a test override.     if ($test_prefix = drupal_valid_test_ua()) {
      $test_db = new TestDatabase($test_prefix);
      return $test_db->getTestSitePath();
    }

class ValidateHostnameTest extends UnitTestCase {

  /** * @covers ::validateHostname * @dataProvider providerTestValidateHostname */
  public function testValidateHostname($hostname$message$expected = FALSE) {
    $server = ['HTTP_HOST' => $hostname];
    $request = new Request([][][][][]$server);
    $validated_hostname = DrupalKernel::validateHostname($request);
    $this->assertSame($expected$validated_hostname$message);
  }

  /** * Provides test data for testValidateHostname(). */
  public function providerTestValidateHostname() {
    $data = [];

    // Verifies that DrupalKernel::validateHostname() prevents invalid     // characters per RFC 952/2181.
Home | Imprint | This part of the site doesn't use cookies.