Make your own test.php file

Benjamin Melançon's picture
Submitted by Benjamin Melançon on 2010, October 22 - 13:18
  • Chx tip via Chad Phillips (hunmonk) at DrupalCon Boston 2008 (updated to Drupal 7).

    Make your own test scripts.

    Require the first three lines of index.php, and you have a fully bootstrapped Drupal.

    Make a file called test.php or anything you like and keep that in the same folder as index.php.

    Here is an example that prints out all the configuration information available to Drupal:

    <?php
    define
    ('DRUPAL_ROOT', getcwd());

    require_once

    DRUPAL_ROOT . '/includes/bootstrap.inc';
    drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

    drupal_test();
    function
    drupal_test() {
      global
    $conf;
      print
    '<pre>';
     
    var_export($conf);
      print
    '</pre>';
    }
    ?>

    But we can test out any function here (not hook implementations, however) without needing to create and enable a module.

    Other tips from chx via hunmonk:
    "As soon as you get in trouble start looking at your variables."

    use Exit.

    Find an example in core. Ask in channel (#drupal, #drupal-contribute) for an example of how to do x in core.

    Clear your cache.

    Document your work. [Because when you come back in a week, or a year, you won't have any idea what you thought you were doing.]

  • Book element

  • Tip