From 407d3bd3fbd68f6e704790d9daf7e611ff49541c Mon Sep 17 00:00:00 2001 From: nathangray Date: Thu, 30 Aug 2018 11:11:19 -0600 Subject: [PATCH] Add test for config command --- admin/tests/ConfigCommandTest.php | 109 ++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 admin/tests/ConfigCommandTest.php diff --git a/admin/tests/ConfigCommandTest.php b/admin/tests/ConfigCommandTest.php new file mode 100644 index 0000000000..556fab937f --- /dev/null +++ b/admin/tests/ConfigCommandTest.php @@ -0,0 +1,109 @@ +config_name) + { + $config = new Api\Config(static::APP); + $config->delete_value($this->config_name); + $config->save_repository(); + } + parent::tearDown(); + } + + /** + * Test that adding a setting works + */ + public function testAddConfig() + { + // Set up + $log_count = $this->get_log_count(); + $pre = Api\Config::read(static::APP); + + $set = array($this->config_name => 'Yes'); + + // Execute + $command = new admin_cmd_config(static::APP, $set); + $command->comment = 'Needed for unit test ' . $this->getName(); + $command->run(); + + // Check + $post = Api\Config::read(static::APP); + + $this->assertArrayHasKey($this->config_name, $post); + $this->assertGreaterThan($log_count, $this->get_log_count(), "Command ($command) did not log"); + } + + /** + * Try to change an existing configuration + */ + public function testChangeConfig() + { + // Set up + $log_count = $this->get_log_count(); + $pre = Api\Config::read(static::APP); + + $set = array($this->config_name => 'Yes'); + $old = array($this->config_name => 'It will log whatever'); + + // Execute + $command = new admin_cmd_config(static::APP, $set, $old); + $command->comment = 'Needed for unit test ' . $this->getName(); + $command->run(); + + // Check + $post = Api\Config::read(static::APP); + + $this->assertArrayHasKey($this->config_name, $post); + $this->assertEquals($set[$this->config_name], $post[$this->config_name]); + $this->assertNotEquals($pre[$this->config_name], $post[$this->config_name]); + $this->assertGreaterThan($log_count, $this->get_log_count(), "Command ($command) did not log"); + } + + /** + * Try to delete a config + */ + public function testDeleteConfig() + { + // Set up + $log_count = $this->get_log_count(); + Api\Config::save_value($this->config_name, 'Delete me', static::APP); + $pre = Api\Config::read(static::APP); + + $set = array($this->config_name => null); + + // Execute + $command = new admin_cmd_config(static::APP, $set, array($this->config_name => 'Delete me')); + $command->comment = 'Needed for unit test ' . $this->getName(); + $command->run(); + + // Check + $post = Api\Config::read(static::APP); + $this->assertEmpty($post[$this->config_name]); + $this->assertGreaterThan($log_count, $this->get_log_count(), "Command ($command) did not log"); + } + +} \ No newline at end of file