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

Commit

Permalink
EZP-27869: Added an attribute on VersionInfo to expose language codes
Browse files Browse the repository at this point in the history
  • Loading branch information
dpobel committed Sep 15, 2017
1 parent 16f2a82 commit 8515a45
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 4 deletions.
19 changes: 17 additions & 2 deletions Resources/public/js/models/ez-versioninfomodel.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ YUI.add('ez-versioninfomodel', function (Y) {
* @extends eZ.RestModel
*/
Y.eZ.VersionInfo = Y.Base.create('versionInfoModel', Y.eZ.RestModel, [], {


/**
* sync implementation for the VersionInfo. For now, it supports deleting it.
*
Expand Down Expand Up @@ -202,6 +200,23 @@ YUI.add('ez-versioninfomodel', function (Y) {
value: ""
},

/**
* The language code list.
*
* @readOnly
* @attribute languageCodeList
* @type Array
*/
languageCodeList: {
readOnly: true,
getter: function () {
if ( this.get('languageCodes') ) {
return this.get('languageCodes').split(',');
}
return [];
}
},

/**
* The initial language code
*
Expand Down
51 changes: 49 additions & 2 deletions Tests/js/models/assets/ez-versioninfomodel-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* For full copyright and license information view LICENSE file distributed with this source code.
*/
YUI.add('ez-versioninfomodel-tests', function (Y) {
var loadFromHashTest, removeTest,
var loadFromHashTest, removeTest, languageCodeListTest,
Assert = Y.Assert;

loadFromHashTest = new Y.Test.Case({
Expand Down Expand Up @@ -244,8 +244,55 @@ YUI.add('ez-versioninfomodel-tests', function (Y) {
},
});

languageCodeListTest = new Y.Test.Case({
name: "eZ Version Model languageCodeList attribute tests",

setUp: function () {
this.version = new Y.eZ.VersionInfo();
},

tearDown: function () {
this.version.destroy();
delete this.version;
},

"Should return the languages as an array": function () {
var languages = ['fre-FR', 'eng-GB'],
list;

this.version.set('languageCodes', languages.join(','));
list = this.version.get('languageCodeList');

Assert.isArray(
list,
"The list should be an array"
);
Assert.areEqual(
languages.length, list.length,
"The list should contain the language codes"
);
Y.Array.each(list, function (lang, i) {
Assert.areEqual(languages[i], lang);
});
},

"Should return an empty array": function () {
var list = this.version.get('languageCodeList');

Assert.isArray(
list,
"The list should be an array"
);
Assert.areEqual(
0, list.length,
"The list should be an empty array"
);
},

});

Y.Test.Runner.setName("eZ Version Info Model tests");
Y.Test.Runner.add(loadFromHashTest);
Y.Test.Runner.add(removeTest);

Y.Test.Runner.add(languageCodeListTest);
}, '', {requires: ['test', 'json', 'model-tests', 'ez-versioninfomodel', 'ez-restmodel']});

0 comments on commit 8515a45

Please sign in to comment.