Skip to content
Permalink
Browse files
Revert "CB-6344: Specify after which sibling to add config-changes in…
… plugin.xml"

This reverts commit ac1160d.

It broke CLI's unit tests.
  • Loading branch information
agrieve committed Mar 31, 2014
1 parent 54fc858 commit e85004a125cd43f14203eeffea265a40a06cb6e4
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 285 deletions.
@@ -70,11 +70,6 @@ describe('wp8 project handler', function() {
});

describe('installation', function() {
var done;
function installPromise(f) {
done = false;
f.then(function() { done = true; }, function(err) { done = err; });
}
beforeEach(function() {
shell.mkdir('-p', temp);
});
@@ -107,22 +102,6 @@ describe('wp8 project handler', function() {
}).toThrow('"' + target + '" already exists!');
});
});
describe('of <config-changes> elements', function() {
beforeEach(function() {
shell.cp('-rf', path.join(wp8_project, '*'), temp);
});
it('should process and pass the after parameter to graftXML', function () {
var graftXML = spyOn(xml_helpers, 'graftXML').andCallThrough();

runs(function () { installPromise(install('wp8', temp, dummyplugin, plugins_dir, {})); });
waitsFor(function () { return done; }, 'install promise never resolved', 500);
runs(function () {
expect(graftXML).toHaveBeenCalledWith(jasmine.any(Object), jasmine.any(Array), "/Deployment/App", "Tokens");
expect(graftXML).toHaveBeenCalledWith(jasmine.any(Object), jasmine.any(Array), "/Deployment/App/Extensions", "Extension");
expect(graftXML).toHaveBeenCalledWith(jasmine.any(Object), jasmine.any(Array), "/Deployment/App/Extensions", "FileTypeAssociation;Extension");
});
});
});
});

describe('uninstallation', function() {
@@ -155,28 +155,6 @@
<feature id="dummyPlugin" required="true" version="1.0.0.0"/>
</config-file>

<config-file target="Properties/WMAppManifest.xml" parent="/Deployment/App" after="Tokens">
<Extensions />
</config-file>

<config-file target="Properties/WMAppManifest.xml" parent="/Deployment/App/Extensions" after="Extension">
<Extension ExtensionName="DummyExtension1" ConsumerID="{5B04B775-356B-4AA0-AAF8-6491FFEA5661}" TaskID="_default" ExtraFile="Extensions\\Extras.xml" />
<Extension ExtensionName="DummyExtension2" ConsumerID="{5B04B775-356B-4AA0-AAF8-6491FFEA5661}" TaskID="_default" ExtraFile="Extensions\\Extras.xml" />
</config-file>

<config-file target="Properties/WMAppManifest.xml" parent="/Deployment/App/Extensions" after="FileTypeAssociation;Extension">
<FileTypeAssociation TaskID="_default" Name="DummyFileType1" NavUriFragment="fileToken=%s">
<SupportedFileTypes>
<FileType ContentType="application/dummy1">.dummy1</FileType>
</SupportedFileTypes>
</FileTypeAssociation>
<FileTypeAssociation TaskID="_default" Name="DummyFileType2" NavUriFragment="fileToken=%s">
<SupportedFileTypes>
<FileType ContentType="application/dummy2">.dummy2</FileType>
</SupportedFileTypes>
</FileTypeAssociation>
</config-file>

<source-file src="src/wp8/DummyPlugin.cs"/>
<js-module src="www/dummyplugin.js" name="Dummy">
<clobbers target="dummy" />
@@ -118,10 +118,7 @@ describe('config-changes module', function() {
});
it('should return the json file if it exists', function() {
var filepath = path.join(plugins_dir, 'android.json');
var json = {
prepare_queue: {installed: [], uninstalled: []},
config_munge: {files: {"some_file": {parents: {"some_parent": [{"xml": "some_change", "count": 1}]}}}},
installed_plugins: {}};
var json = {prepare_queue:{installed:[],uninstalled:[]},config_munge:{somechange:"blah"},installed_plugins:{}};
fs.writeFileSync(filepath, JSON.stringify(json), 'utf-8');
var cfg = configChanges.get_platform_json(plugins_dir, 'android');
expect(JSON.stringify(json)).toEqual(JSON.stringify(cfg));
@@ -147,65 +144,64 @@ describe('config-changes module', function() {
var xml;
var munger = new configChanges.PlatformMunger('android', temp, 'unused');
var munge = munger.generate_plugin_config_munge(dummyplugin, {});
expect(munge.files['AndroidManifest.xml']).toBeDefined();
expect(munge.files['AndroidManifest.xml'].parents['/manifest/application']).toBeDefined();
expect(munge['AndroidManifest.xml']).toBeDefined();
expect(munge['AndroidManifest.xml']['/manifest/application']).toBeDefined();
xml = (new et.ElementTree(dummy_xml.find('./platform[@name="android"]/config-file[@target="AndroidManifest.xml"]'))).write({xml_declaration:false});
xml = innerXML(xml);
expect(configChanges.get_munge_change(munge, 'AndroidManifest.xml', '/manifest/application', xml).count).toEqual(1);
expect(munge.files['res/xml/plugins.xml']).toBeDefined();
expect(munge.files['res/xml/plugins.xml'].parents['/plugins']).toBeDefined();
expect(munge['AndroidManifest.xml']['/manifest/application'][xml]).toEqual(1);
expect(munge['res/xml/plugins.xml']).toBeDefined();
expect(munge['res/xml/plugins.xml']['/plugins']).toBeDefined();
xml = (new et.ElementTree(dummy_xml.find('./platform[@name="android"]/config-file[@target="res/xml/plugins.xml"]'))).write({xml_declaration:false});
xml = innerXML(xml);
expect(configChanges.get_munge_change(munge, 'res/xml/plugins.xml', '/plugins', xml).count).toEqual(1);
expect(munge.files['res/xml/config.xml']).toBeDefined();
expect(munge.files['res/xml/config.xml'].parents['/cordova/plugins']).toBeDefined();
expect(munge['res/xml/plugins.xml']['/plugins'][xml]).toEqual(1);
expect(munge['res/xml/config.xml']).toBeDefined();
expect(munge['res/xml/config.xml']['/cordova/plugins']).toBeDefined();
xml = (new et.ElementTree(dummy_xml.find('./platform[@name="android"]/config-file[@target="res/xml/config.xml"]'))).write({xml_declaration:false});
xml = innerXML(xml);
expect(configChanges.get_munge_change(munge, 'res/xml/config.xml', '/cordova/plugins', xml).count).toEqual(1);
expect(munge['res/xml/config.xml']['/cordova/plugins'][xml]).toEqual(1);
});
it('should split out multiple children of config-file elements into individual leaves', function() {
var munger = new configChanges.PlatformMunger('android', temp, 'unused');
var munge = munger.generate_plugin_config_munge(childrenplugin, {});
expect(munge.files['AndroidManifest.xml']).toBeDefined();
expect(munge.files['AndroidManifest.xml'].parents['/manifest']).toBeDefined();
expect(configChanges.get_munge_change(munge, 'AndroidManifest.xml', '/manifest', '<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />')).toBeDefined();
expect(configChanges.get_munge_change(munge, 'AndroidManifest.xml', '/manifest', '<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />')).toBeDefined();
expect(configChanges.get_munge_change(munge, 'AndroidManifest.xml', '/manifest', '<uses-permission android:name="android.permission.READ_PHONE_STATE" />')).toBeDefined();
expect(configChanges.get_munge_change(munge, 'AndroidManifest.xml', '/manifest', '<uses-permission android:name="android.permission.INTERNET" />')).toBeDefined();
expect(configChanges.get_munge_change(munge, 'AndroidManifest.xml', '/manifest', '<uses-permission android:name="android.permission.GET_ACCOUNTS" />')).toBeDefined();
expect(configChanges.get_munge_change(munge, 'AndroidManifest.xml', '/manifest', '<uses-permission android:name="android.permission.WAKE_LOCK" />')).toBeDefined();
expect(configChanges.get_munge_change(munge, 'AndroidManifest.xml', '/manifest', '<permission android:name="com.alunny.childapp.permission.C2D_MESSAGE" android:protectionLevel="signature" />')).toBeDefined();
expect(configChanges.get_munge_change(munge, 'AndroidManifest.xml', '/manifest', '<uses-permission android:name="com.alunny.childapp.permission.C2D_MESSAGE" />')).toBeDefined();
expect(configChanges.get_munge_change(munge, 'AndroidManifest.xml', '/manifest', '<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />')).toBeDefined();
expect(munge['AndroidManifest.xml']).toBeDefined();
expect(munge['AndroidManifest.xml']['/manifest']).toBeDefined();
expect(munge['AndroidManifest.xml']['/manifest']['<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />']).toBeDefined();
expect(munge['AndroidManifest.xml']['/manifest']['<uses-permission android:name="android.permission.READ_PHONE_STATE" />']).toBeDefined();
expect(munge['AndroidManifest.xml']['/manifest']['<uses-permission android:name="android.permission.INTERNET" />']).toBeDefined();
expect(munge['AndroidManifest.xml']['/manifest']['<uses-permission android:name="android.permission.GET_ACCOUNTS" />']).toBeDefined();
expect(munge['AndroidManifest.xml']['/manifest']['<uses-permission android:name="android.permission.WAKE_LOCK" />']).toBeDefined();
expect(munge['AndroidManifest.xml']['/manifest']['<permission android:name="com.alunny.childapp.permission.C2D_MESSAGE" android:protectionLevel="signature" />']).toBeDefined();
expect(munge['AndroidManifest.xml']['/manifest']['<uses-permission android:name="com.alunny.childapp.permission.C2D_MESSAGE" />']).toBeDefined();
expect(munge['AndroidManifest.xml']['/manifest']['<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />']).toBeDefined();
});
it('should not use xml comments as config munge leaves', function() {
var munger = new configChanges.PlatformMunger('android', temp, 'unused');
var munge = munger.generate_plugin_config_munge(childrenplugin, {});
expect(configChanges.get_munge_change(munge, 'AndroidManifest.xml', '/manifest', '<!--library-->')).not.toBeDefined();
expect(configChanges.get_munge_change(munge, 'AndroidManifest.xml', '/manifest', '<!-- GCM connects to Google Services. -->')).not.toBeDefined();
expect(munge['AndroidManifest.xml']['/manifest']['<!--library-->']).not.toBeDefined();
expect(munge['AndroidManifest.xml']['/manifest']['<!-- GCM connects to Google Services. -->']).not.toBeDefined();
});
it('should increment config heirarchy leaves if dfferent config-file elements target the same file + selector + xml', function() {
var munger = new configChanges.PlatformMunger('android', temp, 'unused');
var munge = munger.generate_plugin_config_munge(configplugin, {});
expect(configChanges.get_munge_change(munge, 'res/xml/config.xml', '/widget', '<poop />').count).toEqual(2);
expect(munge['res/xml/config.xml']['/widget']['<poop />']).toEqual(2);
});
it('should take into account interpolation variables', function() {
var munger = new configChanges.PlatformMunger('android', temp, 'unused');
var munge = munger.generate_plugin_config_munge(childrenplugin, {PACKAGE_NAME:'ca.filmaj.plugins'});
expect(configChanges.get_munge_change(munge, 'AndroidManifest.xml', '/manifest', '<uses-permission android:name="ca.filmaj.plugins.permission.C2D_MESSAGE" />')).toBeDefined();
expect(munge['AndroidManifest.xml']['/manifest']['<uses-permission android:name="ca.filmaj.plugins.permission.C2D_MESSAGE" />']).toBeDefined();
});
it('should create munges for platform-agnostic config.xml changes', function() {
var munger = new configChanges.PlatformMunger('android', temp, 'unused');
var munge = munger.generate_plugin_config_munge(dummyplugin, {});
expect(configChanges.get_munge_change(munge, 'config.xml', '/*', '<access origin="build.phonegap.com" />')).toBeDefined();
expect(configChanges.get_munge_change(munge, 'config.xml', '/*', '<access origin="s3.amazonaws.com" />')).toBeDefined();
expect(munge['config.xml']['/*']['<access origin="build.phonegap.com" />']).toBeDefined();
expect(munge['config.xml']['/*']['<access origin="s3.amazonaws.com" />']).toBeDefined();
});
it('should automatically add on app java identifier as PACKAGE_NAME variable for android config munges', function() {
shell.cp('-rf', android_two_project, temp);
var munger = new configChanges.PlatformMunger('android', temp, 'unused');
var munge = munger.generate_plugin_config_munge(varplugin, {});
var expected_xml = '<package>com.alunny.childapp</package>';
expect(configChanges.get_munge_change(munge, 'AndroidManifest.xml', '/manifest', expected_xml)).toBeDefined();
expect(munge['AndroidManifest.xml']['/manifest'][expected_xml]).toBeDefined();
});
});

@@ -217,16 +213,16 @@ describe('config-changes module', function() {
var munger = new configChanges.PlatformMunger('ios', temp, 'unused');
var munge = munger.generate_plugin_config_munge(varplugin, {});
var expected_xml = '<cfbundleid>com.example.friendstring</cfbundleid>';
expect(configChanges.get_munge_change(munge, 'config.xml', '/widget', expected_xml)).toBeDefined();
expect(munge['config.xml']['/widget'][expected_xml]).toBeDefined();
});
it('should special case framework elements for ios', function() {
var munger = new configChanges.PlatformMunger('ios', temp, 'unused');
var munge = munger.generate_plugin_config_munge(cbplugin, {});
expect(munge.files['framework']).toBeDefined();
expect(configChanges.get_munge_change(munge, 'framework', 'libsqlite3.dylib', 'false')).toBeDefined();
expect(configChanges.get_munge_change(munge, 'framework', 'social.framework', 'true')).toBeDefined();
expect(configChanges.get_munge_change(munge, 'framework', 'music.framework', 'false')).toBeDefined();
expect(munge.files['framework'].parents['Custom.framework']).not.toBeDefined();
expect(munge['framework']).toBeDefined();
expect(munge['framework']['libsqlite3.dylib']['false']).toBeDefined();
expect(munge['framework']['social.framework']['true']).toBeDefined();
expect(munge['framework']['music.framework']['false']).toBeDefined();
expect(munge['framework']['Custom.framework']).not.toBeDefined();
});
});
});
@@ -139,32 +139,5 @@ describe('xml-helpers', function(){
selector= "/bookstore/book[price>35]/title";
expect(xml_helpers.graftXML(doc, children, selector)).toBe(false);
});

it('appends children after the specified sibling', function () {
var doc = new et.ElementTree(et.XML('<widget><A/><B/><C/></widget>')),
children = [et.XML('<B id="new"/>'), et.XML('<B id="new2"/>')],
selector= "/widget",
after= "B;A";
expect(xml_helpers.graftXML(doc, children, selector, after)).toBe(true);
expect(et.tostring(doc.getroot())).toContain('<B /><B id="new" /><B id="new2" />');
});

it('appends children after the 2nd priority sibling if the 1st one is missing', function () {
var doc = new et.ElementTree(et.XML('<widget><A/><C/></widget>')),
children = [et.XML('<B id="new"/>'), et.XML('<B id="new2"/>')],
selector= "/widget",
after= "B;A";
expect(xml_helpers.graftXML(doc, children, selector, after)).toBe(true);
expect(et.tostring(doc.getroot())).toContain('<A /><B id="new" /><B id="new2" />');
});

it('inserts children at the beginning if specified sibling is missing', function () {
var doc = new et.ElementTree(et.XML('<widget><B/><C/></widget>')),
children = [et.XML('<A id="new"/>'), et.XML('<A id="new2"/>')],
selector= "/widget",
after= "A";
expect(xml_helpers.graftXML(doc, children, selector, after)).toBe(true);
expect(et.tostring(doc.getroot())).toContain('<widget><A id="new" /><A id="new2" />');
});
});
});

0 comments on commit e85004a

Please sign in to comment.