Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LPS-104326 Adds new test #80694

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,29 @@ public void testFragmentEntryProcessorEditableWithDuplicateIds()
_addFragmentEntry("fragment_entry_with_duplicate_editable_ids.html");
}

@Test
public void testFragmentEntryProcessorEditableWithEmptyString()
throws Exception {

FragmentEntryLink fragmentEntryLink =
_fragmentEntryLinkLocalService.createFragmentEntryLink(0);

FragmentEntry fragmentEntry = _addFragmentEntry("fragment_entry.html");

fragmentEntryLink.setHtml(fragmentEntry.getHtml());

fragmentEntryLink.setEditableValues(
_getJsonFileAsString(
"fragment_entry_link_editable_values_empty_string.json"));

Assert.assertEquals(
_getProcessedHTML("processed_fragment_entry_empty_string.html"),
_fragmentEntryProcessorRegistry.processFragmentEntryLinkHTML(
fragmentEntryLink,
_getFragmentEntryProcessorContext(
LocaleUtil.US, new long[] {0L})));
}

@Test(expected = FragmentEntryContentException.class)
public void testFragmentEntryProcessorEditableWithInvalidTypeAttribute()
throws Exception {
Expand Down Expand Up @@ -457,8 +480,11 @@ private String _getJsonFileAsString(String jsonFileName)
}

private String _getProcessedHTML() throws IOException {
Document document = Jsoup.parseBodyFragment(
_getFileAsString("processed_fragment_entry.html"));
return _getFileAsString("processed_fragment_entry.html");
}

private String _getProcessedHTML(String fileName) throws IOException {
Document document = Jsoup.parseBodyFragment(_getFileAsString(fileName));

document.outputSettings(
new Document.OutputSettings() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"com.liferay.fragment.entry.processor.editable.EditableFragmentEntryProcessor": {
"editable_img": {
"defaultValue": "sample.jpg"
},
"editable_text": {
"defaultValue": "editable text default value",
"segments-experience-id-0" : {
"en_US": "",
"es_ES": "editable text segment 0 spanish variation",
"pt_BR": "editable text segment 0 portuguese variation"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<div>
<lfr-editable id="editable_text" type="text"></lfr-editable>

<div>
<br />Editable Image:<br />

<lfr-editable id="editable_img" type="image"><img src="sample.jpg" /></lfr-editable>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import com.liferay.info.display.contributor.InfoDisplayContributor;
import com.liferay.info.display.contributor.InfoDisplayContributorTracker;
import com.liferay.info.display.contributor.InfoDisplayObjectProvider;
import com.liferay.petra.string.StringPool;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.io.unsync.UnsyncStringWriter;
import com.liferay.portal.kernel.json.JSONFactoryUtil;
Expand Down Expand Up @@ -271,7 +270,7 @@ private String _getEditableValueBySegmentsExperienceAndLocale(
String value = _getSegmentsExperienceValue(
jsonObject, locale, segmentsExperienceId);

if (Validator.isNotNull(value)) {
if (value != null) {
return value;
}
}
Expand All @@ -286,13 +285,13 @@ private String _getSegmentsExperienceValue(
SegmentsExperienceConstants.ID_PREFIX + segmentsExperienceId);

if (segmentsExperienceJSONObject == null) {
return StringPool.BLANK;
return null;
}

String value = segmentsExperienceJSONObject.getString(
LanguageUtil.getLanguageId(locale));
LanguageUtil.getLanguageId(locale), null);

if (Validator.isNotNull(value)) {
if (value != null) {
return value;
}

Expand All @@ -303,7 +302,7 @@ private String _getSegmentsExperienceValue(
return value;
}

return StringPool.BLANK;
return null;
}

private boolean _isPersonalizationSupported(JSONObject jsonObject) {
Expand Down