3b82d9bad4f0d3153353ef50bcac2e34a14610aa
[yaffs-website] / vendor / drush / drush / tests / generateMakeTest.php
1 <?php
2
3 namespace Unish;
4 use Webmozart\PathUtil\Path;
5
6 /**
7  * Generate makefile tests
8  *
9  * @group make
10  * @group slow
11  */
12 class generateMakeCase extends CommandUnishTestCase {
13   function testGenerateMake() {
14     return $this->_testGenerateMake('devel', 'bootstrap');
15   }
16
17   function testGenerateMakeOmega() {
18     # TODO: Don't skip this test by default once the underlying issue is resolved.
19     # See: https://github.com/drush-ops/drush/issues/2030
20     $run_omega_make_test = getenv("DRUSH_TEST_MAKE_OMEGA");
21     if ($run_omega_make_test) {
22       return $this->_testGenerateMake('devel', 'omega');
23     }
24     else {
25       $this->markTestSkipped('Set `DRUSH_TEST_MAKE_OMEGA=1`, in order to run this test. See: https://github.com/drush-ops/drush/issues/2028');
26     }
27   }
28
29   function _testGenerateMake($module, $theme) {
30     $sites = $this->setUpDrupal(1, TRUE);
31     $major_version = UNISH_DRUPAL_MAJOR_VERSION . '.x';
32
33     $options = array(
34       'yes' => NULL,
35       'pipe' => NULL,
36       'root' => $this->webroot(),
37       'uri' => key($sites),
38       'cache' => NULL,
39       'strict' => 0, // Don't validate options
40     );
41     // Omega requires these core modules.
42     $this->drush('pm-enable', array('block', 'search', 'help'), $options);
43     $this->drush('pm-download', array($theme, $module), $options);
44     $this->drush('pm-enable', array($theme, $module), $options);
45
46     $makefile = UNISH_SANDBOX . '/dev.make.yml';
47
48     // First generate a simple makefile with no version information
49     $this->drush('generate-makefile', array($makefile), array('exclude-versions' => NULL) + $options);
50     $expected = <<<EOD
51 core: $major_version
52 api: 2
53 projects:
54   drupal: {  }
55   $module: {  }
56   $theme: {  }
57 EOD;
58     $actual = trim(file_get_contents($makefile));
59
60     $this->assertEquals($expected, $actual);
61
62     // Next generate a simple makefile with no version information in .ini format
63     $makefile = UNISH_SANDBOX . '/dev.make';
64     $this->drush('generate-makefile', array($makefile), array('exclude-versions' => NULL, 'format' => 'ini') + $options);
65     $expected = <<<EOD
66 ; This file was auto-generated by drush make
67 core = $major_version
68 api = 2
69
70 ; Core
71 projects[] = "drupal"
72 ; Modules
73 projects[] = "$module"
74 ; Themes
75 projects[] = "$theme"
76 EOD;
77     $actual = trim(file_get_contents($makefile));
78
79     $this->assertEquals($expected, $actual);
80
81     // Download a module to a 'contrib' directory to test the subdir feature
82     $this->mkdir(Path::join($this->webroot(). '/sites/all/modules/contrib'));
83     $this->drush('pm-download', array('libraries'), array('destination' => 'sites/all/modules/contrib') + $options);
84     $this->drush('pm-enable', array('libraries'), $options);
85     $makefile = UNISH_SANDBOX . '/dev.make.yml';
86     $this->drush('generate-makefile', array($makefile), array('exclude-versions' => NULL) + $options);
87     $expected = <<<EOD
88 core: $major_version
89 api: 2
90 projects:
91   drupal: {  }
92   $module: {  }
93   libraries:
94     subdir: contrib
95   $theme: {  }
96 EOD;
97     $actual = trim(file_get_contents($makefile));
98
99     $this->assertEquals($expected, $actual);
100
101     // Again in .ini format.
102     $makefile = UNISH_SANDBOX . '/dev.make';
103     $this->drush('generate-makefile', array($makefile), array('exclude-versions' => NULL, 'format' => 'ini') + $options);
104     $expected = <<<EOD
105 ; This file was auto-generated by drush make
106 core = $major_version
107 api = 2
108
109 ; Core
110 projects[] = "drupal"
111 ; Modules
112 projects[] = "$module"
113 projects[libraries][subdir] = "contrib"
114
115 ; Themes
116 projects[] = "$theme"
117 EOD;
118     $actual = trim(file_get_contents($makefile));
119
120     $this->assertEquals($expected, $actual);
121
122     // Generate a makefile with version numbers (in .ini format).
123     $this->drush('generate-makefile', array($makefile), array('format' => 'ini') + $options);
124     $actual = file_get_contents($makefile);
125     $this->assertContains('projects[' . $module . '][version] = "', $actual);
126   }
127 }