I started work on porting simpletest to D6.
Attached patch fixes simpletest module to the point where tests can be run and resulsts dispayed.
I will work on fixing tests later this week.

Comments

Rok Žlender’s picture

Assigned: Unassigned » Rok Žlender
Status: Needs work » Needs review
StatusFileSize
new14.43 KB

This patch fixes all tests. There really was not much to do.

- this http://drupal.org/node/154216 has to be committed for profile tests to work
- image module is not yet ported to D6 and I couldn't look into fixing tests

If someone can try it out and let me know if everything is green.

mrharolda’s picture

Rok,

I've downloaded the CVS version of the simpletest module, applied 'simpletest.d6port.patch', downloaded simpeltest from sourceforge and added it to the simpletest module dir with the following result in the 'Simpletest unit testing' menu item:

Fatal error: Call to undefined method DrupalUnitTests::_requireWithError() in /var/www/d6/drupal/sites/all/modules/simpletest/drupal_unit_tests.php on line 42

My bad or bug?

-H-

Rok Žlender’s picture

Thanks for trying out my patch. Its not your bad its rather an unresolved issue http://drupal.org/node/160859 . Hope this helps.

mrharolda’s picture

That sure helps!

I'd reckon that most tests aren't ported to Drupal 6 yet? A lot of the tests fail, even on a 'clean' checkout of Drupal 6...

-H-

Rok Žlender’s picture

Well at the time I posted my patch everything was green. But since D6 is moving target things probably changed. So please if you can help out and post a patch that fixes the tests.

mrharolda’s picture

This is my first encounter with unit tests. I'm currently researching tools/methods to perform tests through a cron job.

Simpletest looks very promising, except for the fact that the Drupal module depends on a slightly older version...

If I encounter any (easy) fixable bugs, I'll surely report them here...

-H-

mrharolda’s picture

Ehm, how can I launch a test from the CLI? Or is this not possible?

mrharolda’s picture

Title: Port simpletest to 6.x » CLI testing
StatusFileSize
new1.15 KB

I've cooked up the following script to run tests from the command line:

require_once(dirname(__FILE__) . '/../../../../includes/bootstrap.inc');
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

require_once(dirname(__FILE__) . '/simpletest/compatibility.php');
require_once(dirname(__FILE__) . '/simpletest/browser.php');
require_once(dirname(__FILE__) . '/simpletest/web_tester.php');
require_once(dirname(__FILE__) . '/simpletest/unit_tester.php');
require_once(dirname(__FILE__) . '/simpletest.module');
require_once(dirname(__FILE__) . '/drupal_test_case.php');
require_once(dirname(__FILE__) . '/drupal_unit_tests.php');
require_once(dirname(__FILE__) . '/drupal_reporter.php');

if ((preg_match("/^test=/", $argv[1])) and (preg_match("/^url=/", $argv[2]))) {
  $sTests = preg_replace("/^test=/","",$argv[1]); // remove 'test=' part
  $aTests = explode(",",$sTests); // cast into an array
  
  $sCLI_URL = preg_replace("/^url=/","",$argv[2]); // remove 'url=' part
  if (!preg_match("/\/$/", $sCLI_URL)) $sCLI_URL.="/"; // add missing trailing slash
  
  $output = simpletest_run_tests($aTests);
  simpletest_running_output($output);
}
else {
  die ("\nUsage:\n\tphp ".$argv[0]." test=\"Test 1[,Test 2]\" url=http://localhost/drupal_path/\n\n");
}

I've named it "simpletest_cli.php" and put it the Simpletest module directory (sites/all/modules/simpletest/simpletest_cli.php)

When running Drupal from the CLI, the url() function doesn't create a 'http://' like url. Use this ugly hack to get tests working again.

Edit 'drupal_test_case.php' around line 104:

function drupalPostRequest($path, $edit = array(), $submit, $edit_multi = array()) {
  global $sCLI_URL;
  if (isset($sCLI_URL))
    $url = $sCLI_URL.$path;
  else
    $url = url($path, array('absolute' => TRUE));

I've got little Drupal experience, so please tell me if I'm totally wrong on this one...

-H-

Rok Žlender’s picture

Title: CLI testing » Port simpletest to 6.x

Please don't change title of the issue.

There is already a CLI version of simpletest "run_all_tests.php". If you have special needs use that one to build on.

moshe weitzman’s picture

rok - we may not need that script anymore in D6 version. instead, we could ask folks to use the new /scripts/drupal.sh with the right url (we might need to build this callback). i didn't look at run_all_tests, so i might be wrong on this.

mrharolda’s picture

I might be wrong on this, but doesn't the drupal.sh output formatted (=html) text?

As for "run_all_tests.php", it has 'require_once' issues, I doubt that it handles url's correctly, and it isn't possible to specify a specific test, so I'm sticking with my own script for the moment.

If time permits, I'll try to fix some tests on D6 once I've fully mastered the art of testing...

Cheers!

-H-

PS: I wasn't aware that I could change the title of the issue, I thought it was the title of my own post... Sorry 'bout that...

mrharolda’s picture

StatusFileSize
new9.93 KB

I've attached a patch that fixes all tests (except for the 'Image Module' test) on a fresh checkout of Drupal 6. Basically, all the 'Submit' buttons are replaced by 'Save' buttons...

Current test result: 443 passes, 0 fails and 0 exceptions.

-H-

pwolanin’s picture

StatusFileSize
new23.06 KB

This patch combines the above two so that it can be applied in one go.

pwolanin’s picture

StatusFileSize
new23.75 KB

Patch updated for the removal from the DB API of db_num_rows().

Seems to work now.

chx’s picture

StatusFileSize
new24.42 KB

I added an 'administer users' permission to single profile field testing. That helped -- we did not need to test profile for D6 beta. I love simpletest.

Rok Žlender’s picture

Status: Needs review » Fixed

Commited to HEAD. Thanks everyone for helping out.

Anonymous’s picture

Status: Fixed » Closed (fixed)