From 08800f55a2f466fd1e391dd8f5b366e7746d9302 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=2E=20Rene=CC=81e=20Beach?= <splendidnoise@gmail.com>
Date: Wed, 22 Jan 2014 17:52:15 -0500
Subject: [PATCH] Just the 7.x to 8.x test.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: J. Renée Beach <splendidnoise@gmail.com>
---
 .../system/Tests/Update/UpdateScriptTest.php       | 96 ++++++++++++++++++++++
 1 file changed, 96 insertions(+)

diff --git a/core/modules/system/lib/Drupal/system/Tests/Update/UpdateScriptTest.php b/core/modules/system/lib/Drupal/system/Tests/Update/UpdateScriptTest.php
index d581147..04a56e0 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Update/UpdateScriptTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Update/UpdateScriptTest.php
@@ -41,6 +41,28 @@ function setUp() {
   }
 
   /**
+   * Tests that updates from schema versions prior to 8000 are prevented.
+   */
+  function testInvalidMigration() {
+    // Mock a D7 system table so that the schema value of the system module
+    // can be retrieved.
+    db_create_table('system', $this->getSystemSchema());
+    // Assert that the table exists.
+    $this->assertTrue(db_table_exists('system'), 'The table exists.');
+    // Insert a value for the system module.
+    db_insert('system')
+      ->fields(array(
+        'name' => 'system',
+        'schema_version' => 7000,
+      ))
+      ->execute();
+    $system_schema = db_query('SELECT schema_version FROM {system} WHERE name = :system', array(':system' => 'system'))->fetchField();
+    $this->drupalGet($this->update_url, array('external' => TRUE));
+    $text = 'Your system schema version is ' . $system_schema . '. Updating directly from a schema version prior to 8000 is not supported. You must <a href="https://drupal.org/node/2179269">migrate your site to Drupal 8</a> first.';
+    $this->assertRaw($text, 'Updates from schema versions prior to 8000 are prevented.');
+  }
+
+  /**
    * Tests access to the update script.
    */
   function testUpdateAccess() {
@@ -192,4 +214,78 @@ function testSuccessfulUpdateFunctionality() {
     $this->clickLink('Administration pages');
     $this->assertResponse(200);
   }
+
+  /**
+   * Returns the Drupal 7 system table schema.
+   */
+  public function getSystemSchema() {
+    return array(
+      'description' => "A list of all modules, themes, and theme engines that are or have been installed in Drupal's file system.",
+      'fields' => array(
+        'filename' => array(
+          'description' => 'The path of the primary file for this item, relative to the Drupal root; e.g. modules/node/node.module.',
+          'type' => 'varchar',
+          'length' => 255,
+          'not null' => TRUE,
+          'default' => '',
+        ),
+        'name' => array(
+          'description' => 'The name of the item; e.g. node.',
+          'type' => 'varchar',
+          'length' => 255,
+          'not null' => TRUE,
+          'default' => '',
+        ),
+        'type' => array(
+          'description' => 'The type of the item, either module, theme, or theme_engine.',
+          'type' => 'varchar',
+          'length' => 12,
+          'not null' => TRUE,
+          'default' => '',
+        ),
+        'owner' => array(
+          'description' => "A theme's 'parent' . Can be either a theme or an engine.",
+          'type' => 'varchar',
+          'length' => 255,
+          'not null' => TRUE,
+          'default' => '',
+        ),
+        'status' => array(
+          'description' => 'Boolean indicating whether or not this item is enabled.',
+          'type' => 'int',
+          'not null' => TRUE,
+          'default' => 0,
+        ),
+        'bootstrap' => array(
+          'description' => "Boolean indicating whether this module is loaded during Drupal's early bootstrapping phase (e.g. even before the page cache is consulted).",
+          'type' => 'int',
+          'not null' => TRUE,
+          'default' => 0,
+        ),
+        'schema_version' => array(
+          'description' => "The module's database schema version number. -1 if the module is not installed (its tables do not exist); 0 or the largest N of the module's hook_update_N() function that has either been run or existed when the module was first installed.",
+          'type' => 'int',
+          'not null' => TRUE,
+          'default' => -1,
+          'size' => 'small',
+        ),
+        'weight' => array(
+          'description' => "The order in which this module's hooks should be invoked relative to other modules. Equal-weighted modules are ordered by name.",
+          'type' => 'int',
+          'not null' => TRUE,
+          'default' => 0,
+        ),
+        'info' => array(
+          'description' => "A serialized array containing information from the module's .info file; keys can include name, description, package, version, core, dependencies, and php.",
+          'type' => 'blob',
+          'not null' => FALSE,
+        ),
+      ),
+      'primary key' => array('filename'),
+      'indexes' => array(
+        'system_list' => array('status', 'bootstrap', 'type', 'weight', 'name'),
+        'type_name' => array('type', 'name'),
+      ),
+    );
+  }
 }
-- 
1.8.2

