Project

General

Profile

Revision b0dc3a2e

Added by Julien Enselme over 7 years ago

Update to Drupal 7.52

View differences:

drupal7/modules/simpletest/tests/system_test.module
127 127
    'type' => MENU_CALLBACK,
128 128
  );
129 129

  
130
  $items['system-test/drupal-get-filename'] = array(
131
    'title' => 'Test drupal_get_filename()',
132
    'page callback' => 'system_test_drupal_get_filename',
133
    'access callback' => TRUE,
134
    'type' => MENU_CALLBACK,
135
  );
136

  
137
  $items['system-test/drupal-get-filename-with-schema-rebuild'] = array(
138
    'title' => 'Test drupal_get_filename() with a schema rebuild',
139
    'page callback' => 'system_test_drupal_get_filename_with_schema_rebuild',
140
    'access callback' => TRUE,
141
    'type' => MENU_CALLBACK,
142
  );
143

  
130 144
  return $items;
131 145
}
132 146

  
......
482 496
  // information.
483 497
  exit;
484 498
}
499

  
500
/**
501
 * Page callback to run drupal_get_filename() on a particular module.
502
 */
503
function system_test_drupal_get_filename() {
504
  // Prevent SimpleTest from failing as a result of the expected PHP warnings
505
  // this function causes. Any warnings will be recorded in the database logs
506
  // for examination by the tests.
507
  define('SIMPLETEST_COLLECT_ERRORS', FALSE);
508

  
509
  $module_name = variable_get('system_test_drupal_get_filename_test_module_name');
510
  drupal_get_filename('module', $module_name);
511

  
512
  return '';
513
}
514

  
515
/**
516
 * Page callback to run drupal_get_filename() and do a schema rebuild.
517
 */
518
function system_test_drupal_get_filename_with_schema_rebuild() {
519
  // Prevent SimpleTest from failing as a result of the expected PHP warnings
520
  // this function causes.
521
  define('SIMPLETEST_COLLECT_ERRORS', FALSE);
522

  
523
  // Record the original database tables from drupal_get_schema().
524
  variable_set('system_test_drupal_get_filename_with_schema_rebuild_original_tables', array_keys(drupal_get_schema(NULL, TRUE)));
525

  
526
  // Trigger system_test_schema() and system_test_watchdog() to perform an
527
  // attempted recursive rebuild when drupal_get_schema() is called. See
528
  // BootstrapGetFilenameWebTestCase::testRecursiveRebuilds().
529
  variable_set('system_test_drupal_get_filename_attempt_recursive_rebuild', TRUE);
530
  drupal_get_schema(NULL, TRUE);
531

  
532
  return '';
533
}
534

  
535
/**
536
 * Implements hook_watchdog().
537
 */
538
function system_test_watchdog($log_entry) {
539
  // If an attempted recursive schema rebuild has been triggered by
540
  // system_test_drupal_get_filename_with_schema_rebuild(), perform the rebuild
541
  // in response to the missing file message triggered by system_test_schema().
542
  if (!variable_get('system_test_drupal_get_filename_attempt_recursive_rebuild')) {
543
    return;
544
  }
545
  if ($log_entry['type'] != 'php' || $log_entry['severity'] != WATCHDOG_WARNING) {
546
    return;
547
  }
548
  $module_name = variable_get('system_test_drupal_get_filename_test_module_name');
549
  if (!isset($log_entry['variables']['!message']) || strpos($log_entry['variables']['!message'], format_string('The following module is missing from the file system: %name', array('%name' => $module_name))) === FALSE) {
550
    return;
551
  }
552
  variable_set('system_test_drupal_get_filename_with_schema_rebuild_final_tables', array_keys(drupal_get_schema()));
553
}
554

  
555
/**
556
 * Implements hook_module_implements_alter().
557
 */
558
function system_test_module_implements_alter(&$implementations, $hook) {
559
  // For BootstrapGetFilenameWebTestCase::testRecursiveRebuilds() to work
560
  // correctly, this module's hook_schema() implementation cannot be either the
561
  // first implementation (since that would trigger a potential recursive
562
  // rebuild before anything is in the drupal_get_schema() cache) or the last
563
  // implementation (since that would trigger a potential recursive rebuild
564
  // after the cache is already complete). So put it somewhere in the middle.
565
  if ($hook == 'schema') {
566
    $group = $implementations['system_test'];
567
    unset($implementations['system_test']);
568
    $count = count($implementations);
569
    $implementations = array_merge(array_slice($implementations, 0, $count / 2, TRUE), array('system_test' => $group), array_slice($implementations, $count / 2, NULL, TRUE));
570
  }
571
}

Also available in: Unified diff