Project

General

Profile

Revision b0dc3a2e

Added by Julien Enselme over 7 years ago

Update to Drupal 7.52

View differences:

drupal7/modules/simpletest/tests/bootstrap.test
70 70
      'Proxy forwarding with trusted proxy got forwarded IP address.'
71 71
    );
72 72

  
73
    // Proxy forwarding on and proxy address trusted and visiting from proxy.
74
    $_SERVER['REMOTE_ADDR'] = $this->proxy_ip;
75
    $_SERVER['HTTP_X_FORWARDED_FOR'] = $this->proxy_ip;
76
    drupal_static_reset('ip_address');
77
    $this->assertTrue(
78
      ip_address() == $this->proxy_ip,
79
      'Visiting from trusted proxy got proxy IP address.'
80
    );
81

  
73 82
    // Multi-tier architecture with comma separated values in header.
74 83
    $_SERVER['REMOTE_ADDR'] = $this->proxy_ip;
75 84
    $_SERVER['HTTP_X_FORWARDED_FOR'] = implode(', ', array($this->untrusted_ip, $this->forwarded_ip, $this->proxy2_ip));
......
191 200
    $this->drupalGet('system-test/set-header', array('query' => array('name' => 'Foo', 'value' => 'bar')));
192 201
    $this->assertFalse($this->drupalGetHeader('X-Drupal-Cache'), 'Caching was bypassed.');
193 202
    $this->assertTrue(strpos($this->drupalGetHeader('Vary'), 'Cookie') === FALSE, 'Vary: Cookie header was not sent.');
194
    $this->assertEqual($this->drupalGetHeader('Cache-Control'), 'no-cache, must-revalidate, post-check=0, pre-check=0', 'Cache-Control header was sent.');
203
    $this->assertEqual($this->drupalGetHeader('Cache-Control'), 'no-cache, must-revalidate', 'Cache-Control header was sent.');
195 204
    $this->assertEqual($this->drupalGetHeader('Expires'), 'Sun, 19 Nov 1978 05:00:00 GMT', 'Expires header was sent.');
196 205
    $this->assertEqual($this->drupalGetHeader('Foo'), 'bar', 'Custom header was sent.');
197 206

  
......
379 388

  
380 389
  public static function getInfo() {
381 390
    return array(
382
      'name' => 'Get filename test',
383
      'description' => 'Test that drupal_get_filename() works correctly when the file is not found in the database.',
391
      'name' => 'Get filename test (without the system table)',
392
      'description' => 'Test that drupal_get_filename() works correctly when the database is not available.',
384 393
      'group' => 'Bootstrap',
385 394
    );
386 395
  }
387 396

  
397
  /**
398
   * The last file-related error message triggered by the filename test.
399
   *
400
   * Used by BootstrapGetFilenameTestCase::testDrupalGetFilename().
401
   */
402
  protected $getFilenameTestTriggeredError;
403

  
388 404
  /**
389 405
   * Test that drupal_get_filename() works correctly when the file is not found in the database.
390 406
   */
......
414 430
    // automatically check there for 'script' files, just as it does for (e.g.)
415 431
    // 'module' files in modules.
416 432
    $this->assertIdentical(drupal_get_filename('script', 'test'), 'scripts/test.script', t('Retrieve test script location.'));
433

  
434
    // When searching for a module that does not exist, drupal_get_filename()
435
    // should return NULL and trigger an appropriate error message.
436
    $this->getFilenameTestTriggeredError = NULL;
437
    set_error_handler(array($this, 'fileNotFoundErrorHandler'));
438
    $non_existing_module = $this->randomName();
439
    $this->assertNull(drupal_get_filename('module', $non_existing_module), 'Searching for a module that does not exist returns NULL.');
440
    $this->assertTrue(strpos($this->getFilenameTestTriggeredError, format_string('The following module is missing from the file system: %name', array('%name' => $non_existing_module))) === 0, 'Searching for an item that does not exist triggers the correct error.');
441
    restore_error_handler();
442

  
443
    // Check that the result is stored in the file system scan cache.
444
    $file_scans = _drupal_file_scan_cache();
445
    $this->assertIdentical($file_scans['module'][$non_existing_module], FALSE, 'Searching for a module that does not exist creates a record in the missing and moved files static variable.');
446

  
447
    // Performing the search again in the same request still should not find
448
    // the file, but the error message should not be repeated (therefore we do
449
    // not override the error handler here).
450
    $this->assertNull(drupal_get_filename('module', $non_existing_module), 'Searching for a module that does not exist returns NULL during the second search.');
451
  }
452

  
453
  /**
454
   * Skips handling of "file not found" errors.
455
   */
456
  public function fileNotFoundErrorHandler($error_level, $message, $filename, $line, $context) {
457
    // Skip error handling if this is a "file not found" error.
458
    if (strpos($message, 'is missing from the file system:') !== FALSE || strpos($message, 'has moved within the file system:') !== FALSE) {
459
      $this->getFilenameTestTriggeredError = $message;
460
      return;
461
    }
462
    _drupal_error_handler($error_level, $message, $filename, $line, $context);
463
  }
464
}
465

  
466
/**
467
 * Test drupal_get_filename() in the context of a full Drupal installation.
468
 */
469
class BootstrapGetFilenameWebTestCase extends DrupalWebTestCase {
470

  
471
  public static function getInfo() {
472
    return array(
473
      'name' => 'Get filename test (full installation)',
474
      'description' => 'Test that drupal_get_filename() works correctly in the context of a full Drupal installation.',
475
      'group' => 'Bootstrap',
476
    );
477
  }
478

  
479
  function setUp() {
480
    parent::setUp('system_test');
481
  }
482

  
483
  /**
484
   * The last file-related error message triggered by the filename test.
485
   *
486
   * Used by BootstrapGetFilenameWebTestCase::testDrupalGetFilename().
487
   */
488
  protected $getFilenameTestTriggeredError;
489

  
490
  /**
491
   * Test that drupal_get_filename() works correctly with a full Drupal site.
492
   */
493
  function testDrupalGetFilename() {
494
    // Search for a module that exists in the file system and the {system}
495
    // table and make sure that it is found.
496
    $this->assertIdentical(drupal_get_filename('module', 'node'), 'modules/node/node.module', 'Module found at expected location.');
497

  
498
    // Search for a module that does not exist in either the file system or the
499
    // {system} table. Make sure that an appropriate error is triggered and
500
    // that the module winds up in the static and persistent cache.
501
    $this->getFilenameTestTriggeredError = NULL;
502
    set_error_handler(array($this, 'fileNotFoundErrorHandler'));
503
    $non_existing_module = $this->randomName();
504
    $this->assertNull(drupal_get_filename('module', $non_existing_module), 'Searching for a module that does not exist returns NULL.');
505
    $this->assertTrue(strpos($this->getFilenameTestTriggeredError, format_string('The following module is missing from the file system: %name', array('%name' => $non_existing_module))) === 0, 'Searching for a module that does not exist triggers the correct error.');
506
    restore_error_handler();
507
    $file_scans = _drupal_file_scan_cache();
508
    $this->assertIdentical($file_scans['module'][$non_existing_module], FALSE, 'Searching for a module that does not exist creates a record in the missing and moved files static variable.');
509
    drupal_file_scan_write_cache();
510
    $cache = cache_get('_drupal_file_scan_cache', 'cache_bootstrap');
511
    $this->assertIdentical($cache->data['module'][$non_existing_module], FALSE, 'Searching for a module that does not exist creates a record in the missing and moved files persistent cache.');
512

  
513
    // Simulate moving a module to a location that does not match the location
514
    // in the {system} table and perform similar tests as above.
515
    db_update('system')
516
      ->fields(array('filename' => 'modules/simpletest/tests/fake_location/module_test.module'))
517
      ->condition('name', 'module_test')
518
      ->condition('type', 'module')
519
      ->execute();
520
    $this->getFilenameTestTriggeredError = NULL;
521
    set_error_handler(array($this, 'fileNotFoundErrorHandler'));
522
    $this->assertIdentical(drupal_get_filename('module', 'module_test'), 'modules/simpletest/tests/module_test.module', 'Searching for a module that has moved finds the module at its new location.');
523
    $this->assertTrue(strpos($this->getFilenameTestTriggeredError, format_string('The following module has moved within the file system: %name', array('%name' => 'module_test'))) === 0, 'Searching for a module that has moved triggers the correct error.');
524
    restore_error_handler();
525
    $file_scans = _drupal_file_scan_cache();
526
    $this->assertIdentical($file_scans['module']['module_test'], 'modules/simpletest/tests/module_test.module', 'Searching for a module that has moved creates a record in the missing and moved files static variable.');
527
    drupal_file_scan_write_cache();
528
    $cache = cache_get('_drupal_file_scan_cache', 'cache_bootstrap');
529
    $this->assertIdentical($cache->data['module']['module_test'], 'modules/simpletest/tests/module_test.module', 'Searching for a module that has moved creates a record in the missing and moved files persistent cache.');
530

  
531
    // Simulate a module that exists in the {system} table but does not exist
532
    // in the file system and perform similar tests as above.
533
    $non_existing_module = $this->randomName();
534
    db_update('system')
535
      ->fields(array('name' => $non_existing_module))
536
      ->condition('name', 'module_test')
537
      ->condition('type', 'module')
538
      ->execute();
539
    $this->getFilenameTestTriggeredError = NULL;
540
    set_error_handler(array($this, 'fileNotFoundErrorHandler'));
541
    $this->assertNull(drupal_get_filename('module', $non_existing_module), 'Searching for a module that exists in the system table but not in the file system returns NULL.');
542
    $this->assertTrue(strpos($this->getFilenameTestTriggeredError, format_string('The following module is missing from the file system: %name', array('%name' => $non_existing_module))) === 0, 'Searching for a module that exists in the system table but not in the file system triggers the correct error.');
543
    restore_error_handler();
544
    $file_scans = _drupal_file_scan_cache();
545
    $this->assertIdentical($file_scans['module'][$non_existing_module], FALSE, 'Searching for a module that exists in the system table but not in the file system creates a record in the missing and moved files static variable.');
546
    drupal_file_scan_write_cache();
547
    $cache = cache_get('_drupal_file_scan_cache', 'cache_bootstrap');
548
    $this->assertIdentical($cache->data['module'][$non_existing_module], FALSE, 'Searching for a module that exists in the system table but not in the file system creates a record in the missing and moved files persistent cache.');
549

  
550
    // Simulate a module that exists in the file system but not in the {system}
551
    // table and perform similar tests as above.
552
    db_delete('system')
553
      ->condition('name', 'common_test')
554
      ->condition('type', 'module')
555
      ->execute();
556
    system_list_reset();
557
    $this->getFilenameTestTriggeredError = NULL;
558
    set_error_handler(array($this, 'fileNotFoundErrorHandler'));
559
    $this->assertIdentical(drupal_get_filename('module', 'common_test'), 'modules/simpletest/tests/common_test.module', 'Searching for a module that does not exist in the system table finds the module at its actual location.');
560
    $this->assertTrue(strpos($this->getFilenameTestTriggeredError, format_string('The following module has moved within the file system: %name', array('%name' => 'common_test'))) === 0, 'Searching for a module that does not exist in the system table triggers the correct error.');
561
    restore_error_handler();
562
    $file_scans = _drupal_file_scan_cache();
563
    $this->assertIdentical($file_scans['module']['common_test'], 'modules/simpletest/tests/common_test.module', 'Searching for a module that does not exist in the system table creates a record in the missing and moved files static variable.');
564
    drupal_file_scan_write_cache();
565
    $cache = cache_get('_drupal_file_scan_cache', 'cache_bootstrap');
566
    $this->assertIdentical($cache->data['module']['common_test'], 'modules/simpletest/tests/common_test.module', 'Searching for a module that does not exist in the system table creates a record in the missing and moved files persistent cache.');
567
  }
568

  
569
  /**
570
   * Skips handling of "file not found" errors.
571
   */
572
  public function fileNotFoundErrorHandler($error_level, $message, $filename, $line, $context) {
573
    // Skip error handling if this is a "file not found" error.
574
    if (strpos($message, 'is missing from the file system:') !== FALSE || strpos($message, 'has moved within the file system:') !== FALSE) {
575
      $this->getFilenameTestTriggeredError = $message;
576
      return;
577
    }
578
    _drupal_error_handler($error_level, $message, $filename, $line, $context);
579
  }
580

  
581
  /**
582
   * Test that watchdog messages about missing files are correctly recorded.
583
   */
584
  public function testWatchdog() {
585
    // Search for a module that does not exist in either the file system or the
586
    // {system} table. Make sure that an appropriate warning is recorded in the
587
    // logs.
588
    $non_existing_module = $this->randomName();
589
    $query_parameters = array(
590
      ':type' => 'php',
591
      ':severity' => WATCHDOG_WARNING,
592
    );
593
    $this->assertEqual(db_query('SELECT COUNT(*) FROM {watchdog} WHERE type = :type AND severity = :severity', $query_parameters)->fetchField(), 0, 'No warning message appears in the logs before searching for a module that does not exist.');
594
    // Trigger the drupal_get_filename() call. This must be done via a request
595
    // to a separate URL since the watchdog() will happen in a shutdown
596
    // function, and so that SimpleTest can be told to ignore (and not fail as
597
    // a result of) the expected PHP warnings generated during this process.
598
    variable_set('system_test_drupal_get_filename_test_module_name', $non_existing_module);
599
    $this->drupalGet('system-test/drupal-get-filename');
600
    $message_variables = db_query('SELECT variables FROM {watchdog} WHERE type = :type AND severity = :severity', $query_parameters)->fetchCol();
601
    $this->assertEqual(count($message_variables), 1, 'A single warning message appears in the logs after searching for a module that does not exist.');
602
    $variables = reset($message_variables);
603
    $variables = unserialize($variables);
604
    $this->assertTrue(isset($variables['!message']) && strpos($variables['!message'], format_string('The following module is missing from the file system: %name', array('%name' => $non_existing_module))) !== FALSE, 'The warning message that appears in the logs after searching for a module that does not exist contains the expected text.');
605
  }
606

  
607
  /**
608
   * Test that drupal_get_filename() does not break recursive rebuilds.
609
   */
610
  public function testRecursiveRebuilds() {
611
    // Ensure that the drupal_get_filename() call due to a missing module does
612
    // not break the data returned by an attempted recursive rebuild. The code
613
    // path which is tested is as follows:
614
    // - Call drupal_get_schema().
615
    // - Within a hook_schema() implementation, trigger a drupal_get_filename()
616
    //   search for a nonexistent module.
617
    // - In the watchdog() call that results from that, trigger
618
    //   drupal_get_schema() again.
619
    // Without some kind of recursion protection, this could cause the second
620
    // drupal_get_schema() call to return incomplete results. This test ensures
621
    // that does not happen.
622
    $non_existing_module = $this->randomName();
623
    variable_set('system_test_drupal_get_filename_test_module_name', $non_existing_module);
624
    $this->drupalGet('system-test/drupal-get-filename-with-schema-rebuild');
625
    $original_drupal_get_schema_tables = variable_get('system_test_drupal_get_filename_with_schema_rebuild_original_tables');
626
    $final_drupal_get_schema_tables = variable_get('system_test_drupal_get_filename_with_schema_rebuild_final_tables');
627
    $this->assertTrue(!empty($original_drupal_get_schema_tables));
628
    $this->assertTrue(!empty($final_drupal_get_schema_tables));
629
    $this->assertEqual($original_drupal_get_schema_tables, $final_drupal_get_schema_tables);
417 630
  }
418 631
}
419 632

  

Also available in: Unified diff