Skip to content

Commit

Permalink
[FIX] base/ManagedObject: Aggregation Bindings in JSON Views
Browse files Browse the repository at this point in the history
Fixes issue where aggregation objects which have a value
property were wrongly interpreted as bindings.

BCP: 2080356736
Fixes: #2972

Change-Id: I1882cfe12d52cfbdc2aea1073959c3f12840b9bc
(cherry picked from commit 56a3a25)
CR-Id: 002075125900004538032020
  • Loading branch information
devtomtom committed Dec 11, 2020
1 parent 1f544d4 commit 3f2d1c1
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 9 deletions.
8 changes: 4 additions & 4 deletions src/sap.ui.core/src/sap/ui/base/ManagedObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -2899,10 +2899,12 @@ sap.ui.define([
* @private
*/
ManagedObject.prototype.extractBindingInfo = function(oValue, oScope, bDetectValue) {

// property:{path:"path", template:oTemplate}
if (oValue && typeof oValue === "object") {
if (oValue.ui5object) {
if (oValue.Type) {
// if value contains the 'Type' property (capital 'T'), this is not a binding info.
return undefined;
} else if (oValue.ui5object) {
// if value contains ui5object property, this is not a binding info,
// remove it and not check for path or parts property
delete oValue.ui5object;
Expand All @@ -2920,8 +2922,6 @@ sap.ui.define([
// either returns a binding info or an unescaped string or undefined - depending on binding syntax
return ManagedObject.bindingParser(oValue, oScope, true);
}

// return undefined;
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ sap.ui.define([
"sap/base/i18n/ResourceBundle",
"sap/ui/core/mvc/View",
"sap/ui/core/mvc/JSONView",
"sap/ui/base/ManagedObject",
"./AnyViewAsync.qunit",
"sap/base/Log"
], function(ResourceBundle, View, JSONView, asyncTestsuite, Log) {
], function(ResourceBundle, View, JSONView, ManagedObject, asyncTestsuite, Log) {
"use strict";

// setup test config with generic factory
Expand Down Expand Up @@ -78,4 +79,40 @@ sap.ui.define([
oResourceBundleCreateSpy.restore();
});
});

QUnit.test("Async JSONView: Aggregation Binding with value property", function(assert) {
var done = assert.async();

sap.ui.require(["sap/ui/table/Table"], function() {
var oExtractBindingInfoSpy = sinon.spy(ManagedObject.prototype, "extractBindingInfo");
var json = JSON.stringify({
"Type": "sap.ui.core.mvc.JSONView",
"content": [
{
"Type": "sap.ui.table.Table",
"columns": [
{
"Type": "sap.ui.table.Column",
"template": {
"Type": "sap.m.DatePicker",
"value": {
"path": "Date",
"type": "sap.ui.model.type.String"
}
}
}
]
}
]
});

JSONView.create({
definition: json
}).then(function(oJsonView) {
assert.equal(oExtractBindingInfoSpy.callCount, 7, "ManagedObject#extractBindingInfo called seven times");
assert.equal(oExtractBindingInfoSpy.getCall(5).returnValue, undefined, "ManagedObject#extractBindingInfo should return undefined");
done();
});
});
});
});
40 changes: 37 additions & 3 deletions src/sap.ui.core/test/sap/ui/core/qunit/mvc/JSONView.qunit.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/*global QUnit */
/*global sinon QUnit */
sap.ui.define([
'sap/ui/core/library',
'./AnyView.qunit'
], function(coreLibrary, testsuite) {
'./AnyView.qunit',
'sap/ui/base/ManagedObject'
], function(coreLibrary, testsuite, ManagedObject) {
"use strict";

var ViewType = coreLibrary.mvc.ViewType;
Expand Down Expand Up @@ -85,4 +86,37 @@ sap.ui.define([
oView.destroy();
});

QUnit.test("JSONView: Aggregation Binding with value property", function(assert) {
var done = assert.async();
sap.ui.require(["sap/ui/table/Table"], function(Table) {
var oExtractBindingInfoSpy = sinon.spy(ManagedObject.prototype, "extractBindingInfo");

var json = JSON.stringify({
"Type": "sap.ui.core.mvc.JSONView",
"content": [
{
"Type": "sap.ui.table.Table",
"columns": [
{
"Type": "sap.ui.table.Column",
"template": {
"Type": "sap.m.DatePicker",
"value": {
"path": "Date",
"type": "sap.ui.model.type.String"
}
}
}
]
}
]
});

sap.ui.jsonview({ viewContent: json });
assert.equal(oExtractBindingInfoSpy.callCount, 7, "ManagedObject#extractBindingInfo called seven times");
assert.equal(oExtractBindingInfoSpy.getCall(5).returnValue, undefined, "ManagedObject#extractBindingInfo should return undefined");
done();
});
});

});
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ sap.ui.define(["sap/ui/Device"], function(Device) {
},
JSONView: {
title: "QUnit Page for sap.ui.core.mvc.JSONView + sap.ui.core.mvc.Controller",
sinon: false
sinon: true
},
JSView: {
title: "QUnit Page for sap.ui.core.mvc.JSView + sap.ui.core.mvc.Controller",
Expand Down

0 comments on commit 3f2d1c1

Please sign in to comment.