Skip to content

Commit

Permalink
(NFC) SettingsStack - Add test coverage for new helper
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
totten committed Aug 17, 2017
1 parent 34caf21 commit 8f37e8e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Civi/Core/SettingsStack.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
33 changes: 33 additions & 0 deletions tests/phpunit/Civi/Core/SettingsStackTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
namespace Civi\Core;

class SettingsStackTest extends \CiviUnitTestCase {

protected function setUp() {
parent::setUp();
$this->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'));
}

}

0 comments on commit 8f37e8e

Please sign in to comment.