public function testI18nEventCopy() {
- $otherLocale = 'fr_CA';
- $locSuffix = " ({$otherLocale})";
+ $locales = ['en_US', 'fr_CA', 'nl_NL'];
$this->enableMultilingual();
- CRM_Core_I18n_Schema::addLocale($otherLocale, 'en_US');
+ CRM_Core_I18n_Schema::addLocale('fr_CA', 'en_US');
+ CRM_Core_I18n_Schema::addLocale('nl_NL', 'en_US');
CRM_Core_I18n::singleton()->setLocale('en_US');
$locParams = [
'summary',
'description',
+ 'event_full_text',
+ 'registration_link_text',
+ 'fee_label',
+ 'intro_text',
+ 'footer_text',
+ 'confirm_title',
+ 'confirm_text',
+ 'confirm_footer_text',
+ 'confirm_email_text',
+ 'confirm_from_name',
+ 'thankyou_title',
+ 'thankyou_text',
+ 'thankyou_footer_text',
+ 'pay_later_text',
+ 'pay_later_receipt',
+ 'initial_amount_label',
+ 'initial_amount_help_text',
];
- CRM_Core_I18n::singleton()->setLocale($otherLocale);
- $ploc = ['id' => $eventId];
+ // init in case it's not defined
foreach ($locParams as $field) {
- $ploc[$field] = $eventData[$field] . $locSuffix;
+ $eventData[$field] = $eventData[$field] ?? '';
}
- $this->callAPISuccess('Event', 'create', $ploc);
+ // differencing the data in original content for each locales
+ foreach ($locales as $locale) {
+ CRM_Core_I18n::singleton()->setLocale($locale);
+ $locSuffix = " ({$locale})";
+ $ploc = ['id' => $eventId];
+ foreach ($locParams as $field) {
+ $ploc[$field] = $eventData[$field] . $locSuffix;
+ }
+
+ $res = $this->callAPISuccess('Event', 'create', $ploc);
+ }
+
+ // now that the data is different, do the copy
CRM_Core_I18n::singleton()->setLocale('en_US');
$eventCopy = CRM_Event_BAO_Event::copy($eventId);
$eventCopyId = $eventCopy->id;
+ // define the fields that doesn't change
$identicalParams = [
'event_type_id',
'is_public',
'registration_start_date',
'registration_end_date',
'max_participants',
- 'event_full_text',
'is_monetary',
'is_active',
'is_show_location',
'is_email_confirm',
];
- // en_US should be as the original
- CRM_Core_I18n::singleton()->setLocale('en_US');
- $eventCopy = civicrm_api3('Event', 'getsingle', ['id' => $eventCopyId]);
- foreach ($identicalParams as $name) {
- $this->assertEquals($eventCopy[$name], $eventData[$name]);
- }
- // title is special
- $this->assertEquals($eventCopy['title'], 'Copy of ' . $eventData['title']);
+ // check the data on the copy
+ foreach ($locales as $locale) {
+ CRM_Core_I18n::singleton()->setLocale($locale);
+ $locSuffix = " ({$locale})";
+ $eventCopy = civicrm_api3('Event', 'getsingle', ['id' => $eventCopyId]);
- // localized fields should be different
- CRM_Core_I18n::singleton()->setLocale($otherLocale);
- $eventCopy = civicrm_api3('Event', 'getsingle', ['id' => $eventCopyId]);
- foreach ($identicalParams as $name) {
- $this->assertEquals($eventCopy[$name], $eventData[$name]);
- }
- foreach ($locParams as $name) {
- $this->assertEquals($eventCopy[$name], $eventData[$name] . $locSuffix);
+ // title is special
+ $this->assertEquals($eventCopy['title'], 'Copy of ' . $eventData['title']);
+
+ // other fields
+ $this->compareLocalizedCopy($eventData, $eventCopy, $locParams, $identicalParams, $locSuffix);
}
- // title is special
- $this->assertEquals($eventCopy['title'], 'Copy of ' . $eventData['title']);
// reset to en_US only
CRM_Core_I18n::singleton()->setLocale('en_US');
}
+ protected function compareLocalizedCopy($source, $dest, $locParams, $identicalParams, $locSuffix) {
+
+ foreach ($identicalParams as $name) {
+ $this->assertEquals($dest[$name], $source[$name]);
+ }
+ foreach ($locParams as $name) {
+ $this->assertEquals($dest[$name], $source[$name] . $locSuffix);
+ }
+
+ }
+
}