From cd65f6b48a83eed8447d3ecb50a6c74835e9d6be Mon Sep 17 00:00:00 2001
From: Alexander Benjamin <alx_benjamin@yahoo.com>
Date: Fri, 7 Aug 2015 15:28:40 +0200
Subject: [PATCH] - Issue #585268: Not setting "Operating in off-line mode." message when site is put offline with test

---
 .../system/src/Form/SiteMaintenanceModeForm.php    |  8 +++--
 .../src/Tests/System/SiteMaintenanceTest.php       | 37 ++++++++++++++++++++++
 2 files changed, 42 insertions(+), 3 deletions(-)

diff --git a/core/modules/system/src/Form/SiteMaintenanceModeForm.php b/core/modules/system/src/Form/SiteMaintenanceModeForm.php
index cde1f57..72eb0ad 100644
--- a/core/modules/system/src/Form/SiteMaintenanceModeForm.php
+++ b/core/modules/system/src/Form/SiteMaintenanceModeForm.php
@@ -85,9 +85,11 @@ public function buildForm(array $form, FormStateInterface $form_state) {
    * {@inheritdoc}
    */
   public function submitForm(array &$form, FormStateInterface $form_state) {
-    $this->config('system.maintenance')
-      ->set('message', $form_state->getValue('maintenance_mode_message'))
-      ->save();
+    if ($form_state->getValue('maintenance_mode') != 0) {
+      $this->config('system.maintenance')
+          ->set('message', $form_state->getValue('maintenance_mode_message'))
+          ->save();
+    }
 
     $this->state->set('system.maintenance_mode', $form_state->getValue('maintenance_mode'));
     parent::submitForm($form, $form_state);
diff --git a/core/modules/system/src/Tests/System/SiteMaintenanceTest.php b/core/modules/system/src/Tests/System/SiteMaintenanceTest.php
index 54ab8b7..4bfc18b 100644
--- a/core/modules/system/src/Tests/System/SiteMaintenanceTest.php
+++ b/core/modules/system/src/Tests/System/SiteMaintenanceTest.php
@@ -122,4 +122,41 @@ protected function testSiteMaintenance() {
     $this->drupalPostForm($path, array(), t('Log in'));
     $this->assertText($user_message);
   }
+
+  /**
+   * Make sure there is no message saying site is still in maintenance mode after
+   * taking site into normal mode
+   */
+  protected function testSiteMaintenanceMessage() {
+    //Go to 'Maintenance mode' page
+    $this->drupalGet('admin/config/development/maintenance');
+
+    // Submit form to put site into maintenance mode
+    $edit = array(
+      'maintenance_mode' => 1,
+    );
+    $this->drupalPostForm('admin/config/development/maintenance', $edit, t('Save configuration'));
+
+    // Make sure configuration has been saved
+    $saved_message = 'The configuration options have been saved.';
+    $this->assertRaw($saved_message);
+
+    // Put site into normal mode
+    $edit = array(
+      'maintenance_mode' => 1,
+    );
+    $this->drupalPostForm('admin/config/development/maintenance', $edit, t('Save configuration'));
+
+    // Make sure configuration has been saved
+    $saved_message = 'The configuration options have been saved.';
+    $this->assertRaw($saved_message);
+
+    // Make sure there is no message saying site is still in maintenance mode
+    $maintenance_message = 'Operating in maintenance mode.';
+    $this->assertNoRaw($maintenance_message);
+
+
+    // Logout
+    $this->drupalLogout();
+  }
 }
-- 
1.9.1

