From 534f8af19213cb56df3974ea8a5aca3f091632d9 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Wed, 16 Aug 2017 21:53:13 -0700 Subject: [PATCH] CRM-21052 - api_v3_CaseTest - Update more tests to be explicit about revision-history --- Civi/Core/SettingsStack.php | 52 +++++++++++++++++++++++++++++++ tests/phpunit/api/v3/CaseTest.php | 31 ++++++++++++++---- 2 files changed, 77 insertions(+), 6 deletions(-) create mode 100644 Civi/Core/SettingsStack.php diff --git a/Civi/Core/SettingsStack.php b/Civi/Core/SettingsStack.php new file mode 100644 index 0000000000..79e2f22d7a --- /dev/null +++ b/Civi/Core/SettingsStack.php @@ -0,0 +1,52 @@ +stack[] = array($setting, $GLOBALS['civicrm_setting']['domain'][$setting]); + } + else { + $this->stack[] = array($setting, NULL); + } + $GLOBALS['civicrm_setting']['domain'][$setting] = $settingValue; + \Civi::service('settings_manager')->useMandatory(); + } + + /** + * Restore original settings. + */ + public function popAll() { + while ($frame = array_pop($this->stack)) { + list($setting, $value) = $frame; + if ($value === NULL) { + unset($GLOBALS['civicrm_setting']['domain'][$setting]); + } + else { + $GLOBALS['civicrm_setting']['domain'][$setting] = $value; + } + } + \Civi::service('settings_manager')->useMandatory(); + } + +} diff --git a/tests/phpunit/api/v3/CaseTest.php b/tests/phpunit/api/v3/CaseTest.php index ec86456ba1..72ea596cf6 100644 --- a/tests/phpunit/api/v3/CaseTest.php +++ b/tests/phpunit/api/v3/CaseTest.php @@ -51,6 +51,11 @@ class api_v3_CaseTest extends CiviCaseTestCase { */ protected $_caseActivityId; + /** + * @var \Civi\Core\SettingsStack + */ + protected $settingsStack; + /** * Test setup for every test. * @@ -75,10 +80,12 @@ class api_v3_CaseTest extends CiviCaseTestCase { 'subject' => 'Test case', 'contact_id' => 17, ); + + $this->settingsStack = new \Civi\Core\SettingsStack(); } public function tearDown() { - unset($GLOBALS['civicrm_setting']['domain']['civicaseActivityRevisions']); + $this->settingsStack->popAll(); parent::tearDown(); } @@ -393,7 +400,9 @@ class api_v3_CaseTest extends CiviCaseTestCase { /** * Test activity api update for case activities. */ - public function testCaseActivityUpdate() { + public function testCaseActivityUpdate_Tracked() { + $this->settingsStack->push('civicaseActivityRevisions', TRUE); + // Need to create the case and activity before we can update it $this->testCaseActivityCreate(); @@ -437,9 +446,7 @@ class api_v3_CaseTest extends CiviCaseTestCase { * will *not* create or change IDs. */ public function testCaseActivityUpdate_Untracked() { - $GLOBALS['civicrm_setting']['domain']['civicaseActivityRevisions'] = FALSE; - Civi::service('settings_manager')->useMandatory(); - $this->assertEquals(FALSE, Civi::settings()->get('civicaseActivityRevisions')); + $this->settingsStack->push('civicaseActivityRevisions', FALSE); // Need to create the case and activity before we can update it $this->testCaseActivityCreate(); @@ -471,6 +478,8 @@ class api_v3_CaseTest extends CiviCaseTestCase { } public function testCaseActivityUpdateCustom() { + $this->settingsStack->push('civicaseActivityRevisions', TRUE); + // Create a case first $result = $this->callAPISuccess('case', 'create', $this->_params); @@ -741,9 +750,12 @@ class api_v3_CaseTest extends CiviCaseTestCase { * * See the case.addtimeline api. * + * @dataProvider caseActivityRevisionExamples * @throws \Exception */ - public function testCaseAddtimeline() { + public function testCaseAddtimeline($enableRevisions) { + $this->settingsStack->push('civicaseActivityRevisions', $enableRevisions); + $caseSpec = array( 'title' => 'Application with Definition', 'name' => 'Application_with_Definition', @@ -830,4 +842,11 @@ class api_v3_CaseTest extends CiviCaseTestCase { $this->assertEquals(1, $result['is_deleted']); } + public function caseActivityRevisionExamples() { + $examples = array(); + $examples[] = array(FALSE); + $examples[] = array(TRUE); + return $examples; + } + } -- 2.25.1