Skip to content

Commit

Permalink
Merge pull request #10867 from totten/master-stack-test
Browse files Browse the repository at this point in the history
(NFC) SettingsStack - Add test coverage for new helper class
  • Loading branch information
eileenmcnaughton authored Aug 21, 2017
2 parents 5105de0 + 8f37e8e commit c6cb408
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 c6cb408

Please sign in to comment.