EGroupware /
egroupware
| 1 | <?php |
||
| 2 | |||
| 3 | /** |
||
| 4 | * Tests for config command |
||
| 5 | * |
||
| 6 | * @link http://www.egroupware.org |
||
| 7 | * @author Nathan Gray |
||
| 8 | * @copyright (c) 2018 Nathan Gray |
||
| 9 | * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License |
||
| 10 | */ |
||
| 11 | |||
| 12 | // test base providing common stuff |
||
| 13 | require_once __DIR__.'/CommandBase.php'; |
||
| 14 | |||
| 15 | use EGroupware\Api; |
||
| 16 | |||
| 17 | class ConfigCommandTest extends CommandBase |
||
| 18 | { |
||
| 19 | |||
| 20 | // Use the same app for everything |
||
| 21 | const APP = 'addressbook'; |
||
| 22 | |||
| 23 | // If we add a config, make sure we can delete it for clean up |
||
| 24 | protected $config_name = 'test_config'; |
||
| 25 | |||
| 26 | protected function tearDown() : void |
||
| 27 | { |
||
| 28 | if($this->config_name) |
||
| 29 | { |
||
| 30 | $config = new Api\Config(static::APP); |
||
| 31 | $config->delete_value($this->config_name); |
||
| 32 | $config->save_repository(); |
||
| 33 | } |
||
| 34 | parent::tearDown(); |
||
| 35 | } |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Test that adding a setting works |
||
| 39 | */ |
||
| 40 | public function testAddConfig() |
||
| 41 | { |
||
| 42 | // Set up |
||
| 43 | $log_count = $this->get_log_count(); |
||
| 44 | $pre = Api\Config::read(static::APP); |
||
|
0 ignored issues
–
show
Unused Code
introduced
by
Loading history...
|
|||
| 45 | |||
| 46 | $set = array($this->config_name => 'Yes'); |
||
| 47 | |||
| 48 | // Execute |
||
| 49 | $command = new admin_cmd_config(static::APP, $set); |
||
| 50 | $command->comment = 'Needed for unit test ' . $this->getName(); |
||
| 51 | $command->run(); |
||
| 52 | |||
| 53 | // Check |
||
| 54 | $post = Api\Config::read(static::APP); |
||
| 55 | |||
| 56 | $this->assertArrayHasKey($this->config_name, $post); |
||
| 57 | $this->assertGreaterThan($log_count, $this->get_log_count(), "Command ($command) did not log"); |
||
| 58 | } |
||
| 59 | |||
| 60 | /** |
||
| 61 | * Try to change an existing configuration |
||
| 62 | */ |
||
| 63 | public function testChangeConfig() |
||
| 64 | { |
||
| 65 | // Set up |
||
| 66 | $log_count = $this->get_log_count(); |
||
| 67 | $pre = Api\Config::read(static::APP); |
||
| 68 | |||
| 69 | $set = array($this->config_name => 'Yes'); |
||
| 70 | $old = array($this->config_name => 'It will log whatever'); |
||
| 71 | |||
| 72 | // Execute |
||
| 73 | $command = new admin_cmd_config(static::APP, $set, $old); |
||
| 74 | $command->comment = 'Needed for unit test ' . $this->getName(); |
||
| 75 | $command->run(); |
||
| 76 | |||
| 77 | // Check |
||
| 78 | $post = Api\Config::read(static::APP); |
||
| 79 | |||
| 80 | $this->assertArrayHasKey($this->config_name, $post); |
||
| 81 | $this->assertEquals($set[$this->config_name], $post[$this->config_name]); |
||
| 82 | $this->assertNotEquals($pre[$this->config_name], $post[$this->config_name]); |
||
| 83 | $this->assertGreaterThan($log_count, $this->get_log_count(), "Command ($command) did not log"); |
||
| 84 | } |
||
| 85 | |||
| 86 | /** |
||
| 87 | * Try to delete a config |
||
| 88 | */ |
||
| 89 | public function testDeleteConfig() |
||
| 90 | { |
||
| 91 | // Set up |
||
| 92 | $log_count = $this->get_log_count(); |
||
| 93 | Api\Config::save_value($this->config_name, 'Delete me', static::APP); |
||
| 94 | $pre = Api\Config::read(static::APP); |
||
|
0 ignored issues
–
show
|
|||
| 95 | |||
| 96 | $set = array($this->config_name => null); |
||
| 97 | |||
| 98 | // Execute |
||
| 99 | $command = new admin_cmd_config(static::APP, $set, array($this->config_name => 'Delete me')); |
||
| 100 | $command->comment = 'Needed for unit test ' . $this->getName(); |
||
| 101 | $command->run(); |
||
| 102 | |||
| 103 | // Check |
||
| 104 | $post = Api\Config::read(static::APP); |
||
| 105 | $this->assertEmpty($post[$this->config_name]); |
||
| 106 | $this->assertGreaterThan($log_count, $this->get_log_count(), "Command ($command) did not log"); |
||
| 107 | } |
||
| 108 | |||
| 109 | } |