Skip to content

Commit

Permalink
Specify paths in a way that survives the move from PSR-0 to PSR-4:
Browse files Browse the repository at this point in the history
- Use __DIR__ instead of drupal_get_path() to refer to other class files in the same directory.
- Use DRUPAL_ROOT instead of trying to determine it from __DIR__.
- If necessary, check whether to use ../../../.. or just ../.. to get to the module directory, by checking if a *.module file exists.
  • Loading branch information
donquixote committed Apr 22, 2014
1 parent 6b14065 commit 60834c2
Show file tree
Hide file tree
Showing 22 changed files with 30 additions and 27 deletions.
Expand Up @@ -40,7 +40,7 @@ public function setUp() {
parent::setUp();
$migration = entity_load('migration', 'd6_action_settings');
$dumps = array(
drupal_get_path('module', 'migrate_drupal') . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6ActionSettings.php',
dirname(__DIR__) . '/Dump/Drupal6ActionSettings.php',
);
$this->prepare($migration, $dumps);
$executable = new MigrateExecutable($migration, $this);
Expand Down
Expand Up @@ -40,7 +40,7 @@ public function setUp() {
parent::setUp();
$migration = entity_load('migration', 'd6_aggregator_settings');
$dumps = array(
drupal_get_path('module', 'migrate_drupal') . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6AggregatorSettings.php',
dirname(__DIR__) . '/Dump/Drupal6AggregatorSettings.php',
);
$this->prepare($migration, $dumps);
$executable = new MigrateExecutable($migration, $this);
Expand Down
Expand Up @@ -41,7 +41,7 @@ public function setUp() {
parent::setUp();
$migration = entity_load('migration', 'd6_book_settings');
$dumps = array(
drupal_get_path('module', 'migrate_drupal') . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6BookSettings.php',
dirname(__DIR__) . '/Dump/Drupal6BookSettings.php',
);
$this->prepare($migration, $dumps);
$executable = new MigrateExecutable($migration, new MigrateMessage());
Expand Down
Expand Up @@ -41,7 +41,7 @@ public function setUp() {
parent::setUp();
$migration = entity_load('migration', 'd6_contact_settings');
$dumps = array(
drupal_get_path('module', 'migrate_drupal') . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6ContactSettings.php',
dirname(__DIR__) . '/Dump/Drupal6ContactSettings.php',
);
$this->prepare($migration, $dumps);
$executable = new MigrateExecutable($migration, new MigrateMessage());
Expand Down
Expand Up @@ -41,7 +41,7 @@ public function setUp() {
parent::setUp();
$migration = entity_load('migration', 'd6_dblog_settings');
$dumps = array(
drupal_get_path('module', 'migrate_drupal') . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6DblogSettings.php',
dirname(__DIR__) . '/Dump/Drupal6DblogSettings.php',
);
$this->prepare($migration, $dumps);
$executable = new MigrateExecutable($migration, new MigrateMessage());
Expand Down
Expand Up @@ -33,7 +33,7 @@ public function setUp() {
parent::setUp();
$migration = entity_load('migration', 'd6_field_settings');
$dumps = array(
drupal_get_path('module', 'migrate_drupal') . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6FieldSettings.php',
dirname(__DIR__) . '/Dump/Drupal6FieldSettings.php',
);
$this->prepare($migration, $dumps);
$executable = new MigrateExecutable($migration, $this);
Expand Down
Expand Up @@ -41,7 +41,7 @@ public function setUp() {
parent::setUp();
$migration = entity_load('migration', 'd6_file_settings');
$dumps = array(
drupal_get_path('module', 'migrate_drupal') . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6FileSettings.php',
dirname(__DIR__) . '/Dump/Drupal6FileSettings.php',
);
$this->prepare($migration, $dumps);
$executable = new MigrateExecutable($migration, new MigrateMessage());
Expand Down
Expand Up @@ -40,7 +40,7 @@ public function setUp() {
parent::setUp();
$migration = entity_load('migration', 'd6_forum_settings');
$dumps = array(
drupal_get_path('module', 'migrate_drupal') . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6ForumSettings.php',
dirname(__DIR__) . '/Dump/Drupal6ForumSettings.php',
);
$this->prepare($migration, $dumps);
$executable = new MigrateExecutable($migration, $this);
Expand Down
Expand Up @@ -40,7 +40,7 @@ public function setUp() {
parent::setUp();
$migration = entity_load('migration', 'd6_locale_settings');
$dumps = array(
drupal_get_path('module', 'migrate_drupal') . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6LocaleSettings.php',
dirname(__DIR__) . '/Dump/Drupal6LocaleSettings.php',
);
$this->prepare($migration, $dumps);
$executable = new MigrateExecutable($migration, $this);
Expand Down
Expand Up @@ -40,7 +40,7 @@ public function setUp() {
parent::setUp();
$migration = entity_load('migration', 'd6_menu_settings');
$dumps = array(
drupal_get_path('module', 'migrate_drupal') . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6MenuSettings.php',
dirname(__DIR__) . '/Dump/Drupal6MenuSettings.php',
);
$this->prepare($migration, $dumps);
$executable = new MigrateExecutable($migration, $this);
Expand Down
Expand Up @@ -41,7 +41,7 @@ public function setUp() {
parent::setUp();
$migration = entity_load('migration', 'd6_node_settings');
$dumps = array(
drupal_get_path('module', 'migrate_drupal') . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6NodeSettings.php',
dirname(__DIR__) . '/Dump/Drupal6NodeSettings.php',
);
$this->prepare($migration, $dumps);
$executable = new MigrateExecutable($migration, new MigrateMessage);
Expand Down
Expand Up @@ -41,7 +41,7 @@ protected function setUp() {
parent::setUp();
$migration = entity_load('migration', 'd6_search_settings');
$dumps = array(
drupal_get_path('module', 'migrate_drupal') . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6SearchSettings.php',
dirname(__DIR__) . '/Dump/Drupal6SearchSettings.php',
);
$this->prepare($migration, $dumps);
$executable = new MigrateExecutable($migration, new MigrateMessage());
Expand Down
Expand Up @@ -41,7 +41,7 @@ protected function setUp() {
parent::setUp();
$migration = entity_load('migration', 'd6_simpletest_settings');
$dumps = array(
drupal_get_path('module', 'migrate_drupal') . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6SimpletestSettings.php',
dirname(__DIR__) . '/Dump/Drupal6SimpletestSettings.php',
);
$this->prepare($migration, $dumps);
$executable = new MigrateExecutable($migration, new MigrateMessage());
Expand Down
Expand Up @@ -41,7 +41,7 @@ protected function setUp() {
parent::setUp();
$migration = entity_load('migration', 'd6_statistics_settings');
$dumps = array(
drupal_get_path('module', 'migrate_drupal') . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6StatisticsSettings.php',
dirname(__DIR__) . '/Dump/Drupal6StatisticsSettings.php',
);
$this->prepare($migration, $dumps);
$executable = new MigrateExecutable($migration, new MigrateMessage());
Expand Down
Expand Up @@ -40,7 +40,7 @@ protected function setUp() {
parent::setUp();
$migration = entity_load('migration', 'd6_syslog_settings');
$dumps = array(
drupal_get_path('module', 'migrate_drupal') . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6SyslogSettings.php',
dirname(__DIR__) . '/Dump/Drupal6SyslogSettings.php',
);
$this->prepare($migration, $dumps);
$executable = new MigrateExecutable($migration, $this);
Expand Down
Expand Up @@ -40,7 +40,7 @@ protected function setUp() {
parent::setUp();
$migration = entity_load('migration', 'd6_taxonomy_settings');
$dumps = array(
drupal_get_path('module', 'migrate_drupal') . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6TaxonomySettings.php',
dirname(__DIR__) . '/Dump/Drupal6TaxonomySettings.php',
);
$this->prepare($migration, $dumps);
$executable = new MigrateExecutable($migration, $this);
Expand Down
Expand Up @@ -40,7 +40,7 @@ protected function setUp() {
parent::setUp();
$migration = entity_load('migration', 'd6_text_settings');
$dumps = array(
drupal_get_path('module', 'migrate_drupal') . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6TextSettings.php',
dirname(__DIR__) . '/Dump/Drupal6TextSettings.php',
);
$this->prepare($migration, $dumps);
$executable = new MigrateExecutable($migration, $this);
Expand Down
Expand Up @@ -40,7 +40,7 @@ protected function setUp() {
parent::setUp();
$migration = entity_load('migration', 'd6_update_settings');
$dumps = array(
drupal_get_path('module', 'migrate_drupal') . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6UpdateSettings.php',
dirname(__DIR__) . '/Dump/Drupal6UpdateSettings.php',
);
$this->prepare($migration, $dumps);
$executable = new MigrateExecutable($migration, $this);
Expand Down
Expand Up @@ -33,7 +33,7 @@ protected function setUp() {
parent::setUp();
$migration = entity_load('migration', 'd6_user_mail');
$dumps = array(
drupal_get_path('module', 'migrate_drupal') . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6UserMail.php',
dirname(__DIR__) . '/Dump/Drupal6UserMail.php',
);
$this->prepare($migration, $dumps);
$executable = new MigrateExecutable($migration, $this);
Expand Down
Expand Up @@ -49,10 +49,9 @@ public function setUp() {

/** @var \Drupal\migrate\entity\Migration $migration */
$migration = entity_load('migration', 'd6_user_role');
$path = drupal_get_path('module', 'migrate_drupal');
$dumps = array(
$path . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6UserRole.php',
$path . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6FilterFormat.php',
dirname(__DIR__) . '/Dump/Drupal6UserRole.php',
dirname(__DIR__) . '/Dump/Drupal6FilterFormat.php',
);
$this->prepare($migration, $dumps);
$executable = new MigrateExecutable($migration, $this);
Expand Down
Expand Up @@ -22,7 +22,14 @@ public static function getInfo() {
* Test errors reported.
*/
public function testPhpUnitXmlParsing() {
require_once __DIR__ . '/../../../../simpletest.module';
// This test class could be either in tests/Drupal/simpletest/Tests/, or in
// tests/src/, after the PSR-4 transition.
if (file_exists(__DIR__ . '/../../simpletest.module')) {
require_once __DIR__ . '/../../simpletest.module';
}
else {
require_once __DIR__ . '/../../../../simpletest.module';
}
$phpunit_error_xml = __DIR__ . '/phpunit_error.xml';
$res = simpletest_phpunit_xml_to_rows(1, $phpunit_error_xml);
$this->assertEquals(count($res), 4, 'All testcases got extracted');
Expand Down
Expand Up @@ -30,10 +30,7 @@ public static function getInfo() {
*/
public function setUp() {
parent::setUp();
$path_parts = explode(DIRECTORY_SEPARATOR, __DIR__);
// This file is 8 levels below the Drupal root.
$root = implode(DIRECTORY_SEPARATOR, array_slice($path_parts, 0, -8));
chdir($root);
chdir(DRUPAL_ROOT);
}

/**
Expand Down

0 comments on commit 60834c2

Please sign in to comment.