From b060c603d69771c4e49f2fcd6346ad9c9cf4ef8e Mon Sep 17 00:00:00 2001 From: Bram Goffings Date: Wed, 18 Jul 2012 12:58:49 +0200 Subject: [PATCH] image upgrade path tests --- core/modules/image/image.install | 98 ++++++++++++++++++++++ core/modules/search/config/search.settings.yml | 20 +++++ .../system/Tests/Upgrade/ImageUpgradePathTest.php | 82 ++++++++++++++++++ .../system/Tests/Upgrade/SystemUpgradePathTest.php | 55 ++++++++++++ core/modules/system/system.install | 15 ++++ .../tests/upgrade/drupal-7.image.database.php | 66 +++++++++++++++ .../tests/upgrade/drupal-7.system.database.php | 42 ++++++++++ 7 files changed, 378 insertions(+) create mode 100644 core/modules/search/config/search.settings.yml create mode 100644 core/modules/system/lib/Drupal/system/Tests/Upgrade/ImageUpgradePathTest.php create mode 100644 core/modules/system/lib/Drupal/system/Tests/Upgrade/SystemUpgradePathTest.php create mode 100644 core/modules/system/tests/upgrade/drupal-7.image.database.php create mode 100644 core/modules/system/tests/upgrade/drupal-7.system.database.php diff --git a/core/modules/image/image.install b/core/modules/image/image.install index 75ffd2a..c3505e9 100644 --- a/core/modules/image/image.install +++ b/core/modules/image/image.install @@ -103,3 +103,101 @@ function image_requirements($phase) { return $requirements; } + +/* + * Load all the effects for an image style. + * + * Helper function for retrieving image effects from the image_effects database + * table for a given image style. This is a combination of the + * image_style_effects() and image_effects() functions from Drupal 7. + * + * @see image_update_8000() + */ +function _image_upgrade_style_effects($style) { + $effects = &drupal_static(__FUNCTION__); + + if (!isset($effects)) { + $effects = array(); + + // Get image effects. + $result = db_select('image_effects', NULL, array('fetch' => PDO::FETCH_ASSOC)) + ->fields('image_effects') + ->orderBy('image_effects.weight', 'ASC') + ->execute(); + foreach ($result as $effect) { + $effect['data'] = unserialize($effect['data']); + $definition = image_effect_definition_load($effect['name']); + // Do not load image effects whose definition cannot be found. + if ($definition) { + $effect = array_merge($definition, $effect); + // Generate machine name for each effect. + $effect['ieid'] = $effect['name']; + foreach ($effect['data'] as $key => $value) { + $effect['ieid'] .= '_' . $value; + } + $effect['ieid'] = preg_replace('@[^a-zA-Z0-9_-]@', '', $effect['ieid']); + // Remove deprecated items from the effect. + $deprecated = array('effect callback', 'dimensions callback', 'form callback', 'summary theme', 'help', 'label', 'dimensions passthrough', 'module'); + foreach ($effect as $key => $value) { + if (in_array($key, $deprecated)) { + unset($effect[$key]); + } + } + $effects[$effect['ieid']] = $effect; + } + } + } + + $style_effects = array(); + foreach ($effects as $effect) { + if ($style['isid'] == $effect['isid']) { + unset($effect['isid']); + $style_effects[$effect['ieid']] = $effect; + } + } + + return $style_effects; +} + +/** + * Convert existing image styles to the new config system. + */ +function image_update_8000() { + // Install default config for the image module + config_install_default_config('image'); + + // Get the image module-defined styles. + $styles = array(); + + // Get the user generated styles. If there are overrides of any of + // the image module's default styles, then they will overwrite the + // default style. + $user_styles = db_select('image_styles', NULL, array('fetch' => PDO::FETCH_ASSOC)) + ->fields('image_styles') + ->orderBy('name') + ->execute() + ->fetchAllAssoc('name', PDO::FETCH_ASSOC); + + foreach ($user_styles as $style_name => $style) { + $style['effects'] = _image_upgrade_style_effects($style); + if (isset($styles[$style_name]['module'])) { + $style['module'] = $styles[$style_name]['module']; + } + $styles[$style_name] = $style; + } + + // Convert styles to the config system + foreach ($styles as $name => $style) { + $config = config('image.style.' . $name); + + $config->set('name', $name); + if (isset($style['effects'])) { + $config->set('effects', $style['effects']); + } + else { + $config->set('effects', array()); + } + + $config->save(); + } +} diff --git a/core/modules/search/config/search.settings.yml b/core/modules/search/config/search.settings.yml new file mode 100644 index 0000000..a4a61ac --- /dev/null +++ b/core/modules/search/config/search.settings.yml @@ -0,0 +1,20 @@ +overlap_cjk: '1' +active_modules: ['node', 'user'] +cron_limit: '100' +default_module: node +embedded_form_submitted: '0' +minimum_word_size : '3' +and_or_limit: 7 +tag_weights: + h1: 25 + h2: 18 + h3: 15 + h4: 12 + h5: 9 + h6: 6 + u: 3 + b: 3 + i: 3 + strong: 3 + em: 3 + a: 10 diff --git a/core/modules/system/lib/Drupal/system/Tests/Upgrade/ImageUpgradePathTest.php b/core/modules/system/lib/Drupal/system/Tests/Upgrade/ImageUpgradePathTest.php new file mode 100644 index 0000000..e11187c --- /dev/null +++ b/core/modules/system/lib/Drupal/system/Tests/Upgrade/ImageUpgradePathTest.php @@ -0,0 +1,82 @@ + 'Image upgrade test', + 'description' => 'Upgrade tests for overridden and custom image styles.', + 'group' => 'Upgrade path', + ); + } + + public function setUp() { + // Path to the database dump files. + $this->databaseDumpFiles = array( + drupal_get_path('module', 'system') . '/tests/upgrade/drupal-7.filled.standard_all.database.php.gz',, + drupal_get_path('module', 'system') . '/tests/upgrade/drupal-7.image.database.php', + ); + parent::setUp(); + } + + /** + * Tests that custom and overridden image styles have been upgraded. + */ + public function testImageStyleUpgrade() { + $this->assertTrue($this->performUpgrade(), 'The upgrade was completed successfully.'); + + // Test that overridden and custom image styles are properly upgraded. + $styles = array( + 'test-custom' => array( + 'name' => 'test-custom', + 'effects' => array( + 'image_rotate_90_FFFFFF_1' => array( + 'name' => 'image_rotate', + 'data' => array( + 'degrees' => '90', + 'bgcolor' => '#FFFFFF', + 'random' => '1', + ), + 'ieid' => 'image_rotate_90_FFFFFF_1', + 'weight' => '1', + ), + 'image_desaturate' => array( + 'name' => 'image_desaturate', + 'data' => array(), + 'ieid' => 'image_desaturate', + 'weight' => '2', + ), + ), + ), + 'thumbnail' => array( + 'name' => 'thumbnail', + 'effects' => array ( + 'image_scale_177_177_0' => array( + 'name' => 'image_scale', + 'data' => array ( + 'width' => '177', + 'height' => '177', + 'upscale' => '0', + ), + 'ieid' => 'image_scale_177_177_0', + 'weight' => '0', + ), + ), + ), + ); + + foreach ($styles as $name => $style) { + $config = config('image.style.' . $name)->get(); + $this->assertEqual($style, $config, t('Upgraded image style %name successfully.', array('%name' => $name))); + } + } +} diff --git a/core/modules/system/lib/Drupal/system/Tests/Upgrade/SystemUpgradePathTest.php b/core/modules/system/lib/Drupal/system/Tests/Upgrade/SystemUpgradePathTest.php new file mode 100644 index 0000000..cab0b7f --- /dev/null +++ b/core/modules/system/lib/Drupal/system/Tests/Upgrade/SystemUpgradePathTest.php @@ -0,0 +1,55 @@ + 'System upgrade test', + 'description' => 'Upgrade tests for non-default values of system variables.', + 'group' => 'Upgrade path', + ); + } + + public function setUp() { + // Path to the database dump files. + $this->databaseDumpFiles = array( + drupal_get_path('module', 'system') . '/tests/upgrade/drupal-7.bare.standard_all.database.php.gz', + drupal_get_path('module', 'system') . '/tests/upgrade/drupal-7.system.database.php', + ); + parent::setUp(); + } + + /** + * Tests that custom and overridden image styles have been upgraded. + */ + public function testSystemVariableUpgrade() { + $this->assertTrue($this->performUpgrade(), 'The upgrade was completed successfully.'); + + // Test that the overridden values were properly converted. + $overrides = array( + 'system.performance' => array( + 'cache' => 1, + 'page_cache_maximum_age' => '1800', + 'page_compression' => 1, + 'preprocess_css' => 1, + 'preprocess_js' => 1, + ), + ); + foreach ($overrides as $file => $values) { + $config = config($file); + foreach ($values as $name => $value) { + $stored = $config->get($name); + $this->assertEqual($value, $stored, t('Stored value %stored for %name matches old value %value.', array('%stored' => $stored, '%name' => $name, '%value' => $value))); + } + } + } +} diff --git a/core/modules/system/system.install b/core/modules/system/system.install index 656b5b2..e12d542 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -1995,6 +1995,21 @@ function system_update_8013() { } /** + * Moves performance system settings from variable to config. + * + * @ingroup config_upgrade + */ +function system_update_8013() { + update_variables_to_config('system.performance', array( + 'cache' => 'cache', + 'page_cache_maximum_age' => 'page_cache_maximum_age', + 'page_compression' => 'page_compression', + 'preprocess_css' => 'preprocess_css', + 'preprocess_js' => 'preprocess_js', + )); +} + +/** * @} End of "defgroup updates-7.x-to-8.x". * The next series of updates should start at 9000. */ diff --git a/core/modules/system/tests/upgrade/drupal-7.image.database.php b/core/modules/system/tests/upgrade/drupal-7.image.database.php new file mode 100644 index 0000000..3cc99c0 --- /dev/null +++ b/core/modules/system/tests/upgrade/drupal-7.image.database.php @@ -0,0 +1,66 @@ +fields(array( + 'ieid', + 'isid', + 'weight', + 'name', + 'data', +)) +->values(array( + 'ieid' => '1', + 'isid' => '1', + 'weight' => '0', + 'name' => 'image_scale', + 'data' => 'a:3:{s:5:"width";s:3:"177";s:6:"height";s:3:"177";s:7:"upscale";i:0;}', +)) +->values(array( + 'ieid' => '2', + 'isid' => '1', + 'weight' => '2', + 'name' => 'image_desaturate', + 'data' => 'a:0:{}', +)) +->values(array( + 'ieid' => '3', + 'isid' => '2', + 'weight' => '1', + 'name' => 'image_rotate', + 'data' => 'a:3:{s:7:"degrees";s:2:"90";s:7:"bgcolor";s:7:"#FFFFFF";s:6:"random";i:1;}', +)) +->values(array( + 'ieid' => '4', + 'isid' => '2', + 'weight' => '2', + 'name' => 'image_desaturate', + 'data' => 'a:0:{}', +)) +->execute(); + +// Add image styles. +db_insert('image_styles')->fields(array( + 'isid', + 'name', +)) +// Custom style. +->values(array( + 'isid' => '2', + 'name' => 'test-custom', +)) +// Override thumbnail style. +->values(array( + 'isid' => '1', + 'name' => 'thumbnail', +)) +->execute(); diff --git a/core/modules/system/tests/upgrade/drupal-7.system.database.php b/core/modules/system/tests/upgrade/drupal-7.system.database.php new file mode 100644 index 0000000..428f535 --- /dev/null +++ b/core/modules/system/tests/upgrade/drupal-7.system.database.php @@ -0,0 +1,42 @@ +fields(array( + 'name', + 'value', +)) +->values(array( + 'name' => 'cache', + 'value'=> 'i:1;', +)) +->values(array( + 'name' => 'cache_lifetime', + 'value' => 's:5:"10800";', + )) +->values(array( + 'name' => 'page_cache_maximum_age', + 'value' => 's:4:"1800";', + )) +->values(array( + 'name' => 'page_compression', + 'value' => 'i:1;', + )) +->values(array( + 'name' => 'preprocess_css', + 'value' => 'i:1;', + )) +->values(array( + 'name' => 'preprocess_js', + 'value' => 'i:1;', + )) +->execute(); -- 1.7.11.msysgit.1