Merge branch 'CB-10694'
authorShazron Abdullah <shazron@apache.org>
Wed, 16 Mar 2016 23:38:28 +0000 (16:38 -0700)
committerShazron Abdullah <shazron@apache.org>
Wed, 16 Mar 2016 23:38:28 +0000 (16:38 -0700)
1  2 
spec/util/xml-helpers.spec.js
src/util/xml-helpers.js

@@@ -268,26 -268,25 +268,45 @@@ describe('xml-helpers', function()
  
          });
          
 -        
 +        it('should remove duplicate preferences (by name attribute value)', function () {
 +            var testXml = et.XML(
 +                '<?xml version="1.0" encoding="UTF-8"?>\n' +
 +                '<widget xmlns     = "http://www.w3.org/ns/widgets"\n' +
 +                '        xmlns:cdv = "http://cordova.apache.org/ns/1.0"\n' +
 +                '        id        = "io.cordova.hellocordova"\n' +
 +                '        version   = "0.0.1">\n' +
 +                '    <preference name="Orientation" value="default" />\n' +
 +                '    <preference name="Orientation" value="portrait" />\n' +
 +                '    <preference name="Orientation" value="landscape" />\n' +
 +                '    <platform name="ios">\n' +
 +                '        <preference name="Orientation" value="all" />\n' +
 +                '        <preference name="Orientation" value="portrait" />\n' +
 +                '    </platform>\n' +
 +                '</widget>\n'
 +            );
 +            xml_helpers.mergeXml(testXml, dstXml, 'ios');
 +            var testElements = dstXml.findall('preference[@name="Orientation"]');
 +            expect(testElements.length).toEqual(1);
 +        });
 +                
+         it('should merge preferences, with platform preferences written last', function () {
+             var testXml = et.XML(
+                 '<?xml version="1.0" encoding="UTF-8"?>\n' +
+                 '<widget xmlns     = "http://www.w3.org/ns/widgets"\n' +
+                 '        xmlns:cdv = "http://cordova.apache.org/ns/1.0"\n' +
+                 '        id        = "io.cordova.hellocordova"\n' +
+                 '        version   = "0.0.1">\n' +
+                 '    <preference name="Orientation" value="default" />\n' +
+                 '    <platform name="ios">\n' +
+                 '        <preference name="Orientation" value="all" />\n' +
+                 '    </platform>\n' +
+                 '</widget>\n'
+             );
+             xml_helpers.mergeXml(testXml, dstXml, 'ios');
+             var testElements = dstXml.findall('preference[@name="Orientation"]');
+             expect(testElements.length).toEqual(2);
+             expect(testElements[0].attrib.value).toEqual('default');
+             expect(testElements[1].attrib.value).toEqual('all');
+         });
      });
  });
@@@ -216,12 -219,6 +219,9 @@@ function mergeXml(src, dest, platform, 
          });
      }
  
-     //Handle children
-     src.getchildren().forEach(mergeChild);
-     
 +    //Handle duplicate preference tags (by name attribute)
 +    removeDuplicatePreferences(dest);
 +
      function mergeChild (srcChild) {
          var srcTag = srcChild.tag,
              destChild = new et.Element(srcTag),