Exemple #1
0
 protected function tearDown()
 {
     if (isset($this->restore_logfile)) {
         OC_Config::setValue("logfile", $this->restore_logfile);
     } else {
         OC_Config::deleteKey("logfile");
     }
     if (isset($this->restore_logdateformat)) {
         OC_Config::setValue("logdateformat", $this->restore_logdateformat);
     } else {
         OC_Config::deleteKey("restore_logdateformat");
     }
     OC_Log_Owncloud::init();
     parent::tearDown();
 }
Exemple #2
0
 /**
  * @dataProvider findLanguageData
  */
 public function testFindLanguage($default, $preference, $expected)
 {
     OC_User::setUserId(null);
     if (is_null($default)) {
         OC_Config::deleteKey('default_language');
     } else {
         OC_Config::setValue('default_language', $default);
     }
     $_SERVER['HTTP_ACCEPT_LANGUAGE'] = $preference;
     $reflection = new \ReflectionClass('OC_L10N');
     $prop = $reflection->getProperty('language');
     $prop->setAccessible(1);
     $prop->setValue('');
     $prop->setAccessible(0);
     $this->assertSame($expected, OC_L10N::findLanguage());
 }
Exemple #3
0
 /**
  * Set mail settings
  */
 public static function setMailSettings()
 {
     \OC_Util::checkAdminUser();
     \OCP\JSON::callCheck();
     $l = \OC::$server->getL10N('settings');
     $smtp_settings = array('mail_domain' => null, 'mail_from_address' => null, 'mail_smtpmode' => array('sendmail', 'smtp', 'qmail', 'php'), 'mail_smtpsecure' => array('', 'ssl', 'tls'), 'mail_smtphost' => null, 'mail_smtpport' => null, 'mail_smtpauthtype' => array('LOGIN', 'PLAIN', 'NTLM'), 'mail_smtpauth' => true, 'mail_smtpname' => null, 'mail_smtppassword' => null);
     foreach ($smtp_settings as $setting => $validate) {
         if (!$validate) {
             if (!isset($_POST[$setting]) || $_POST[$setting] === '') {
                 \OC_Config::deleteKey($setting);
             } else {
                 \OC_Config::setValue($setting, $_POST[$setting]);
             }
         } else {
             if (is_bool($validate)) {
                 if (!empty($_POST[$setting])) {
                     \OC_Config::setValue($setting, (bool) $_POST[$setting]);
                 } else {
                     \OC_Config::deleteKey($setting);
                 }
             } else {
                 if (is_array($validate)) {
                     if (!isset($_POST[$setting]) || $_POST[$setting] === '') {
                         \OC_Config::deleteKey($setting);
                     } else {
                         if (in_array($_POST[$setting], $validate)) {
                             \OC_Config::setValue($setting, $_POST[$setting]);
                         } else {
                             $message = $l->t('Invalid value supplied for %s', array(self::getFieldname($setting, $l)));
                             \OC_JSON::error(array("data" => array("message" => $message)));
                             exit;
                         }
                     }
                 }
             }
         }
     }
     \OC_JSON::success(array("data" => array("message" => $l->t("Saved"))));
 }
Exemple #4
0
 function testGetInstanceIdGeneratesValidId()
 {
     OC_Config::deleteKey('instanceid');
     $this->assertStringStartsWith('oc', OC_Util::getInstanceId());
 }
Exemple #5
0
 /**
  * Delete a system wide defined value
  *
  * @param string $key the key of the value, under which it was saved
  */
 public function deleteValue($key)
 {
     \OC_Config::deleteKey($key);
 }
Exemple #6
0
 public function testServerHost()
 {
     OC_Config::deleteKey('overwritecondaddr');
     OC_Config::setValue('overwritehost', 'overwritten.host:8080');
     OC_Config::setValue('trusted_domains', array('trusted.host:8080', 'second.trusted.host:8080'));
     $_SERVER['HTTP_HOST'] = 'trusted.host:8080';
     // CLI always gives localhost
     $oldCLI = OC::$CLI;
     OC::$CLI = true;
     $host = OC_Request::serverHost();
     $this->assertEquals('localhost', $host);
     OC::$CLI = false;
     // overwritehost overrides trusted domain
     $host = OC_Request::serverHost();
     $this->assertEquals('overwritten.host:8080', $host);
     // trusted domain returned when used
     OC_Config::deleteKey('overwritehost');
     $host = OC_Request::serverHost();
     $this->assertEquals('trusted.host:8080', $host);
     // trusted domain returned when untrusted one in header
     $_SERVER['HTTP_HOST'] = 'untrusted.host:8080';
     OC_Config::deleteKey('overwritehost');
     $host = OC_Request::serverHost();
     $this->assertEquals('trusted.host:8080', $host);
     // clean up
     OC_Config::deleteKey('overwritecondaddr');
     OC_Config::deleteKey('overwritehost');
     unset($_SERVER['HTTP_HOST']);
     OC::$CLI = $oldCLI;
 }
Exemple #7
0
 /**
  * Deletes a value from config.php
  * @param string $key key
  *
  * This function deletes the value from config.php.
  */
 public static function deleteSystemValue($key)
 {
     return \OC_Config::deleteKey($key);
 }
Exemple #8
0
 function testGetInstanceIdGeneratesValidId()
 {
     OC_Config::deleteKey('instanceid');
     $instanceId = OC_Util::getInstanceId();
     $this->assertStringStartsWith('oc', $instanceId);
     $matchesRegex = preg_match('/^[a-z0-9]+$/', $instanceId);
     $this->assertSame(1, $matchesRegex);
 }