PageRenderTime 49ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/drush/files/drush/tests/makeTest.php

https://bitbucket.org/draenen/puppet
PHP | 539 lines | 437 code | 51 blank | 51 comment | 13 complexity | 39a3cae81d885cce1985c8d633fd0e5e MD5 | raw file
Possible License(s): GPL-3.0, GPL-2.0
  1. <?php
  2. /**
  3. * Make makefile tests.
  4. * @group make
  5. * @group slow
  6. */
  7. class makeMakefileCase extends Drush_CommandTestCase {
  8. /**
  9. * Path to test make files.
  10. */
  11. protected $makefile_path;
  12. /**
  13. * Initialize $makefile_path.
  14. */
  15. function __construct() {
  16. $this->makefile_path = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'makefiles';
  17. }
  18. /**
  19. * Run a given makefile test.
  20. *
  21. * @param $test
  22. * The test makefile to run, as defined by $this->getMakefile();
  23. */
  24. private function runMakefileTest($test) {
  25. $default_options = array(
  26. 'test' => NULL,
  27. 'md5' => 'print',
  28. );
  29. $config = $this->getMakefile($test);
  30. $options = array_merge($config['options'], $default_options);
  31. $makefile = $this->makefile_path . DIRECTORY_SEPARATOR . $config['makefile'];
  32. $return = !empty($config['fail']) ? self::EXIT_ERROR : self::EXIT_SUCCESS;
  33. $this->drush('make', array($makefile), $options, NULL, NULL, $return);
  34. // Check the log for the build hash if this test should pass.
  35. if (empty($config['fail'])) {
  36. $output = $this->getOutput();
  37. $this->assertContains($config['md5'], $output, $config['name'] . ' - build md5 matches expected value: ' . $config['md5']);
  38. }
  39. }
  40. function testMakeGet() {
  41. $this->runMakefileTest('get');
  42. }
  43. function testMakeGit() {
  44. $this->runMakefileTest('git');
  45. }
  46. function testMakeGitSimple() {
  47. $this->runMakefileTest('git-simple');
  48. }
  49. function testMakeNoPatchTxt() {
  50. $this->runMakefileTest('no-patch-txt');
  51. }
  52. function testMakePatch() {
  53. $this->runMakefileTest('patch');
  54. }
  55. function testMakeInclude() {
  56. $this->runMakefileTest('include');
  57. }
  58. function testMakeRecursion() {
  59. $this->runMakefileTest('recursion');
  60. }
  61. function testMakeSvn() {
  62. // Silently skip svn test if svn is not installed.
  63. exec('which svn', $output, $whichSvnErrorCode);
  64. if (!$whichSvnErrorCode) {
  65. $this->runMakefileTest('svn');
  66. }
  67. else {
  68. $this->markTestSkipped('svn command not available.');
  69. }
  70. }
  71. function testMakeBzr() {
  72. // Silently skip bzr test if bzr is not installed.
  73. exec('which bzr', $output, $whichBzrErrorCode);
  74. if (!$whichBzrErrorCode) {
  75. $this->runMakefileTest('bzr');
  76. }
  77. else {
  78. $this->markTestSkipped('bzr command is not available.');
  79. }
  80. }
  81. /**
  82. * Translations can change arbitrarily, so these test for the existence of .po
  83. * files, rather than trying to match a build hash.
  84. */
  85. function testMakeTranslations() {
  86. $config = $this->getMakefile('translations');
  87. $makefile = $this->makefile_path . DIRECTORY_SEPARATOR . $config['makefile'];
  88. $install_directory = UNISH_SANDBOX . '/translations';
  89. $this->drush('make', array($makefile, $install_directory), $config['options']);
  90. $po_files = array(
  91. 'sites/all/modules/token/translations/pt-br.po',
  92. 'sites/all/modules/token/translations/es.po',
  93. );
  94. foreach ($po_files as $po_file) {
  95. $this->assertFileExists($install_directory . '/' . $po_file);
  96. }
  97. }
  98. /**
  99. * Translations can change arbitrarily, so these test for the existence of .po
  100. * files, rather than trying to match a build hash.
  101. */
  102. function testMakeTranslationsInside() {
  103. $config = $this->getMakefile('translations-inside');
  104. $makefile = $this->makefile_path . '/' . $config['makefile'];
  105. $install_directory = UNISH_SANDBOX . '/translations-inside';
  106. $this->drush('make', array($makefile, $install_directory));
  107. $po_files = array(
  108. 'profiles/default/translations/pt-br.po',
  109. 'profiles/default/translations/es.po',
  110. 'sites/all/modules/token/translations/pt-br.po',
  111. 'sites/all/modules/token/translations/es.po',
  112. 'modules/system/translations/pt-br.po',
  113. 'modules/system/translations/es.po',
  114. );
  115. foreach ($po_files as $po_file) {
  116. $this->assertFileExists($install_directory . '/' . $po_file);
  117. }
  118. }
  119. /**
  120. * Translations can change arbitrarily, so these test for the existence of .po
  121. * files, rather than trying to match a build hash.
  122. */
  123. function testMakeTranslationsInside7() {
  124. $config = $this->getMakefile('translations-inside7');
  125. $makefile = $this->makefile_path . DIRECTORY_SEPARATOR . $config['makefile'];
  126. $install_directory = UNISH_SANDBOX . '/translations-inside7';
  127. $this->drush('make', array($makefile, $install_directory));
  128. $po_files = array(
  129. 'profiles/minimal/translations/pt-br.po',
  130. 'profiles/minimal/translations/es.po',
  131. 'profiles/testing/translations/pt-br.po',
  132. 'profiles/testing/translations/es.po',
  133. 'profiles/standard/translations/pt-br.po',
  134. 'profiles/standard/translations/es.po',
  135. 'sites/all/modules/token/translations/pt-br.po',
  136. 'sites/all/modules/token/translations/es.po',
  137. 'modules/system/translations/pt-br.po',
  138. 'modules/system/translations/es.po',
  139. );
  140. foreach ($po_files as $po_file) {
  141. $this->assertFileExists($install_directory . '/' . $po_file);
  142. }
  143. }
  144. function testMakeContribDestination() {
  145. $this->runMakefileTest('contrib-destination');
  146. }
  147. function testMakeDefaults() {
  148. $this->runMakefileTest('defaults');
  149. }
  150. function testMakeFile() {
  151. $this->runMakefileTest('file');
  152. }
  153. function testMakeBZ2() {
  154. // Silently skip bz2 test if bz2 is not installed.
  155. exec('which bzip2', $output, $whichBzip2ErrorCode);
  156. if (!$whichBzip2ErrorCode) {
  157. $this->runMakefileTest('bz2');
  158. }
  159. else {
  160. $this->markTestSkipped('bzip2 command not available.');
  161. }
  162. }
  163. function testMakeBZ2SingleFile() {
  164. // Silently skip bz2 test if bz2 is not installed.
  165. exec('which bzip2', $output, $whichBzip2ErrorCode);
  166. if (!$whichBzip2ErrorCode) {
  167. $this->runMakefileTest('bz2-singlefile');
  168. }
  169. else {
  170. $this->markTestSkipped('bzip2 command not available.');
  171. }
  172. }
  173. function testMakeGZip() {
  174. // Silently skip gzip test if gzip is not installed.
  175. exec('which gzip', $output, $whichGzipErrorCode);
  176. if (!$whichGzipErrorCode) {
  177. $this->runMakefileTest('gzip');
  178. }
  179. else {
  180. $this->markTestSkipped('gzip command not available.');
  181. }
  182. }
  183. function testMakeSubtree() {
  184. $config = $this->getMakefile('subtree');
  185. $makefile = $this->makefile_path . DIRECTORY_SEPARATOR . $config['makefile'];
  186. $install_directory = UNISH_SANDBOX . DIRECTORY_SEPARATOR . 'subtree';
  187. $this->drush('make', array('--no-core', $makefile, $install_directory));
  188. $files['nivo-slider'] = array(
  189. 'exists' => array(
  190. 'jquery.nivo.slider.js',
  191. 'jquery.nivo.slider.pack.js',
  192. 'license.txt',
  193. 'nivo-slider.css',
  194. 'README',
  195. ),
  196. 'notexists' => array(
  197. '__MACOSX',
  198. 'nivo-slider',
  199. ),
  200. );
  201. $files['fullcalendar'] = array(
  202. 'exists' => array(
  203. 'fullcalendar.css',
  204. 'fullcalendar.js',
  205. 'fullcalendar.min.js',
  206. 'fullcalendar.print.css',
  207. 'gcal.js',
  208. ),
  209. 'notexists' => array(
  210. 'changelog.txt',
  211. 'demos',
  212. 'fullcalendar',
  213. 'GPL-LICENSE.txt',
  214. 'jquery',
  215. 'MIT-LICENSE.txt',
  216. ),
  217. );
  218. $basedir = $install_directory . DIRECTORY_SEPARATOR . 'sites' . DIRECTORY_SEPARATOR . 'all' . DIRECTORY_SEPARATOR . 'libraries';
  219. foreach ($files as $lib => $details) {
  220. $dir = $basedir . DIRECTORY_SEPARATOR . $lib;
  221. if (!empty($details['exists'])) {
  222. foreach ($details['exists'] as $file) {
  223. $this->assertFileExists($dir . DIRECTORY_SEPARATOR . $file);
  224. }
  225. }
  226. if (!empty($details['notexists'])) {
  227. foreach ($details['notexists'] as $file) {
  228. $this->assertFileNotExists($dir . DIRECTORY_SEPARATOR . $file);
  229. }
  230. }
  231. }
  232. }
  233. function testMakeMd5Succeed() {
  234. $this->runMakefileTest('md5-succeed');
  235. }
  236. function testMakeMd5Fail() {
  237. $this->runMakefileTest('md5-fail');
  238. }
  239. function testMakeIgnoreChecksums() {
  240. $this->runMakefileTest('ignore-checksums');
  241. }
  242. /**
  243. * Test .info file writing and the use of a git reference cache for
  244. * git downloads.
  245. */
  246. function testInfoFileWritingGit() {
  247. // Use the git-simple.make file.
  248. $config = $this->getMakefile('git-simple');
  249. $options = array('no-core' => NULL);
  250. $makefile = $this->makefile_path . DIRECTORY_SEPARATOR . $config['makefile'];
  251. $this->drush('make', array($makefile, UNISH_SANDBOX . '/test-build'), $options);
  252. // Test cck_signup.info file.
  253. $this->assertFileExists(UNISH_SANDBOX . '/test-build/sites/all/modules/cck_signup/cck_signup.info');
  254. $contents = file_get_contents(UNISH_SANDBOX . '/test-build/sites/all/modules/cck_signup/cck_signup.info');
  255. $this->assertContains('; Information added by drush on ' . date('Y-m-d'), $contents);
  256. $this->assertContains('version = "2fe932c"', $contents);
  257. $this->assertContains('project = "cck_signup"', $contents);
  258. // Verify that a reference cache was created.
  259. $cache_dir = UNISH_CACHE . DIRECTORY_SEPARATOR . 'cache';
  260. $this->assertFileExists($cache_dir . '/git/cck_signup-' . md5('http://git.drupal.org/project/cck_signup.git'));
  261. // Test context_admin.info file.
  262. $this->assertFileExists(UNISH_SANDBOX . '/test-build/sites/all/modules/context_admin/context_admin.info');
  263. $contents = file_get_contents(UNISH_SANDBOX . '/test-build/sites/all/modules/context_admin/context_admin.info');
  264. $this->assertContains('; Information added by drush on ' . date('Y-m-d'), $contents);
  265. $this->assertContains('version = "eb9f05e"', $contents);
  266. $this->assertContains('project = "context_admin"', $contents);
  267. // Verify git reference cache exists.
  268. $this->assertFileExists($cache_dir . '/git/context_admin-' . md5('http://git.drupal.org/project/context_admin.git'));
  269. }
  270. function testMakeFileExtract() {
  271. $this->runMakefileTest('file-extract');
  272. }
  273. function testMakeLimitProjects() {
  274. $this->runMakefileTest('limit-projects');
  275. $this->runMakefileTest('limit-projects-multiple');
  276. }
  277. function testMakeLimitLibraries() {
  278. $this->runMakefileTest('limit-libraries');
  279. $this->runMakefileTest('limit-libraries-multiple');
  280. }
  281. /**
  282. * Test that make_move_build() doesn't wipe out directories that it shouldn't.
  283. */
  284. function testMakeMoveBuild() {
  285. // Manually download a module.
  286. $this->drush('pm-download', array('cck_signup'), array('destination' => UNISH_SANDBOX . '/sites/all/modules/contrib', 'yes' => NULL));
  287. // Build a make file.
  288. $config = $this->getMakefile('contrib-destination');
  289. $makefile = $this->makefile_path . DIRECTORY_SEPARATOR . $config['makefile'];
  290. $this->drush('make', array($makefile, '.'), $config['options']);
  291. // Verify that the manually downloaded module still exists.
  292. $this->assertFileExists(UNISH_SANDBOX . '/sites/all/modules/contrib/cck_signup/README.txt');
  293. }
  294. function getMakefile($key) {
  295. static $tests = array(
  296. 'get' => array(
  297. 'name' => 'Test GET retrieval of projects',
  298. 'makefile' => 'get.make',
  299. 'build' => TRUE,
  300. 'md5' => '4bf18507da89bed601548210c22a3bed',
  301. 'options' => array('no-core' => NULL),
  302. ),
  303. 'git' => array(
  304. 'name' => 'GIT integration',
  305. 'makefile' => 'git.make',
  306. 'build' => TRUE,
  307. 'md5' => '4c80d78b50c89b5ba11a997bafec2b43',
  308. 'options' => array('no-core' => NULL, 'no-gitinfofile' => NULL),
  309. ),
  310. 'git-simple' => array(
  311. 'name' => 'Simple git integration',
  312. 'makefile' => 'git-simple.make',
  313. 'build' => TRUE,
  314. 'md5' => '6754a6814d4213326513ea750e6d5b65',
  315. 'options' => array('no-core' => NULL, 'no-gitinfofile' => NULL),
  316. ),
  317. 'no-patch-txt' => array(
  318. 'name' => 'Test --no-patch-txt option',
  319. 'makefile' => 'patches.make',
  320. 'build' => TRUE,
  321. 'md5' => 'e43b25505a5edfcdf25b4eaa064978b2',
  322. 'options' => array('no-core' => NULL, 'no-patch-txt' => NULL),
  323. ),
  324. 'patch' => array(
  325. 'name' => 'Test patching and writing of PATCHES.txt file',
  326. 'makefile' => 'patches.make',
  327. 'build' => TRUE,
  328. 'md5' => '56f1613fc8b6a9f03ab62cfa0300df4c',
  329. 'options' => array('no-core' => NULL),
  330. ),
  331. 'include' => array(
  332. 'name' => 'Including files and property overrides',
  333. 'makefile' => 'include.make',
  334. 'build' => TRUE,
  335. 'md5' => 'e2e230ec5eccaf5618050559ab11510d',
  336. 'options' => array(),
  337. ),
  338. 'recursion' => array(
  339. 'name' => 'Recursion',
  340. 'makefile' => 'recursion.make',
  341. 'build' => TRUE,
  342. 'md5' => 'cd095bd6dadb2f0d3e81f85f13685372',
  343. 'options' => array(
  344. 'no-core' => NULL,
  345. 'contrib-destination' => 'profiles/drupal_forum',
  346. ),
  347. ),
  348. 'svn' => array(
  349. 'name' => 'SVN',
  350. 'makefile' => 'svn.make',
  351. 'build' => TRUE,
  352. 'md5' => '0cb28a15958d7fc4bbf8bf6b00bc6514',
  353. 'options' => array('no-core' => NULL),
  354. ),
  355. 'bzr' => array(
  356. 'name' => 'Bzr',
  357. 'makefile' => 'bzr.make',
  358. 'build' => TRUE,
  359. 'md5' => '272e2b9bb27794c54396f2f03c159725',
  360. 'options' => array(),
  361. ),
  362. 'translations' => array(
  363. 'name' => 'Translation downloads',
  364. 'makefile' => 'translations.make',
  365. 'options' => array(
  366. 'translations' => 'es,pt-br',
  367. 'no-core' => NULL,
  368. ),
  369. ),
  370. 'translations-inside' => array(
  371. 'name' => 'Translation downloads inside makefile',
  372. 'makefile' => 'translations-inside.make',
  373. ),
  374. 'translations-inside7' => array(
  375. 'name' => 'Translation downloads inside makefile, core 7.x',
  376. 'makefile' => 'translations-inside7.make',
  377. ),
  378. 'contrib-destination' => array(
  379. 'name' => 'Contrib-destination attribute',
  380. 'makefile' => 'contrib-destination.make',
  381. 'build' => TRUE,
  382. 'md5' => 'd615d004adfa8ebfe44e91119b88389c',
  383. 'options' => array('no-core' => NULL, 'contrib-destination' => '.'),
  384. ),
  385. 'file' => array(
  386. 'name' => 'File extraction',
  387. 'makefile' => 'file.make',
  388. 'build' => TRUE,
  389. 'md5' => 'c7cab3930f644961a576d78769498172',
  390. 'options' => array('no-core' => NULL),
  391. ),
  392. 'defaults' => array(
  393. 'name' => 'Test defaults array.',
  394. 'makefile' => 'defaults.make',
  395. 'build' => TRUE,
  396. 'md5' => 'e6c0d6b37cd8573cbd188742b95a274e',
  397. 'options' => array('no-core' => NULL, 'contrib-destination' => '.'),
  398. ),
  399. 'bz2' => array(
  400. 'name' => 'bzip2',
  401. 'makefile' => 'bz2.make',
  402. 'build' => TRUE,
  403. 'md5' => '5ec081203131a1a3277c8b23f9ddb995',
  404. 'options' => array('no-core' => NULL),
  405. ),
  406. 'bz2-singlefile' => array(
  407. 'name' => 'bzip2 single file',
  408. 'makefile' => 'bz2-singlefile.make',
  409. 'build' => TRUE,
  410. 'md5' => '4f9d57f6caaf6ece0526d867327621cc',
  411. 'options' => array('no-core' => NULL),
  412. ),
  413. 'gzip' => array(
  414. 'name' => 'gzip',
  415. 'makefile' => 'gzip.make',
  416. 'build' => TRUE,
  417. 'md5' => '615975484966c36f4c9186601afd61e0',
  418. 'options' => array('no-core' => NULL),
  419. ),
  420. 'subtree' => array(
  421. 'name' => 'Use subtree from downloaded archive',
  422. 'makefile' => 'subtree.make',
  423. 'build' => TRUE,
  424. 'md5' => 'db3770d8b4c9ce77510cbbcc566da9b8',
  425. 'options' => array('no-core' => NULL),
  426. ),
  427. 'md5-succeed' => array(
  428. 'name' => 'MD5 validation',
  429. 'makefile' => 'md5-succeed.make',
  430. 'build' => TRUE,
  431. 'md5' => 'f76ec174a775ce67f8e9edcb02336ef2',
  432. 'options' => array('no-core' => NULL),
  433. ),
  434. 'md5-fail' => array(
  435. 'name' => 'Failed MD5 validation test',
  436. 'makefile' => 'md5-fail.make',
  437. 'build' => FALSE,
  438. 'md5' => FALSE,
  439. 'options' => array('no-core' => NULL),
  440. 'fail' => TRUE,
  441. ),
  442. 'ignore-checksums' => array(
  443. 'name' => 'Ignore invalid checksum/s',
  444. 'makefile' => 'md5-fail.make',
  445. 'build' => TRUE,
  446. 'md5' => 'f76ec174a775ce67f8e9edcb02336ef2',
  447. 'options' => array('no-core' => NULL, 'ignore-checksums' => NULL),
  448. ),
  449. 'file-extract' => array(
  450. 'name' => 'Extract archives',
  451. 'makefile' => 'file-extract.make',
  452. 'build' => TRUE,
  453. 'md5' => 'f92471fb7979e45d2554c61314ac6236',
  454. // @todo This test often fails with concurrency set to more than one.
  455. 'options' => array('no-core' => NULL, 'concurrency' => 1),
  456. ),
  457. 'limit-projects' => array(
  458. 'name' => 'Limit projects downloaded',
  459. 'makefile' => 'limited-projects-libraries.make',
  460. 'build' => TRUE,
  461. 'md5' => '3149650120e541d7d0fa577eef0ee9a3',
  462. 'options' => array('no-core' => NULL, 'projects' => 'boxes'),
  463. ),
  464. 'limit-projects-multiple' => array(
  465. 'name' => 'Limit multiple projects downloaded',
  466. 'makefile' => 'limited-projects-libraries.make',
  467. 'build' => TRUE,
  468. 'md5' => 'ef8996c4d6c6f0d229e2237c73860071',
  469. 'options' => array('no-core' => NULL, 'projects' => 'boxes,admin_menu'),
  470. ),
  471. 'limit-libraries' => array(
  472. 'name' => 'Limit libraries downloaded',
  473. 'makefile' => 'limited-projects-libraries.make',
  474. 'build' => TRUE,
  475. 'md5' => 'cb0da4465d86eb34cafb167787862eb6',
  476. 'options' => array('no-core' => NULL, 'libraries' => 'drush_make'),
  477. ),
  478. 'limit-libraries-multiple' => array(
  479. 'name' => 'Limit multiple libraries downloaded',
  480. 'makefile' => 'limited-projects-libraries.make',
  481. 'build' => TRUE,
  482. 'md5' => '7c10e6fc65728a77a2b0aed4ec2a29cd',
  483. 'options' => array('no-core' => NULL, 'libraries' => 'drush_make,token'),
  484. ),
  485. );
  486. return $tests[$key];
  487. }
  488. }