blob: 793945910174afb405d53516abb2dc31cb853c97 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
<?php
namespace SMW\Tests;
use SMW\ApplicationFactory;
/**
* @license GNU GPL v2+
* @since 3.0
*
* @author mwjames
*/
class TestConfig {
/**
* @var Settings
*/
private $settings;
/**
* @var array
*/
private $configurations = [];
/**
* @var array
*/
private $newKeys = [];
/**
* @since 3.0
*/
public function __construct() {
$this->settings = ApplicationFactory::getInstance()->getSettings();
}
/**
* @since 3.0
*
* @param array $configurations
*/
public function set( array $configurations = [] ) {
foreach ( $configurations as $key => $value ) {
if ( array_key_exists( $key, $GLOBALS ) ) {
$this->configurations[$key] = $GLOBALS[$key];
} else {
$this->newKeys[] = $key;
}
$GLOBALS[$key] = $value;
$this->settings->set( $key, $value );
}
}
/**
* @since 3.0
*/
public function reset() {
foreach ( $this->configurations as $key => $value ) {
$GLOBALS[$key] = $value;
$this->settings->set( $key, $value );
}
foreach ( $this->newKeys as $key ) {
unset( $GLOBALS[$key] );
$this->settings->delete( $key );
}
}
}
|