Skip to content
Snippets Groups Projects
Commit 26185707 authored by catch's avatar catch
Browse files

Issue #1899682 by andypost: Fixed Add upgrade path tests for shortcut module.

parent 64b70d17
Branches
Tags
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -5,6 +5,8 @@
* Install, update and uninstall functions for the shortcut module.
*/
use Drupal\Component\Uuid\Uuid;
/**
* Implements hook_uninstall().
*/
......@@ -67,24 +69,30 @@ function shortcut_schema() {
* Migrate shortcuts into configuration.
*/
function shortcut_update_8000() {
$uuid = new Uuid();
$result = db_query('SELECT * from {shortcut_set}');
$ids = array();
foreach ($result as $set) {
// Save a config object.
if ($set->set_name == 'shortcut-set-1') {
// Change default shortcut id.
$set->set_name = 'default';
// Update menu links.
$links = menu_load_links('shortcut-set-1');
foreach ($links as $link) {
$link['menu_name'] = 'shortcut-default';
menu_link_save($link);
}
db_update('menu_links')
->fields(array(
'menu_name' => 'shortcut-default'
))
->condition('menu_name', 'shortcut-set-1')
->execute();
}
config('shortcut.set.' . $set->set_name)
->set('id', $set->set_name)
->set('label', $set->title)
->set('uuid', $uuid->generate())
->save();
$ids[] = $set->set_name;
}
update_config_manifest_add('shortcut.set', $ids);
}
/**
......
<?php
/**
* @file
* Contains \Drupal\system\Tests\Upgrade\ShortcutUpgradePathTest.
*/
namespace Drupal\system\Tests\Upgrade;
use Drupal\system\Tests\Upgrade\UpgradePathTestBase;
/**
* Tests upgrade of shortcut.
*/
class ShortcutUpgradePathTest extends UpgradePathTestBase {
public static function getInfo() {
return array(
'name' => 'Shortcut upgrade test',
'description' => 'Tests upgrade of shortcut to the configuration system.',
'group' => 'Upgrade path',
);
}
public function setUp() {
$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.shortcut.database.php',
);
parent::setUp();
}
/**
* Tests upgrade of {shortcut_set} table to configuration entities.
*/
public function testContactUpgrade() {
$this->assertTrue(db_table_exists('shortcut_set'), 'Table {shortcut_set} exists.');
$this->assertTrue($this->performUpgrade(), 'The upgrade was completed successfully.');
$this->assertFalse(db_table_exists('shortcut_set'), 'Table {shortcut_set} has been deleted.');
// Ensure that the Drupal 7 default set has been created.
$set = entity_load('shortcut', 'default');
$this->assertTrue($set->uuid(), 'Converted set has a UUID');
$this->assertEqual($set->label(), 'Default');
// Test that the custom set has been updated.
$set = entity_load('shortcut', 'shortcut-set-2');
$this->assertTrue($set->uuid(), 'Converted set has a UUID');
$this->assertEqual($set->label(), 'Custom shortcut set');
// Assert that manifest has been created and contains the expected records.
$manifest = config('manifest.shortcut.set');
$this->assertEqual($manifest->get('default.name'), 'shortcut.set.default');
$this->assertEqual($manifest->get('shortcut-set-2.name'), 'shortcut.set.shortcut-set-2');
}
}
<?php
/**
* @file
* Database additions for shortcut tests. Used in ShortcutUpgradePathTest.
*
* This dump only contains data and schema components relevant for shortcut
* functionality. The drupal-7.bare.standard_all.database.php file is imported
* before this dump, so the two form the database structure expected in tests
* altogether.
*/
// Add custom shortcut set.
db_insert('shortcut_set')
->fields(array(
'set_name',
'title',
))
->values(array(
'set_name' => 'shortcut-set-2',
'title' => 'Custom shortcut set',
))
->execute();
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment