diff --git a/features.drush.inc b/features.drush.inc index 0d7a10d..9a0b978 100644 --- a/features.drush.inc +++ b/features.drush.inc @@ -435,6 +435,9 @@ function drush_features_export() { if (!drush_confirm(dt('Do you really want to continue?'))) { drush_die('Aborting.'); } + $export = _features_generate_export($items, $module); + _features_populate($items, $export[info], $export[name]); + _drush_features_export($export['info'], $module, $directory); } } else { @@ -529,34 +532,8 @@ function _drush_features_export($info, $module_name = NULL, $directory = NULL) { } if (is_dir($directory)) { drupal_flush_all_caches(); - module_load_include('inc', 'features', 'features.export'); - $export = features_populate($info, $module_name); - if (!features_load_feature($module_name)) { - $export['name'] = $module_name; - } - // Set the feature version if the --version-set or --version-increment option is passed. - if ($version = drush_get_option(array('version-set'))) { - preg_match('/^(?P\d+\.x)-(?P\d+)\.(?P\d+)-?(?P\w+)?$/', $version, $matches); - if (!isset($matches['core'], $matches['major'])) { - drush_die(dt('Please enter a valid version with core and major version number. Example: !example', array('!example' => '7.x-1.0'))); - } - $export['version'] = $version; - } - else if ($version = drush_get_option(array('version-increment'))) { - // Determine current version and increment it. - $export_load = features_export_prepare($export, $module_name); - $version = $export_load['version']; - $version_explode = explode('.', $version); - $version_minor = array_pop($version_explode); - // Increment minor version number if numeric or not a dev release. - if (is_numeric($version_minor) || strpos($version_minor, 'dev') !== (strlen($version_minor) - 3)) { - ++$version_minor; - } - array_push($version_explode, $version_minor); - // Rebuild version string. - $version = implode('.', $version_explode); - $export['version'] = $version; - } + variable_set('trace', 'test'); + $export = _features_generate_export($info, $module_name); $files = features_export_render($export, $module_name, TRUE); foreach ($files as $extension => $file_contents) { if (!in_array($extension, array('module', 'info'))) { @@ -576,6 +553,46 @@ function _drush_features_export($info, $module_name = NULL, $directory = NULL) { } /** + * Helper function for _drush_feature_export. + * + * @param $info + * The feature info associative array. + * @param $module_name + * Optional. The name for the exported module. + */ +function _features_generate_export(&$info, &$module_name) { + module_load_include('inc', 'features', 'features.export'); + $export = features_populate($info, $module_name); + if (!features_load_feature($module_name)) { + $export['name'] = $module_name; + } + // Set the feature version if the --version-set or --version-increment option is passed. + if ($version = drush_get_option(array('version-set'))) { + preg_match('/^(?P\d+\.x)-(?P\d+)\.(?P\d+)-?(?P\w+)?$/', $version, $matches); + if (!isset($matches['core'], $matches['major'])) { + drush_die(dt('Please enter a valid version with core and major version number. Example: !example', array('!example' => '7.x-1.0'))); + } + $export['version'] = $version; + } + else if ($version = drush_get_option(array('version-increment'))) { + // Determine current version and increment it. + $export_load = features_export_prepare($export, $module_name); + $version = $export_load['version']; + $version_explode = explode('.', $version); + $version_minor = array_pop($version_explode); + // Increment minor version number if numeric or not a dev release. + if (is_numeric($version_minor) || strpos($version_minor, 'dev') !== (strlen($version_minor) - 3)) { + ++$version_minor; + } + array_push($version_explode, $version_minor); + // Rebuild version string. + $version = implode('.', $version_explode); + $export['version'] = $version; + } + return $export; +} + +/** * Revert a feature to it's code definition. * Optionally accept a list of components to revert. */ diff --git a/tests/features.test b/tests/features.test index 8da66a3..3d6462c 100644 --- a/tests/features.test +++ b/tests/features.test @@ -280,3 +280,54 @@ class FeaturesCtoolsIntegrationTest extends DrupalWebTestCase { } } } + +/** + * Tests Features' Drush integration. + */ +class FeaturesDrushExportTest extends DrupalWebTestCase { + protected $profile = 'testing'; + private $test_module = 'my_sweet_feature'; + private $test_module_path = 'public://my_sweet_feature'; + + /** + * Test info. + */ + public static function getInfo() { + return array( + 'name' => t('Drush integration'), + 'description' => t('Run tests on Features\' `drush` commands.'), + 'group' => t('Features'), + ); + } + + /** + * Set up test. + */ + public function setUp() { + parent::setUp(array('features')); + } + + /** + * Test features-export command when module is not present. + */ + public function testModuleExportNew() { + // Verify the module files are not present. + $stream_wrapper = file_stream_wrapper_get_instance_by_uri($this->test_module_path); + $directory = $stream_wrapper->getDirectoryPath(); + $module_path = "$directory/$this->test_module"; + + $module_file_exists = is_dir($module_path); + $this->assertFalse($module_file_exists, 'The test module files are not present.'); + + // Run drush command then check that the module was created. + exec("drush fe $this->test_module node:page -y --destination=\"$directory\"", $output); + + $module_file_exists = is_dir($module_path); + $this->assertTrue($module_file_exists, 'The test module has been created'); + + // Verify the component was exported. + $component_exported = is_file("$module_path/my_sweet_feature.features.field.inc"); + $this->assertTrue($component_exported, 'The component was exported succesfully.'); + } + +}