cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject [40/50] [abbrv] cordova-common git commit: CB-11908 Add tests for edit-config in config.xml and fix typo
Date Tue, 06 Jun 2017 05:00:08 GMT
CB-11908 Add tests for edit-config in config.xml and fix typo

Add one more test case


Project: http://git-wip-us.apache.org/repos/asf/cordova-common/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-common/commit/e28a9b68
Tree: http://git-wip-us.apache.org/repos/asf/cordova-common/tree/e28a9b68
Diff: http://git-wip-us.apache.org/repos/asf/cordova-common/diff/e28a9b68

Branch: refs/heads/master
Commit: e28a9b683b93a22dbdc737bf574302307431e9aa
Parents: 34016d7
Author: ktop <ktop500@gmail.com>
Authored: Fri Dec 9 14:53:50 2016 -0500
Committer: Steve Gill <stevengill97@gmail.com>
Committed: Wed Apr 19 12:12:43 2017 -0700

----------------------------------------------------------------------
 spec/ConfigChanges/ConfigChanges.spec.js        | 79 ++++++++++++++++++++
 spec/ConfigParser/ConfigParser.spec.js          |  4 +
 .../org.test.editconfigtest_two/plugin.xml      |  2 +-
 spec/fixtures/test-config.xml                   |  9 +++
 spec/fixtures/test-editconfig.xml               | 17 +++++
 src/ConfigChanges/ConfigFile.js                 |  4 +-
 src/util/xml-helpers.js                         |  2 +-
 7 files changed, 113 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-common/blob/e28a9b68/spec/ConfigChanges/ConfigChanges.spec.js
----------------------------------------------------------------------
diff --git a/spec/ConfigChanges/ConfigChanges.spec.js b/spec/ConfigChanges/ConfigChanges.spec.js
index a615b21..5af26a3 100644
--- a/spec/ConfigChanges/ConfigChanges.spec.js
+++ b/spec/ConfigChanges/ConfigChanges.spec.js
@@ -44,6 +44,10 @@ var mungeutil = require('../../src/ConfigChanges/munge-util');
 var PlatformJson = require('../../src/PlatformJson');
 var PluginInfoProvider = require('../../src/PluginInfo/PluginInfoProvider');
 var PluginInfo = require('../../src/PluginInfo/PluginInfo');
+var ConfigParser = require('../../src/ConfigParser/ConfigParser');
+var xml = path.join(__dirname, '../fixtures/test-config.xml');
+var editconfig_xml = path.join(__dirname, '../fixtures/test-editconfig.xml');
+var cfg = new ConfigParser(xml);
 
 // TODO: dont do fs so much
 
@@ -307,6 +311,81 @@ describe('config-changes module', function() {
                     var munger = new configChanges.PlatformMunger('android', temp, platformJson,
pluginInfoProvider);
                     expect(function() {munger.process(plugins_dir);}).toThrow(new Error('There
was a conflict trying to modify attributes with <edit-config> in plugin org.test.editconfigtest_two.
The conflicting plugin, org.test.editconfigtest, already modified the same attributes. The
conflict must be resolved before org.test.editconfigtest_two can be added. You may use --force
to add the plugin and overwrite the conflicting attributes.'));
                 });
+                it('should call graftXMLMerge for every new config.xml config munge with
mode \'merge\' it introduces', function() {
+                    var platformJson = PlatformJson.load(plugins_dir, 'android');
+
+                    var spy = spyOn(xml_helpers, 'graftXMLMerge').andReturn(true);
+
+                    var munger = new configChanges.PlatformMunger('android', temp, platformJson);
+                    munger.add_config_changes(cfg, true);
+
+                    expect(spy.calls.length).toEqual(1);
+                    expect(spy.argsForCall[0][2]).toEqual('/manifest/uses-sdk');
+                });
+                it('should call graftXMLOverwrite for every new config.xml config munge with
mode \'overwrite\' it introduces', function() {
+                    var platformJson = PlatformJson.load(plugins_dir, 'android');
+
+                    var spy = spyOn(xml_helpers, 'graftXMLOverwrite').andReturn(true);
+
+                    var munger = new configChanges.PlatformMunger('android', temp, platformJson);
+                    munger.add_config_changes(cfg, true);
+
+                    expect(spy.calls.length).toEqual(1);
+                    expect(spy.argsForCall[0][2]).toEqual('/manifest/uses-sdk');
+                });
+                it('should call pruneXMLRemove for every new config.xml config munge with
mode \'remove\' it introduces', function() {
+                    var platformJson = PlatformJson.load(plugins_dir, 'android');
+
+                    // var spy = spyOn(xml_helpers, 'pruneXMLRemove').andReturn(true);
+
+                    var munger = new configChanges.PlatformMunger('android', temp, platformJson);
+                    munger.add_config_changes(cfg, true).save_all();
+
+                    var am_xml = new et.ElementTree(et.XML(fs.readFileSync(path.join(temp,
'AndroidManifest.xml'), 'utf-8')));
+                    var sdk = am_xml.find('./uses-sdk');
+
+                    expect(sdk).toBeDefined();
+                    expect(sdk.attrib['android:maxSdkVersion']).toBeUndefined();
+                });
+                it('should overwrite plugin config munge for every conflicting config.xml
config munge', function() {
+                    shell.cp('-rf', editconfigplugin_two, plugins_dir);
+                    var platformJson = PlatformJson.load(plugins_dir, 'android');
+                    platformJson.addInstalledPluginToPrepareQueue('org.test.editconfigtest_two',
{}, true, true);
+
+                    var munger = new configChanges.PlatformMunger('android', temp, platformJson,
pluginInfoProvider);
+                    munger.process(plugins_dir);
+                    munger.add_config_changes(cfg, true).save_all();
+
+                    var am_xml = new et.ElementTree(et.XML(fs.readFileSync(path.join(temp,
'AndroidManifest.xml'), 'utf-8')));
+                    var sdk = am_xml.find('./uses-sdk');
+                    expect(sdk).toBeDefined();
+                    expect(sdk.attrib['android:targetSdkVersion']).toEqual('24');
+                });
+                it('should overwrite config.xml config munge for every new config.xml config
munge that has the same target', function() {
+                    var editconfig_cfg = new ConfigParser(editconfig_xml);
+                    var platformJson = PlatformJson.load(plugins_dir, 'android');
+                    var munger = new configChanges.PlatformMunger('android', temp, platformJson,
pluginInfoProvider);
+
+                    munger.add_config_changes(cfg, true).save_all();
+                    munger.add_config_changes(editconfig_cfg, true).save_all();
+
+                    var am_xml = new et.ElementTree(et.XML(fs.readFileSync(path.join(temp,
'AndroidManifest.xml'), 'utf-8')));
+                    var sdk = am_xml.find('./uses-sdk');
+                    expect(sdk).toBeDefined();
+                    expect(sdk.attrib['android:targetSdkVersion']).toEqual('23');
+                    expect(sdk.attrib['android:minSdkVersion']).toEqual('5');
+                    expect(sdk.attrib['android:maxSdkVersion']).toBeUndefined();
+                });
+                it('should throw error for conflicting plugin config munge with config.xml
config munge', function() {
+                    shell.cp('-rf', editconfigplugin_two, plugins_dir);
+                    var platformJson = PlatformJson.load(plugins_dir, 'android');
+                    platformJson.addInstalledPluginToPrepareQueue('org.test.editconfigtest_two',
{}, true, true);
+
+                    var munger = new configChanges.PlatformMunger('android', temp, platformJson,
pluginInfoProvider);
+                    munger.add_config_changes(cfg, true);
+                    expect(function() {munger.process(plugins_dir);}).toThrow(new Error('org.test.editconfigtest_two
cannot be added. <edit-config> changes in this plugin conflicts with <edit-config>
changes in config.xml. Conflicts must be resolved before plugin can be added.'));
+
+                });
             });
             describe('of plist config files', function() {
                 it('Test 023 : should write empty string nodes with no whitespace', function()
{

http://git-wip-us.apache.org/repos/asf/cordova-common/blob/e28a9b68/spec/ConfigParser/ConfigParser.spec.js
----------------------------------------------------------------------
diff --git a/spec/ConfigParser/ConfigParser.spec.js b/spec/ConfigParser/ConfigParser.spec.js
index fa49550..cfb125b 100644
--- a/spec/ConfigParser/ConfigParser.spec.js
+++ b/spec/ConfigParser/ConfigParser.spec.js
@@ -244,6 +244,10 @@ describe('config.xml parser', function () {
                 var intents = cfg.getAllowIntents();
                 expect(intents.length).not.toEqual(0);
             });
+            it('it should read <edit-config> tag entries', function(){
+                var editConfigs = cfg.getEditConfigs('android');
+                expect(editConfigs.length).not.toEqual(0);
+            });
         });
         describe('static resources', function() {
             var hasPlatformPropertyDefined = function (e) { return !!e.platform; };

http://git-wip-us.apache.org/repos/asf/cordova-common/blob/e28a9b68/spec/fixtures/plugins/org.test.editconfigtest_two/plugin.xml
----------------------------------------------------------------------
diff --git a/spec/fixtures/plugins/org.test.editconfigtest_two/plugin.xml b/spec/fixtures/plugins/org.test.editconfigtest_two/plugin.xml
index 28f9d13..789e607 100644
--- a/spec/fixtures/plugins/org.test.editconfigtest_two/plugin.xml
+++ b/spec/fixtures/plugins/org.test.editconfigtest_two/plugin.xml
@@ -34,7 +34,7 @@
             <activity android:name="ChildApp" android:label="@string/app_name" android:enabled="false"
/>
         </edit-config>
         <edit-config file="AndroidManifest.xml" target="/manifest/uses-sdk" mode="merge">
-            <activity android:maxSdkVersion="23" />
+            <uses-sdk android:maxSdkVersion="24" android:targetSdkVersion="23" />
         </edit-config>
     </platform>
 </plugin>

http://git-wip-us.apache.org/repos/asf/cordova-common/blob/e28a9b68/spec/fixtures/test-config.xml
----------------------------------------------------------------------
diff --git a/spec/fixtures/test-config.xml b/spec/fixtures/test-config.xml
index b64e785..625d218 100644
--- a/spec/fixtures/test-config.xml
+++ b/spec/fixtures/test-config.xml
@@ -90,6 +90,15 @@
         <resource-file src="androidconfig.json" target="androidconfig.json" />
         <preference name="android-minSdkVersion" value="10" />
         <preference name="orientation" value="landscape" />
+        <edit-config file="AndroidManifest.xml" target="/manifest/uses-sdk" mode="merge">
+            <uses-sdk android:targetSdkVersion="24" />
+        </edit-config>
+        <edit-config file="AndroidManifest.xml" target="/manifest/uses-sdk" mode="overwrite">
+            <uses-sdk android:minSdkVersion="14" android:maxSdkVersion="24" android:targetSdkVersion="24"
/>
+        </edit-config>
+        <edit-config file="AndroidManifest.xml" target="/manifest/uses-sdk" mode="remove">
+            <uses-sdk android:maxSdkVersion="24" />
+        </edit-config>
     </platform>
     <platform name="windows">
         <icon src="res/windows/logo.scale-200.png" target="logo.png"/>

http://git-wip-us.apache.org/repos/asf/cordova-common/blob/e28a9b68/spec/fixtures/test-editconfig.xml
----------------------------------------------------------------------
diff --git a/spec/fixtures/test-editconfig.xml b/spec/fixtures/test-editconfig.xml
new file mode 100644
index 0000000..c8f1b56
--- /dev/null
+++ b/spec/fixtures/test-editconfig.xml
@@ -0,0 +1,17 @@
+<?xml version='1.0' encoding='utf-8'?>
+<widget android-packageName="io.cordova.hellocordova.android" id="io.cordova.hellocordova"
ios-CFBundleIdentifier="io.cordova.hellocordova.ios" version="0.0.1" xmlns="http://www.w3.org/ns/widgets"
xmlns:cdv="http://cordova.apache.org/ns/1.0">
+    <name>Hello Cordova</name>
+    <description>
+        A sample Apache Cordova application that responds to the deviceready event.
+    </description>
+    <author email="dev@cordova.apache.org" href="http://cordova.io">
+        Apache Cordova Team
+    </author>
+    <content src="index.html" />
+    <access origin="*" />
+    <platform name="android">
+        <edit-config file="AndroidManifest.xml" target="/manifest/uses-sdk" mode="merge">
+            <uses-sdk android:targetSdkVersion="23" />
+        </edit-config>
+    </platform>
+</widget>

http://git-wip-us.apache.org/repos/asf/cordova-common/blob/e28a9b68/src/ConfigChanges/ConfigFile.js
----------------------------------------------------------------------
diff --git a/src/ConfigChanges/ConfigFile.js b/src/ConfigChanges/ConfigFile.js
index 4a58008..8f880a4 100644
--- a/src/ConfigChanges/ConfigFile.js
+++ b/src/ConfigChanges/ConfigFile.js
@@ -111,7 +111,7 @@ ConfigFile.prototype.graft_child = function ConfigFile_graft_child(selector,
xml
                 result = modules.xml_helpers.graftXMLOverwrite(self.data, xml_to_graft, selector,
xml_child);
                 break;
             case 'remove':
-                result= true;
+                result = modules.xml_helpers.pruneXMLRemove(self.data, selector, xml_to_graft);
                 break;
             default:
                 result = modules.xml_helpers.graftXML(self.data, xml_to_graft, selector,
xml_child.after);
@@ -141,7 +141,7 @@ ConfigFile.prototype.prune_child = function ConfigFile_prune_child(selector,
xml
                 result = modules.xml_helpers.pruneXMLRestore(self.data, selector, xml_child);
                 break;
             case 'remove':
-                result = modules.xml_helpers.prunXMLRemove(self.data, selector, xml_to_graft);
+                result = modules.xml_helpers.pruneXMLRemove(self.data, selector, xml_to_graft);
                 break;
             default:
                 result = modules.xml_helpers.pruneXML(self.data, xml_to_graft, selector);

http://git-wip-us.apache.org/repos/asf/cordova-common/blob/e28a9b68/src/util/xml-helpers.js
----------------------------------------------------------------------
diff --git a/src/util/xml-helpers.js b/src/util/xml-helpers.js
index b4b0490..cc2eb0f 100644
--- a/src/util/xml-helpers.js
+++ b/src/util/xml-helpers.js
@@ -160,7 +160,7 @@ module.exports = {
         return true;
     },
 
-    prunXMLRemove: function(doc, selector, nodes) {
+    pruneXMLRemove: function(doc, selector, nodes) {
         var target = module.exports.resolveParent(doc, selector);
         if (!target) return false;
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message