public function Update()
 {
     $shouldShowConfig = Configuration::Instance()->GetSectionKey(ConfigSection::PAGES, ConfigKeys::PAGES_ENABLE_CONFIGURATION, new BooleanConverter());
     if (!$shouldShowConfig) {
         Log::Debug('Show configuration UI is turned off. No updates are allowed');
         return;
     }
     $configSettings = $this->page->GetSubmittedSettings();
     $configFiles = $this->GetConfigFiles();
     $this->HandleSelectedConfigFile($configFiles);
     $newSettings = array();
     foreach ($configSettings as $setting) {
         if (!empty($setting->Section)) {
             $newSettings[$setting->Section][$setting->Key] = $setting->Value;
         } else {
             $newSettings[$setting->Key] = $setting->Value;
         }
     }
     $existingSettings = $this->configSettings->GetSettings($this->configFilePath);
     $mergedSettings = array_merge($existingSettings, $newSettings);
     foreach ($this->deletedSettings as $deletedSetting) {
         if (array_key_exists($deletedSetting, $mergedSettings)) {
             unset($mergedSettings[$deletedSetting]);
         }
     }
     Log::Debug("Saving %s settings", count($configSettings));
     $this->configSettings->WriteSettings($this->configFilePath, $mergedSettings);
     Log::Debug('Config file saved by %s', ServiceLocator::GetServer()->GetUserSession()->Email);
 }
 public function testUpdatesConfigFileWithSettings()
 {
     $setting1 = ConfigSetting::ParseForm('key1|', 'true');
     $setting2 = ConfigSetting::ParseForm('key2|section1', '10');
     $setting3 = ConfigSetting::ParseForm('key3|section1', 'some string');
     $expectedSettings['key1'] = 'true';
     $expectedSettings['section1']['key2'] = '10';
     $expectedSettings['section1']['key3'] = 'some string';
     $existingValues['oldKey1'] = 'old1';
     $existingValues['section2']['oldKey2'] = 'old2';
     $newSettings['key1'] = 'true';
     $newSettings['section1']['key2'] = '10';
     $newSettings['section1']['key3'] = 'some string';
     $newSettings['oldKey1'] = 'old1';
     $newSettings['section2']['oldKey2'] = 'old2';
     $this->page->_SubmittedSettings = array($setting1, $setting2, $setting3);
     $this->configSettings->expects($this->once())->method('GetSettings')->with($this->equalTo($this->configFilePath))->will($this->returnValue($existingValues));
     $this->configSettings->expects($this->once())->method('WriteSettings')->with($this->equalTo($this->configFilePath), $this->equalTo($newSettings));
     $this->presenter->Update();
 }