You are here

protected function CoderUpgradeUnitTestCase::testRunInterface in Coder 7.2

Same name and namespace in other branches
  1. 7 coder_upgrade/coder_upgrade.test \CoderUpgradeUnitTestCase::testRunInterface()

Tests the upgrade routines (outside of the user interface).

File

coder_upgrade/coder_upgrade.test, line 114

Class

CoderUpgradeUnitTestCase
Unit tests for the upgrade routines.

Code

protected function testRunInterface() {
  file_put_contents('output.html', __METHOD__ . "\n", FILE_APPEND);
  $_coder_upgrade_replace_files = variable_get('coder_upgrade_replace_files', FALSE);
  if ($_coder_upgrade_replace_files) {
    $settings = l('here', 'admin/config/development/coder/upgrade/settings');
    $msg = "WARNING: Do not run this test if the \"Replace files\" option is checked for this module. Change this setting {$settings}.";
    $this
      ->assertFalse($_coder_upgrade_replace_files, $msg, 'Settings');
    return;
  }
  file_put_contents('output.html', __METHOD__ . "\n", FILE_APPEND);
  $module_dirname = DRUPAL_ROOT . '/' . drupal_get_path('module', 'coder_upgrade');
  $in_dirname = $module_dirname . '/tests/old/';
  $expected_dirname = $module_dirname . '/tests/new/';
  $out_dirname = DRUPAL_ROOT . '/' . coder_upgrade_directory_path('new');
  file_put_contents('output.html', "{$out_dirname}\n", FILE_APPEND);
  $upgrades = coder_upgrade_upgrade_info();
  $extensions = array(
    'inc' => TRUE,
    'info' => TRUE,
    'install' => TRUE,
    'module' => TRUE,
    'php' => FALSE,
    'profile' => FALSE,
    'test' => FALSE,
    'theme' => FALSE,
  );
  $directories = array(
    $this->test_directory => 1,
  );
  foreach ($directories as $key => $directory) {
    $items[] = array(
      'name' => $key,
      'old_dir' => $in_dirname . $key,
      'new_dir' => $out_dirname . $key,
    );
  }

  // If Drupal won't commit patch to DrupalUnitTestCase.php, then use a global.
  global $_coder_upgrade_is_test;
  $_coder_upgrade_is_test = TRUE;

  // Apply upgrade routines.
  module_load_include('inc', 'coder_upgrade', 'includes/main');
  if (coder_upgrade_start($upgrades, $extensions, $items)) {
  }
  $ignore = array(
    '.',
    '..',
    'CVS',
    '.svn',
  );

  // Loop on files.
  // TODO This needs to recurse if there are subdirectories.
  $filenames = scandir($in_dirname . $key . '/');
  cdp($filenames);
  foreach ($filenames as $filename) {
    if (in_array($filename, $ignore)) {
      continue;
    }

    // Set file names to be compared.
    $expected_filename = $expected_dirname . $key . '/' . $filename;
    $out_filename = $out_dirname . $key . '/' . $filename;
    coder_upgrade_debug_print("exp = {$expected_filename}");
    coder_upgrade_debug_print("out = {$out_filename}");

    // Compare upgraded file to expected file.
    $this
      ->compareFiles($expected_filename, $out_filename);
  }
}