While working on the Kill role IDs patch I had to develop some upgrade path Simpletests. Unfortunately the documentation for upgrade path tests currently lacks installtion instructions on how to work with the existing bare and filled exported test databases. Here is a small writeup of what I did until we document that properly.

The test databases are exported to executable PHP code and live in core/modules/simpletest/tests/upgrade (Drupal 8). The problem is that you needed a bootstrapped Drupal database system to run those statements and an empty database at the same time where you insert the data. So first you need to create a new, empty development environment - not only a new site in a multi-site setup in your usual development directory.

  • Checkout Drupal core (7.x in my case) in a separate directory, create a new database, setup your web server (this empty instance is called d7upgrade.localhost on my machine).
  • You will also need an existing Drupal 7/8 installation, you can just use any development site you already have (this instance is called drupal-8.localhost on my machine).
  • Extract the zipped drupal-7.bare.database.php.gz or drupal-7.filled.database.php.gz in drupal-8/core/modules/simpletest/tests/upgrade: gunzip drupal-7.bare.database.php.gz
  • Add database credentials for the d7upgrade database to settings.php of drupal-8.localhost: 'd7upgrade', 'username' => 'root', 'password' => '', 'host' => 'localhost', 'port' => '', 'driver' => 'mysql', 'prefix' => '', ); ?>
  • Create a small PHP script called import.php somewhere in drupal-8 that will insert the data to d7upgrade:
  • Execute the script with drush somewhere in drupal-8: drush php-script import.php
  • Now the d7upgrade database should be filled. Go to d7upgrade.localhost in your browser and install Drupal, after entering the database credentials you should get to an existing site.
  • Login as admin with user: drupal and password: drupal. Make changes to the installation that you need for your upgrade test (e.g. I added some user roles that I wanted to do tests with).
  • Export the modified database (you need to run that from the root of your d7upgrade installation): php scripts/dump-database-d7.sh > d7upgrade.php
  • Examine the differences of your export to the original export (note: you will see quite some unrelated changes as the original export may not be fully up to date): diff d7upgrade.php /home/klausi/workspace/drupal-8/core/modules/simpletest/tests/upgrade/drupal-7.bare.database.php | less
  • Copy your modifications to a separate PHP file, as for example done in drupal-7-language.php. By doing that you avoid to have another big full database export and you can reuse drupal-7.bare.database.php.gz or drupal-7.filled.database.php.gz in your UpgradePathTestCase::setUp() (see upgrade.language.test for an example).

Doing all this is ugly and I'm not sure this is the way it should be done. Leave a comment or contact me if you know better.