Skip to content
This repository has been archived by the owner on May 3, 2022. It is now read-only.

Commit

Permalink
Fix EZP-26117: Required richtext not validated as filled with single …
Browse files Browse the repository at this point in the history
…embed
  • Loading branch information
yannickroger committed Aug 30, 2016
1 parent 26ba014 commit dd34410
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Resources/public/js/views/fields/ez-richtext-editview.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,12 @@ YUI.add('ez-richtext-editview', function (Y) {
return element.get('children').some(function (node) {
return L.trim(node.get('text')) !== '';
});
},
hasEmbedElement = function(element) {
return !!element.one('[data-ezelement=ezembed]');
};

return !section || !hasChildNodes(section) || !hasChildWithContent(section);
return !section || !hasChildNodes(section) || !(hasChildWithContent(section) || hasEmbedElement(section));
},

_variables: function () {
Expand Down
20 changes: 20 additions & 0 deletions Tests/js/views/fields/assets/ez-richtext-editview-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ YUI.add('ez-richtext-editview-tests', function (Y) {
editorTest, rerenderEditorTest, focusModeTest, editorFocusHandlingTest, appendToolbarConfigTest,
eventForwardTest, defaultEditorProcessorsTest, defaultProcessorsTest,
VALID_XHTML, INVALID_XHTML, RESULT_XHTML, EMPTY_XHTML, RESULT_EMPTY_XHTML,
VALID_XHTML_WITH_EMBED,
Assert = Y.Assert, Mock = Y.Mock,
destroyTearDown = function () {
// setTimeout is needed otherwise, the editor is destroyed while
Expand All @@ -26,6 +27,10 @@ YUI.add('ez-richtext-editview-tests', function (Y) {
VALID_XHTML += '<section xmlns="http://ez.no/namespaces/ezpublish5/xhtml5/edit">';
VALID_XHTML += '<p>I\'m not empty</p></section>';

VALID_XHTML_WITH_EMBED = '<?xml version="1.0" encoding="UTF-8"?>';
VALID_XHTML_WITH_EMBED += '<section xmlns="http://ez.no/namespaces/ezpublish5/xhtml5/edit">';
VALID_XHTML_WITH_EMBED += '<div data-ezelement="ezembed"></div></section>';

EMPTY_XHTML = '<?xml version="1.0" encoding="UTF-8"?>';
EMPTY_XHTML += '<section xmlns="http://ez.no/namespaces/ezpublish5/xhtml5/edit"/>';

Expand Down Expand Up @@ -271,6 +276,21 @@ YUI.add('ez-richtext-editview-tests', function (Y) {
"A required and filled field should not be valid"
);
},

"Should validate an embed and required field": function () {
var fieldDefinition = this._getFieldDefinition(true),
processor = this._getProcessorMock(1, VALID_XHTML_WITH_EMBED, VALID_XHTML_WITH_EMBED);

this._configureNativeEditor(1, VALID_XHTML_WITH_EMBED);
this.view.set('fieldDefinition', fieldDefinition);
this.view.set('editorContentProcessors', [processor]);
this.view.validate();

Assert.isTrue(
this.view.isValid(),
"A required and filled field with embed should be valid"
);
},
});

getFieldTest = new Y.Test.Case({
Expand Down

0 comments on commit dd34410

Please sign in to comment.