Skip to content

Commit

Permalink
Fixing issue where locale information for name/description was incorr…
Browse files Browse the repository at this point in the history
…ectly case sensitive

Issue - blackberry#214

Reviewed By: Jeffrey Heifetz <[email protected]>
Tested By: Tracy Li <[email protected]>
  • Loading branch information
James Keshavarzi committed Nov 21, 2012
1 parent f90cb82 commit 3c73bf3
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 15 deletions.
2 changes: 1 addition & 1 deletion lib/config-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ function processLocalizedText(tag, data, widgetConfig) {

if (attribs) {
language = attribs['xml:lang'] || DEFAULT;
widgetConfig[tag][language] = tagElement['#'];
widgetConfig[tag][language.toLowerCase()] = tagElement['#'];
} else {
widgetConfig[tag][DEFAULT] = tagElement;
}
Expand Down
48 changes: 35 additions & 13 deletions test/unit/lib/config-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ describe("config parser", function () {
it("Fails when no name was provided - multiple elements", function () {
var data = testUtilities.cloneObj(testData.xml2jsConfig);
data.name = ["",
{ '#': 'API Smoke Test-FR', '@': { 'xml:lang': 'FR' } },
{ '#': 'API Smoke Test-FR', '@': { 'xml:lang': 'fr' } },
];

mockParsing(data);
Expand All @@ -154,7 +154,7 @@ describe("config parser", function () {
it("Fails when localized name was provided but empty", function () {
var data = testUtilities.cloneObj(testData.xml2jsConfig);
data.name = ["API Smoke Test",
{ '#': '', '@': { 'xml:lang': 'FR' } },
{ '#': '', '@': { 'xml:lang': 'fr' } },
];

mockParsing(data);
Expand All @@ -177,33 +177,44 @@ describe("config parser", function () {

it("Parses a name element with xml:lang - single element", function () {
var data = testUtilities.cloneObj(testData.xml2jsConfig);
data.name = { '#': 'EN VALUE', '@': { 'xml:lang': 'EN' } };
data.name = { '#': 'EN VALUE', '@': { 'xml:lang': 'en' } };

mockParsing(data);

configParser.parse(configPath, session, extManager, function (configObj) {
expect(configObj.name).toEqual({"EN": "EN VALUE"});
expect(configObj.name).toEqual({"en": "EN VALUE"});
});
});

it("Parses a name element that is not case sensitive", function () {
var data = testUtilities.cloneObj(testData.xml2jsConfig);
data.name = { '#': 'EN VALUE', '@': { 'xml:lang': 'eN' } };

mockParsing(data);

configParser.parse(configPath, session, extManager, function (configObj) {
expect(configObj.name).toEqual({"en": "EN VALUE"});
});
});

it("Parses a name element with xml:lang - multi element", function () {
var data = testUtilities.cloneObj(testData.xml2jsConfig);
data.name = ['API Smoke Test',
{ '#': 'EN VALUE', '@': { 'xml:lang': 'EN' } },
{ '#': 'FR VALUE', '@': { 'xml:lang': 'FR' } }
{ '#': 'EN VALUE', '@': { 'xml:lang': 'en' } },
{ '#': 'FR VALUE', '@': { 'xml:lang': 'fr' } }

];
mockParsing(data);

configParser.parse(configPath, session, extManager, function (configObj) {
expect(configObj.name).toEqual({"default": "API Smoke Test", "EN": "EN VALUE", "FR": "FR VALUE"});
expect(configObj.name).toEqual({"default": "API Smoke Test", "en": "EN VALUE", "fr": "FR VALUE"});
});
});

it("Fails when localized name was provided but empty", function () {
var data = testUtilities.cloneObj(testData.xml2jsConfig);
data.name = ['API Smoke Test',
{ '#': '', '@': { 'xml:lang': 'FR' } },
{ '#': '', '@': { 'xml:lang': 'fr' } },
];

mockParsing(data);
Expand All @@ -226,26 +237,37 @@ describe("config parser", function () {

it("Parses a description element with xml:lang - single element", function () {
var data = testUtilities.cloneObj(testData.xml2jsConfig);
data.description = { '#': 'EN VALUE', '@': { 'xml:lang': 'EN' } };
data.description = { '#': 'EN VALUE', '@': { 'xml:lang': 'en' } };

mockParsing(data);

configParser.parse(configPath, session, extManager, function (configObj) {
expect(configObj.description).toEqual({"en": "EN VALUE"});
});
});

it("Parses a description element that is not case sensitive", function () {
var data = testUtilities.cloneObj(testData.xml2jsConfig);
data.description = { '#': 'EN VALUE', '@': { 'xml:lang': 'eN' } };

mockParsing(data);

configParser.parse(configPath, session, extManager, function (configObj) {
expect(configObj.description).toEqual({"EN": "EN VALUE"});
expect(configObj.description).toEqual({"en": "EN VALUE"});
});
});

it("Parses a description element with xml:lang - multi element", function () {
var data = testUtilities.cloneObj(testData.xml2jsConfig);
data.description = ['This is my app',
{ '#': 'EN VALUE', '@': { 'xml:lang': 'EN' } },
{ '#': 'FR VALUE', '@': { 'xml:lang': 'FR' } }
{ '#': 'EN VALUE', '@': { 'xml:lang': 'en' } },
{ '#': 'FR VALUE', '@': { 'xml:lang': 'fr' } }

];
mockParsing(data);

configParser.parse(configPath, session, extManager, function (configObj) {
expect(configObj.description).toEqual({"default": "This is my app", "EN": "EN VALUE", "FR": "FR VALUE"});
expect(configObj.description).toEqual({"default": "This is my app", "en": "EN VALUE", "fr": "FR VALUE"});
});
});

Expand Down

0 comments on commit 3c73bf3

Please sign in to comment.