makeTest.php

  1. 8.0.x tests/makeTest.php
  2. 6.x tests/makeTest.php
  3. 7.x tests/makeTest.php
  4. 5.x tests/makeTest.php
  5. master tests/makeTest.php

Classes

Namesort descending Description
makeMakefileCase Make makefile tests. @group make @group slow

File

tests/makeTest.php
View source
  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. // Text caption_filter .info rewrite.
  270. $this->assertFileExists(UNISH_SANDBOX . '/test-build/sites/all/modules/contrib/caption_filter/caption_filter.info');
  271. $contents = file_get_contents(UNISH_SANDBOX . '/test-build/sites/all/modules/contrib/caption_filter/caption_filter.info');
  272. $this->assertContains('; Information added by drush on ' . date('Y-m-d'), $contents);
  273. $this->assertContains('version = "7.x-1.2+0-dev"', $contents);
  274. $this->assertContains('project = "caption_filter"', $contents);
  275. }
  276. function testMakeFileExtract() {
  277. $this->runMakefileTest('file-extract');
  278. }
  279. function testMakeLimitProjects() {
  280. $this->runMakefileTest('limit-projects');
  281. $this->runMakefileTest('limit-projects-multiple');
  282. }
  283. function testMakeLimitLibraries() {
  284. $this->runMakefileTest('limit-libraries');
  285. $this->runMakefileTest('limit-libraries-multiple');
  286. }
  287. /**
  288. * Test that make_move_build() doesn't wipe out directories that it shouldn't.
  289. */
  290. function testMakeMoveBuild() {
  291. // Manually download a module.
  292. $this->drush('pm-download', array('cck_signup'), array('destination' => UNISH_SANDBOX . '/sites/all/modules/contrib', 'yes' => NULL));
  293. // Build a make file.
  294. $config = $this->getMakefile('contrib-destination');
  295. $makefile = $this->makefile_path . DIRECTORY_SEPARATOR . $config['makefile'];
  296. $this->drush('make', array($makefile, '.'), $config['options']);
  297. // Verify that the manually downloaded module still exists.
  298. $this->assertFileExists(UNISH_SANDBOX . '/sites/all/modules/contrib/cck_signup/README.txt');
  299. }
  300. /**
  301. * Test that a distribution can be used as a "core" project.
  302. */
  303. function testMakeUseDistributionAsCore() {
  304. $this->runMakefileTest('use-distribution-as-core');
  305. }
  306. function getMakefile($key) {
  307. static $tests = array(
  308. 'get' => array(
  309. 'name' => 'Test GET retrieval of projects',
  310. 'makefile' => 'get.make',
  311. 'build' => TRUE,
  312. 'md5' => '4bf18507da89bed601548210c22a3bed',
  313. 'options' => array('no-core' => NULL),
  314. ),
  315. 'git' => array(
  316. 'name' => 'GIT integration',
  317. 'makefile' => 'git.make',
  318. 'build' => TRUE,
  319. 'md5' => '4c80d78b50c89b5ba11a997bafec2b43',
  320. 'options' => array('no-core' => NULL, 'no-gitinfofile' => NULL),
  321. ),
  322. 'git-simple' => array(
  323. 'name' => 'Simple git integration',
  324. 'makefile' => 'git-simple.make',
  325. 'build' => TRUE,
  326. 'md5' => '0147681209adef163a8ac2c0cff2a07e',
  327. 'options' => array('no-core' => NULL, 'no-gitinfofile' => NULL),
  328. ),
  329. 'no-patch-txt' => array(
  330. 'name' => 'Test --no-patch-txt option',
  331. 'makefile' => 'patches.make',
  332. 'build' => TRUE,
  333. 'md5' => 'e43b25505a5edfcdf25b4eaa064978b2',
  334. 'options' => array('no-core' => NULL, 'no-patch-txt' => NULL),
  335. ),
  336. 'patch' => array(
  337. 'name' => 'Test patching and writing of PATCHES.txt file',
  338. 'makefile' => 'patches.make',
  339. 'build' => TRUE,
  340. 'md5' => '56f1613fc8b6a9f03ab62cfa0300df4c',
  341. 'options' => array('no-core' => NULL),
  342. ),
  343. 'include' => array(
  344. 'name' => 'Including files and property overrides',
  345. 'makefile' => 'include.make',
  346. 'build' => TRUE,
  347. 'md5' => 'e2e230ec5eccaf5618050559ab11510d',
  348. 'options' => array(),
  349. ),
  350. 'recursion' => array(
  351. 'name' => 'Recursion',
  352. 'makefile' => 'recursion.make',
  353. 'build' => TRUE,
  354. 'md5' => 'cd095bd6dadb2f0d3e81f85f13685372',
  355. 'options' => array(
  356. 'no-core' => NULL,
  357. 'contrib-destination' => 'profiles/drupal_forum',
  358. ),
  359. ),
  360. 'svn' => array(
  361. 'name' => 'SVN',
  362. 'makefile' => 'svn.make',
  363. 'build' => TRUE,
  364. 'md5' => '0cb28a15958d7fc4bbf8bf6b00bc6514',
  365. 'options' => array('no-core' => NULL),
  366. ),
  367. 'bzr' => array(
  368. 'name' => 'Bzr',
  369. 'makefile' => 'bzr.make',
  370. 'build' => TRUE,
  371. 'md5' => '272e2b9bb27794c54396f2f03c159725',
  372. 'options' => array(),
  373. ),
  374. 'translations' => array(
  375. 'name' => 'Translation downloads',
  376. 'makefile' => 'translations.make',
  377. 'options' => array(
  378. 'translations' => 'es,pt-br',
  379. 'no-core' => NULL,
  380. ),
  381. ),
  382. 'translations-inside' => array(
  383. 'name' => 'Translation downloads inside makefile',
  384. 'makefile' => 'translations-inside.make',
  385. ),
  386. 'translations-inside7' => array(
  387. 'name' => 'Translation downloads inside makefile, core 7.x',
  388. 'makefile' => 'translations-inside7.make',
  389. ),
  390. 'contrib-destination' => array(
  391. 'name' => 'Contrib-destination attribute',
  392. 'makefile' => 'contrib-destination.make',
  393. 'build' => TRUE,
  394. 'md5' => '2aed36201ede1849ce43d9b7d6f7e9e1',
  395. 'options' => array('no-core' => NULL, 'contrib-destination' => '.'),
  396. ),
  397. 'file' => array(
  398. 'name' => 'File extraction',
  399. 'makefile' => 'file.make',
  400. 'build' => TRUE,
  401. 'md5' => '4e9883d6f9f6572af287635689c2545d',
  402. 'options' => array('no-core' => NULL),
  403. ),
  404. 'defaults' => array(
  405. 'name' => 'Test defaults array.',
  406. 'makefile' => 'defaults.make',
  407. 'build' => TRUE,
  408. 'md5' => 'e6c0d6b37cd8573cbd188742b95a274e',
  409. 'options' => array('no-core' => NULL, 'contrib-destination' => '.'),
  410. ),
  411. 'bz2' => array(
  412. 'name' => 'bzip2',
  413. 'makefile' => 'bz2.make',
  414. 'build' => TRUE,
  415. 'md5' => '5ec081203131a1a3277c8b23f9ddb995',
  416. 'options' => array('no-core' => NULL),
  417. ),
  418. 'bz2-singlefile' => array(
  419. 'name' => 'bzip2 single file',
  420. 'makefile' => 'bz2-singlefile.make',
  421. 'build' => TRUE,
  422. 'md5' => '4f9d57f6caaf6ece0526d867327621cc',
  423. 'options' => array('no-core' => NULL),
  424. ),
  425. 'gzip' => array(
  426. 'name' => 'gzip',
  427. 'makefile' => 'gzip.make',
  428. 'build' => TRUE,
  429. 'md5' => '615975484966c36f4c9186601afd61e0',
  430. 'options' => array('no-core' => NULL),
  431. ),
  432. 'subtree' => array(
  433. 'name' => 'Use subtree from downloaded archive',
  434. 'makefile' => 'subtree.make',
  435. 'build' => TRUE,
  436. 'md5' => 'db3770d8b4c9ce77510cbbcc566da9b8',
  437. 'options' => array('no-core' => NULL),
  438. ),
  439. 'md5-succeed' => array(
  440. 'name' => 'MD5 validation',
  441. 'makefile' => 'md5-succeed.make',
  442. 'build' => TRUE,
  443. 'md5' => 'f76ec174a775ce67f8e9edcb02336ef2',
  444. 'options' => array('no-core' => NULL),
  445. ),
  446. 'md5-fail' => array(
  447. 'name' => 'Failed MD5 validation test',
  448. 'makefile' => 'md5-fail.make',
  449. 'build' => FALSE,
  450. 'md5' => FALSE,
  451. 'options' => array('no-core' => NULL),
  452. 'fail' => TRUE,
  453. ),
  454. 'ignore-checksums' => array(
  455. 'name' => 'Ignore invalid checksum/s',
  456. 'makefile' => 'md5-fail.make',
  457. 'build' => TRUE,
  458. 'md5' => 'f76ec174a775ce67f8e9edcb02336ef2',
  459. 'options' => array('no-core' => NULL, 'ignore-checksums' => NULL),
  460. ),
  461. 'file-extract' => array(
  462. 'name' => 'Extract archives',
  463. 'makefile' => 'file-extract.make',
  464. 'build' => TRUE,
  465. 'md5' => 'b43d271ab3510eb33c1e300c78893458',
  466. // @todo This test often fails with concurrency set to more than one.
  467. 'options' => array('no-core' => NULL, 'concurrency' => 1),
  468. ),
  469. 'limit-projects' => array(
  470. 'name' => 'Limit projects downloaded',
  471. 'makefile' => 'limited-projects-libraries.make',
  472. 'build' => TRUE,
  473. 'md5' => '3149650120e541d7d0fa577eef0ee9a3',
  474. 'options' => array('no-core' => NULL, 'projects' => 'boxes'),
  475. ),
  476. 'limit-projects-multiple' => array(
  477. 'name' => 'Limit multiple projects downloaded',
  478. 'makefile' => 'limited-projects-libraries.make',
  479. 'build' => TRUE,
  480. 'md5' => 'ef8996c4d6c6f0d229e2237c73860071',
  481. 'options' => array('no-core' => NULL, 'projects' => 'boxes,admin_menu'),
  482. ),
  483. 'limit-libraries' => array(
  484. 'name' => 'Limit libraries downloaded',
  485. 'makefile' => 'limited-projects-libraries.make',
  486. 'build' => TRUE,
  487. 'md5' => 'cb0da4465d86eb34cafb167787862eb6',
  488. 'options' => array('no-core' => NULL, 'libraries' => 'drush_make'),
  489. ),
  490. 'limit-libraries-multiple' => array(
  491. 'name' => 'Limit multiple libraries downloaded',
  492. 'makefile' => 'limited-projects-libraries.make',
  493. 'build' => TRUE,
  494. 'md5' => '7c10e6fc65728a77a2b0aed4ec2a29cd',
  495. 'options' => array('no-core' => NULL, 'libraries' => 'drush_make,token'),
  496. ),
  497. 'use-distribution-as-core' => array(
  498. 'name' => 'Use distribution as core',
  499. 'makefile' => 'use-distribution-as-core.make',
  500. 'build' => TRUE,
  501. 'md5' => '643a603025a20d498eb583a1e7970bad',
  502. 'options' => array(),
  503. ),
  504. );
  505. return $tests[$key];
  506. }
  507. }