Skip to content

Commit 21e6abb

Browse files
committed
Updated plugin tests for activation to ensure config is only set when there is no existing config.
1 parent d291424 commit 21e6abb

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

plugins/wpgraphql-logging/tests/wpunit/Core/PluginTest.php

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,17 @@ public function test_clone_method_throws_error() {
6060
}
6161

6262
public function test_plugin_activate() {
63+
64+
// Delet configuration option
65+
$configuration = ConfigurationHelper::get_instance();
66+
$option_key = $configuration->get_option_key();
67+
delete_option( $option_key );
68+
69+
// Verify that the configuration option has been deleted
70+
$option_value = get_option( $option_key );
71+
$this->assertEmpty( $option_value );
72+
73+
6374
$plugin = Plugin::init();
6475
$plugin::activate();
6576

@@ -71,7 +82,6 @@ public function test_plugin_activate() {
7182
$this->assertEquals( $table_exists, $table_name );
7283

7384
// Verify that the default configuration has been set
74-
$configuration = ConfigurationHelper::get_instance();
7585
$option_value = $configuration->get_option_value( WPGRAPHQL_LOGGING_SETTINGS_KEY );
7686
$this->assertNotEmpty( $option_value );
7787
$default_configuration = [
@@ -99,6 +109,26 @@ public function test_plugin_activate() {
99109
$this->assertEquals( $option_value, $default_configuration );
100110
}
101111

112+
public function test_plugin_activate_when_configuration_already_exists() {
113+
$configuration = ConfigurationHelper::get_instance();
114+
$option_key = $configuration->get_option_key();
115+
$default_configuration = [
116+
BasicConfigurationTab::get_name() => [
117+
BasicConfigurationTab::ENABLED => true,
118+
],
119+
];
120+
update_option( $option_key, $default_configuration );
121+
122+
123+
$plugin = Plugin::init();
124+
$plugin::activate();
125+
126+
// Verify that the default configuration has not been set
127+
$configuration = ConfigurationHelper::get_instance();
128+
$option_value = $configuration->get_option_value( WPGRAPHQL_LOGGING_SETTINGS_KEY );
129+
$this->assertEquals( $option_value, $default_configuration );
130+
}
131+
102132
public function test_wakeup_method_throws_error() {
103133
$reflection = new ReflectionClass( Plugin::class );
104134
$plugin = $reflection->newInstanceWithoutConstructor();

0 commit comments

Comments
 (0)