The drop is always movingYou know that saying about standing on the shoulders of giants? Drupal is standing on a huge pile of midgetsAll content management systems suck, Drupal just happens to suck less.Popular open source software is more secure than unpopular open source software, because insecure software becomes unpopular fast. [That doesn't happen for proprietary software.]Drupal makes sandwiches happen.There is a module for that

Breakthrough in unit testing on the Paris Code Sprint day 1

Submitted by nk on Sun, 2008-04-20 07:47

As numerous others are blogging about all that's done, I can concentrate on one thing: unit testing. As the unit testing plan on Drupal.org says

To perform unit testing each function needs to be isolated from all other functions. To do this all "sub calls" to other drupal functions need be located and each drupal function needs to be overridden to return a static value. The current plan is to use runkit.

. As we were discussing the how in Paris it hit me that we can do better: don't overwrite anything, instead create a skeleton-Drupal which copies all the functions but replaces the function body with a call to the test clearinghouse and then the clearinghouse can tell what's the current return value. I am unsure now who came up with the idea that when this script runs we can copy Drupal to an original-Drupal, where all functions are prefixed by original_. So we have functions like:

function variable_init($conf = array()) {
  return test_clearinghouse('variable_init', $conf);
}

and we also have:

function original_variable_init($conf = array()) {
  // NOTE: caching the variables improves performance by 20% when serving cached pages.
  if ($cached = cache_get('variables', 'cache')) {
...
}

Here is the beginning of the unit test for variable_init:

array(
    array(
      'incoming' => array('cache_get', 'variables', 'cache'),
      'return' => FALSE,
    ),
    array(
      'incoming' => array('db_query', 'SELECT * FROM {variable}'),
      'return' => '__test_placeholder__',
    ),
    array(
      'incoming' => array('db_fetch_object', '__test_placeholder__'),
      'return' => (object) array('name '=> 'foo', 'value' => serialize('bar')),
    ),
    array(
      'incoming' => array('db_fetch_object', '__test_placeholder__'),
      'return' => FALSE,
    ),
...
  );

So you just read the code flow and can create a test like this.

Commenting on this Story is closed.

Submitted by amazon@drupal.org on Sun, 2008-04-20 18:04.

The Drupal project is an amazing example of worldwide developer collaboration. It can seem counter productive to some to try to teak that model of remote collaboration.

We are now on Sprint four out of five in as many months, a big change for our development model. These kinds of breakthroughs help to justify why sprints are important for the Drupal project. Congratulations, I am looking forward to the results.

Cheers,
Kieran