Repository: cordova-lib Updated Branches: refs/heads/master 036904536 -> 93672b7fe
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-lib/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-lib/commit/48e65621 Tree: http://git-wip-us.apache.org/repos/asf/cordova-lib/tree/48e65621 Diff: http://git-wip-us.apache.org/repos/asf/cordova-lib/diff/48e65621 Branch: refs/heads/master Commit: 48e65621d64a75c5d6d4bf53406e83a566daf0da Parents: 0369045 Author: ktop <[email protected]> Authored: Fri Dec 9 14:53:50 2016 -0500 Committer: Steve Gill <[email protected]> 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 +- cordova-common/spec/fixtures/test-config.xml | 9 +++ .../spec/fixtures/test-editconfig.xml | 17 +++++ cordova-common/src/ConfigChanges/ConfigFile.js | 4 +- cordova-common/src/util/xml-helpers.js | 2 +- 7 files changed, 113 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/48e65621/cordova-common/spec/ConfigChanges/ConfigChanges.spec.js ---------------------------------------------------------------------- diff --git a/cordova-common/spec/ConfigChanges/ConfigChanges.spec.js b/cordova-common/spec/ConfigChanges/ConfigChanges.spec.js index a615b21..5af26a3 100644 --- a/cordova-common/spec/ConfigChanges/ConfigChanges.spec.js +++ b/cordova-common/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-lib/blob/48e65621/cordova-common/spec/ConfigParser/ConfigParser.spec.js ---------------------------------------------------------------------- diff --git a/cordova-common/spec/ConfigParser/ConfigParser.spec.js b/cordova-common/spec/ConfigParser/ConfigParser.spec.js index fa49550..cfb125b 100644 --- a/cordova-common/spec/ConfigParser/ConfigParser.spec.js +++ b/cordova-common/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-lib/blob/48e65621/cordova-common/spec/fixtures/plugins/org.test.editconfigtest_two/plugin.xml ---------------------------------------------------------------------- diff --git a/cordova-common/spec/fixtures/plugins/org.test.editconfigtest_two/plugin.xml b/cordova-common/spec/fixtures/plugins/org.test.editconfigtest_two/plugin.xml index 28f9d13..789e607 100644 --- a/cordova-common/spec/fixtures/plugins/org.test.editconfigtest_two/plugin.xml +++ b/cordova-common/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-lib/blob/48e65621/cordova-common/spec/fixtures/test-config.xml ---------------------------------------------------------------------- diff --git a/cordova-common/spec/fixtures/test-config.xml b/cordova-common/spec/fixtures/test-config.xml index b64e785..625d218 100644 --- a/cordova-common/spec/fixtures/test-config.xml +++ b/cordova-common/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-lib/blob/48e65621/cordova-common/spec/fixtures/test-editconfig.xml ---------------------------------------------------------------------- diff --git a/cordova-common/spec/fixtures/test-editconfig.xml b/cordova-common/spec/fixtures/test-editconfig.xml new file mode 100644 index 0000000..c8f1b56 --- /dev/null +++ b/cordova-common/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="[email protected]" 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-lib/blob/48e65621/cordova-common/src/ConfigChanges/ConfigFile.js ---------------------------------------------------------------------- diff --git a/cordova-common/src/ConfigChanges/ConfigFile.js b/cordova-common/src/ConfigChanges/ConfigFile.js index 4a58008..8f880a4 100644 --- a/cordova-common/src/ConfigChanges/ConfigFile.js +++ b/cordova-common/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-lib/blob/48e65621/cordova-common/src/util/xml-helpers.js ---------------------------------------------------------------------- diff --git a/cordova-common/src/util/xml-helpers.js b/cordova-common/src/util/xml-helpers.js index b4b0490..cc2eb0f 100644 --- a/cordova-common/src/util/xml-helpers.js +++ b/cordova-common/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: [email protected] For additional commands, e-mail: [email protected]
