From 8f37e8e37c946e14a6d6d84e4db34b931b3b324b Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Thu, 17 Aug 2017 10:25:08 -0700 Subject: [PATCH] (NFC) SettingsStack - Add test coverage for new helper This class was recently added as a helper for another unit-test, but it didn't have its own coverage. This is a quick/simple test for it. --- Civi/Core/SettingsStack.php | 7 +++- tests/phpunit/Civi/Core/SettingsStackTest.php | 33 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 tests/phpunit/Civi/Core/SettingsStackTest.php diff --git a/Civi/Core/SettingsStack.php b/Civi/Core/SettingsStack.php index 79e2f22d7a84..434c8371e6b6 100644 --- a/Civi/Core/SettingsStack.php +++ b/Civi/Core/SettingsStack.php @@ -4,7 +4,12 @@ /** * Class SettingsStack * - * The settings stack allows you to temporarily apply settings. + * The settings stack allows you to temporarily change (then restore) settings. It's intended + * primarily for use in testing. + * + * Like the global `$civicrm_setting` variable, it works best with typical inert settings that + * do not trigger extra activation logic. A handful of settings (such as `enable_components` + * and ~5 others) * * @package Civi\Core */ diff --git a/tests/phpunit/Civi/Core/SettingsStackTest.php b/tests/phpunit/Civi/Core/SettingsStackTest.php new file mode 100644 index 000000000000..ac4cee90567b --- /dev/null +++ b/tests/phpunit/Civi/Core/SettingsStackTest.php @@ -0,0 +1,33 @@ +useTransaction(TRUE); + } + + public function tearDown() { + parent::tearDown(); + } + + /** + * Temporarily modify -- then restore -- settings. + */ + public function testStack() { + $origVal = \Civi::settings()->get('show_events'); + + $settingsStack = new \Civi\Core\SettingsStack(); + + $settingsStack->push('show_events', 9); + $this->assertEquals(9, \Civi::settings()->get('show_events')); + + $settingsStack->push('show_events', 8); + $this->assertEquals(8, \Civi::settings()->get('show_events')); + + $settingsStack->popAll(); + $this->assertEquals($origVal, \Civi::settings()->get('show_events')); + } + +}