pmDownloadTest.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * pm-download testing
  4. */
  5. class pmDownloadCase extends Drush_TestCase {
  6. public function testPmDownload() {
  7. $this->drush('pm-download', array('devel'));
  8. $this->assertFileExists(UNISH_SANDBOX . '/devel/README.txt');
  9. }
  10. /*
  11. * Parse Drupal version and release from command argument.
  12. *
  13. * --dev option bypasses the logic tested here.
  14. *
  15. * @see pm_parse_project_version().
  16. */
  17. public function testVersionString() {
  18. $eval = 'print json_encode(pm_parse_project_version(array("devel-6.x-1.18")));';
  19. $this->drush('php-eval', array($eval));
  20. $request_data = json_decode($this->getOutput());
  21. $this->assertObjectHasAttribute('devel', $request_data);
  22. $this->assertEquals($request_data->devel->drupal_version, '6.x');
  23. $this->assertEquals($request_data->devel->project_version, '1.18');
  24. }
  25. /*
  26. * Pick right release from the XML (dev, latest published+recommended, ...).
  27. */
  28. public function testReleaseXML() {
  29. // Use a local, static XML file because live files change over time.
  30. $xml = dirname(__FILE__). '/devel.xml';
  31. // Pick specific release.
  32. $request_data = array(
  33. 'name' => 'devel',
  34. 'drupal_version' => '6.x',
  35. 'project_version' => '1.18',
  36. 'version' => '6.x-1.18',
  37. );
  38. // Build an $eval string for use with php-eval in a subprocess.
  39. $eval = '$request_data = ' . var_export($request_data, TRUE) . ";\n";
  40. $eval .= '$release = pm_parse_release($request_data, simplexml_load_file(\'' . $xml . "'));\n";
  41. $eval .= 'print json_encode($release);';
  42. $this->drush('php-eval', array($eval));
  43. $release = json_decode($this->getOutput());
  44. $this->assertEquals($release->version, '6.x-1.18');
  45. // Pick latest recommended+published with no further specification.
  46. // 6.x-2.2 is skipped because it is unpublished.
  47. // 6.x-2.2-rc1 is skipped because it is not a stable release.
  48. // Remove unwanted $request_data items.
  49. $eval = str_replace(array("'project_version' => '1.18',\n", "'version' => '6.x-1.18',\n"), NULL, $eval);
  50. $this->drush('php-eval', array($eval));
  51. $release = json_decode($this->getOutput());
  52. $this->assertEquals($release->version, '6.x-2.1');
  53. }
  54. // @todo Test pure drush commandfile projects. They get special destination.
  55. public function testDestination() {
  56. // Setup first Drupal site. Skip install for speed.
  57. $this->setUpDrupal('dev', FALSE);
  58. $root = $this->sites['dev']['root'];
  59. // Default to sites/all
  60. $this->drush('pm-download', array('devel'), array('root' => $root));
  61. $this->assertFileExists($root . '/sites/all/modules/devel/README.txt');
  62. // If we are in site specific dir, then download belongs there.
  63. // Setup a second site. Skip install for speed.
  64. $this->setUpDrupal('stage', FALSE);
  65. $path_stage = "$root/sites/stage";
  66. mkdir("$path_stage/modules");
  67. $this->drush('pm-download', array('devel'), array(), NULL, $path_stage);
  68. $this->assertFileExists($path_stage . '/modules/devel/README.txt');
  69. }
  70. }