X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=tests%2Fphpunit%2FCRM%2FUpgrade%2FIncremental%2FBaseTest.php;h=a08f02950f55f44ad08e81d18fcadf2c70150fef;hb=2d82d5a2151b9e9ac865f223521836ea4d530566;hp=ffe2b28056bdf873d4a148e1dfec0a30229ef624;hpb=e01f2d31486eec238a7ef4db0c7b4ddc5a9d09b8;p=civicrm-core.git diff --git a/tests/phpunit/CRM/Upgrade/Incremental/BaseTest.php b/tests/phpunit/CRM/Upgrade/Incremental/BaseTest.php index ffe2b28056..a08f02950f 100644 --- a/tests/phpunit/CRM/Upgrade/Incremental/BaseTest.php +++ b/tests/phpunit/CRM/Upgrade/Incremental/BaseTest.php @@ -461,10 +461,79 @@ class CRM_Upgrade_Incremental_BaseTest extends CiviUnitTestCase { * 'proper' setting. */ public function testConvertUpgradeContributeSettings() { - Civi::settings()->set('contribution_invoice_settings', ['foo' => 'bar', 'deferred_revenue_enabled' => 1]); - $this->assertEquals(0, Civi::settings()->get('deferred_revenue_enabled')); + $setting = [ + 'deferred_revenue_enabled' => 1, + 'invoice_prefix' => 'G_', + 'credit_notes_prefix' => 'XX_', + 'due_date' => '20', + 'due_date_period' => 'weeks', + 'notes' => '

Give me money

', + 'tax_term' => 'Extortion', + 'tax_display_settings' => 'Exclusive', + ]; + CRM_Core_DAO::executeQuery("INSERT INTO civicrm_setting (name, domain_id, value) + VALUES ('contribution_invoice_settings', 1, '" . serialize($setting) . "')"); CRM_Upgrade_Incremental_Base::updateContributeSettings(NULL, 5.1); $this->assertEquals(1, Civi::settings()->get('deferred_revenue_enabled')); + $this->assertEquals('G_', Civi::settings()->get('invoice_prefix')); + $this->assertEquals('XX_', Civi::settings()->get('credit_notes_prefix')); + $this->assertEquals('20', Civi::settings()->get('invoice_due_date')); + $this->assertEquals('weeks', Civi::settings()->get('invoice_due_date_period')); + $this->assertEquals('

Give me money

', Civi::settings()->get('invoice_notes')); + $this->assertEquals('Extortion', Civi::settings()->get('tax_term')); + $this->assertEquals('Exclusive', Civi::settings()->get('tax_display_settings')); + } + + /** + * dev/core#1405 Test fixing option groups with spaces in the name + */ + public function testFixOptionGroupName() { + $name = 'This is a test Name'; + $fixedName = CRM_Utils_String::titleToVar(strtolower($name)); + $optionGroup = $this->callAPISuccess('OptionGroup', 'create', [ + 'title' => 'Test Option Group', + 'name' => $name, + ]); + // API is hardened to strip the spaces to lets re-add in now + CRM_Core_DAO::executeQuery("UPDATE civicrm_option_group SET name = %1 WHERE id = %2", [ + 1 => [$name, 'String'], + 2 => [$optionGroup['id'], 'Positive'], + ]); + $preUpgrade = $this->callAPISuccess('OptionGroup', 'getsingle', ['id' => $optionGroup['id']]); + $this->assertEquals($name, $preUpgrade['name']); + CRM_Upgrade_Incremental_php_FiveTwentyOne::fixOptionGroupName(); + $postUpgrade = $this->callAPISuccess('OptionGroup', 'getsingle', ['id' => $optionGroup['id']]); + $this->assertEquals($fixedName, $postUpgrade['name'], 'Ensure that the spaces have been removed from OptionGroup name'); + $this->assertEquals($postUpgrade['name'], $optionGroup['values'][$optionGroup['id']]['name'], 'Ensure that the fixed name matches what the API would produce'); + $this->callAPISuccess('OptionGroup', 'delete', ['id' => $optionGroup['id']]); + } + + /** + * Test that if there is an option group name as the same as the proposed fix name that doesn't cause a hard fail in the upgrade + */ + public function testFixOptionGroupNameWithFixedNameInDatabase() { + $name = 'This is a test Name'; + $fixedName = CRM_Utils_String::titleToVar(strtolower($name)); + $optionGroup = $this->callAPISuccess('OptionGroup', 'create', [ + 'title' => 'Test Option Group', + 'name' => $name, + ]); + // API is hardened to strip the spaces to lets re-add in now + CRM_Core_DAO::executeQuery("UPDATE civicrm_option_group SET name = %1 WHERE id = %2", [ + 1 => [$name, 'String'], + 2 => [$optionGroup['id'], 'Positive'], + ]); + $optionGroup2 = $this->callAPISuccess('OptionGroup', 'create', [ + 'title' => 'Test Option Group 2', + 'name' => $name, + ]); + $preUpgrade = $this->callAPISuccess('OptionGroup', 'getsingle', ['id' => $optionGroup['id']]); + $this->assertEquals($name, $preUpgrade['name']); + $preUpgrade = $this->callAPISuccess('OptionGroup', 'getsingle', ['id' => $optionGroup2['id']]); + $this->assertEquals($fixedName, $preUpgrade['name']); + CRM_Upgrade_Incremental_php_FiveTwentyOne::fixOptionGroupName(); + $this->callAPISuccess('OptionGroup', 'delete', ['id' => $optionGroup['id']]); + $this->callAPISuccess('OptionGroup', 'delete', ['id' => $optionGroup2['id']]); } }