diff --git a/bin/templates/cordova/lib/builders/ProjectBuilder.js b/bin/templates/cordova/lib/builders/ProjectBuilder.js index c5ad00d34a..dd1e58ebd7 100644 --- a/bin/templates/cordova/lib/builders/ProjectBuilder.js +++ b/bin/templates/cordova/lib/builders/ProjectBuilder.js @@ -89,7 +89,7 @@ class ProjectBuilder { }; } - extractRealProjectNameFromManifest () { + getAndroidManifestInfo () { var manifestPath = path.join(this.root, 'app', 'src', 'main', 'AndroidManifest.xml'); var manifestData = fs.readFileSync(manifestPath, 'utf8'); var m = / { }); }); - describe('extractRealProjectNameFromManifest', () => { + describe('getAndroidManifestInfo', () => { it('should get the project name from the Android Manifest', () => { const projectName = 'unittestproject'; const projectId = `io.cordova.${projectName}`; - const manifest = ` - `; + const manifest = + ` + + + `; spyOn(fs, 'readFileSync').and.returnValue(manifest); - expect(builder.extractRealProjectNameFromManifest()).toBe(projectName); + expect(builder.getAndroidManifestInfo().packageName).toBe(projectId); + }); + + it('should get the min & target SDK versions from the Android Manifest', () => { + const projectName = 'unittestproject'; + const projectId = `io.cordova.${projectName}`; + const manifest = + ` + + + `; + + spyOn(fs, 'readFileSync').and.returnValue(manifest); + + expect(builder.getAndroidManifestInfo().minSdkVersion).toBe(22); + expect(builder.getAndroidManifestInfo().targetSdkVersion).toBe(25); }); it('should throw an error if there is no package in the Android manifest', () => { - const manifest = ` - `; + const manifest = + ` + + + `; + + spyOn(fs, 'readFileSync').and.returnValue(manifest); + + expect(() => builder.getAndroidManifestInfo()).toThrow(jasmine.any(CordovaError)); + }); + + it('should throw an error if there is no android:minSdkVersion in the Android manifest', () => { + const projectName = 'unittestproject'; + const projectId = `io.cordova.${projectName}`; + const manifest = + ` + + + `; + + spyOn(fs, 'readFileSync').and.returnValue(manifest); + + expect(() => builder.getAndroidManifestInfo()).toThrow(jasmine.any(CordovaError)); + }); + + it('should throw an error if there is no android:targetSdkVersion in the Android manifest', () => { + const projectName = 'unittestproject'; + const projectId = `io.cordova.${projectName}`; + const manifest = + ` + + + `; spyOn(fs, 'readFileSync').and.returnValue(manifest); - expect(() => builder.extractRealProjectNameFromManifest()).toThrow(jasmine.any(CordovaError)); + expect(() => builder.getAndroidManifestInfo()).toThrow(jasmine.any(CordovaError)); }); });