* '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' => '<p>Give me money</p>',
+ '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('<p>Give me money</p>', Civi::settings()->get('invoice_notes'));
+ $this->assertEquals('Extortion', Civi::settings()->get('tax_term'));
+ $this->assertEquals('Exclusive', Civi::settings()->get('tax_display_settings'));
}
/**
$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']]);
}
}