CB-10233: Support different config.xml file per CDVViewController instance Add unit test to prove that settings are loaded from the right config file
This closes #186 Project: http://git-wip-us.apache.org/repos/asf/cordova-ios/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-ios/commit/48dfb42b Tree: http://git-wip-us.apache.org/repos/asf/cordova-ios/tree/48dfb42b Diff: http://git-wip-us.apache.org/repos/asf/cordova-ios/diff/48dfb42b Branch: refs/heads/master Commit: 48dfb42b95fc8469986ba7f9d977a43bf2aaf56c Parents: 813a3ba Author: Mirko Luchi <[email protected]> Authored: Wed Dec 23 14:06:52 2015 +0100 Committer: Shazron Abdullah <[email protected]> Committed: Mon Jan 4 17:02:04 2016 -0800 ---------------------------------------------------------------------- tests/CordovaLibTests/CDVViewControllerTest.m | 60 ++++++++++++++++++++ tests/CordovaLibTests/CordovaLibApp/config.xml | 4 +- .../CordovaLibTests.xcodeproj/project.pbxproj | 20 +++++-- tests/CordovaLibTests/config-custom.xml | 23 ++++++++ 4 files changed, 100 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/48dfb42b/tests/CordovaLibTests/CDVViewControllerTest.m ---------------------------------------------------------------------- diff --git a/tests/CordovaLibTests/CDVViewControllerTest.m b/tests/CordovaLibTests/CDVViewControllerTest.m new file mode 100644 index 0000000..dcff8fd --- /dev/null +++ b/tests/CordovaLibTests/CDVViewControllerTest.m @@ -0,0 +1,60 @@ +// +// CDVViewControllerTest.m +// CordovaLibTests +// +// Created by Mirko Luchi on 23/12/15. +// +// + +#import <XCTest/XCTest.h> +#import <Cordova/CDVViewController.h> + +#define CDVViewControllerTestSettingKey @"test_cdvconfigfile" +#define CDVViewControllerTestSettingValueDefault @"config.xml" +#define CDVViewControllerTestSettingValueCustom @"config-custom.xml" + +@interface CDVViewControllerTest : XCTestCase + +@end + +@implementation CDVViewControllerTest + +-(CDVViewController*)viewController{ + CDVViewController* viewController = [CDVViewController new]; + return viewController; +} + +-(void)doTestInitWithConfigFile:(NSString*)configFile expectedSettingValue:(NSString*)value{ + // Create a CDVViewController + CDVViewController* viewController = [self viewController]; + if(configFile){ + // Set custom config file + viewController.configFile = configFile; + }else{ + // Do not specify config file ==> fallback to default config.xml + } + + // Trigger -viewDidLoad + [viewController view]; + + // Assert that the proper file was actually loaded, checking the value of a test setting it must contain + NSString* settingValue = [viewController.settings objectForKey:CDVViewControllerTestSettingKey]; + XCTAssertEqualObjects(settingValue, value); +} + +-(void)testInitWithDefaultConfigFile{ + [self doTestInitWithConfigFile:nil expectedSettingValue:CDVViewControllerTestSettingValueDefault]; +} + +-(void)testInitWithCustomConfigFileAbsolutePath{ + NSString* configFileAbsolutePath = [[NSBundle mainBundle] pathForResource:@"config-custom" ofType:@"xml"]; + [self doTestInitWithConfigFile:configFileAbsolutePath expectedSettingValue:CDVViewControllerTestSettingValueCustom]; +} + +-(void)testInitWithCustomConfigFileRelativePath{ + NSString* configFileRelativePath = @"config-custom.xml"; + [self doTestInitWithConfigFile:configFileRelativePath expectedSettingValue:CDVViewControllerTestSettingValueCustom]; +} + +@end + http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/48dfb42b/tests/CordovaLibTests/CordovaLibApp/config.xml ---------------------------------------------------------------------- diff --git a/tests/CordovaLibTests/CordovaLibApp/config.xml b/tests/CordovaLibTests/CordovaLibApp/config.xml index 8acdea7..5b930fc 100644 --- a/tests/CordovaLibTests/CordovaLibApp/config.xml +++ b/tests/CordovaLibTests/CordovaLibApp/config.xml @@ -49,7 +49,9 @@ <preference name="PageLength" value="0" /> <preference name="PaginationBreakingMode" value="page" /> <!-- page, column --> <preference name="PaginationMode" value="unpaginated" /> <!-- unpaginated, leftToRight, topToBottom, bottomToTop, rightToLeft --> - + <!-- This settings is just used by the CDVViewControllerTest to assert which config file has been loaded --> + <preference name="test_CDVConfigFile" value="config.xml" /> + <feature name="LocalStorage"> <param name="ios-package" value="CDVLocalStorage"/> </feature> http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/48dfb42b/tests/CordovaLibTests/CordovaLibTests.xcodeproj/project.pbxproj ---------------------------------------------------------------------- diff --git a/tests/CordovaLibTests/CordovaLibTests.xcodeproj/project.pbxproj b/tests/CordovaLibTests/CordovaLibTests.xcodeproj/project.pbxproj index c4b9007..023b4a5 100644 --- a/tests/CordovaLibTests/CordovaLibTests.xcodeproj/project.pbxproj +++ b/tests/CordovaLibTests/CordovaLibTests.xcodeproj/project.pbxproj @@ -17,6 +17,8 @@ 30B342F515224B360070E6A5 /* CDVWebViewTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 30B342F415224B360070E6A5 /* CDVWebViewTest.m */; }; 30D1B08C15A2B36D0060C291 /* CDVBase64Tests.m in Sources */ = {isa = PBXBuildFile; fileRef = 30D1B08B15A2B36D0060C291 /* CDVBase64Tests.m */; }; 30F8AE1D152129DA006625B3 /* www in Resources */ = {isa = PBXBuildFile; fileRef = 30F8AE1C152129DA006625B3 /* www */; }; + 5C4C91761C2ACE450055AFC3 /* CDVViewControllerTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 5C4C91751C2ACE450055AFC3 /* CDVViewControllerTest.m */; }; + 5C4C917B1C2AD44E0055AFC3 /* config-custom.xml in Resources */ = {isa = PBXBuildFile; fileRef = 5C4C91771C2ACF130055AFC3 /* config-custom.xml */; }; 686357B5141002F200DF4CF2 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 686357B3141002F200DF4CF2 /* InfoPlist.strings */; }; 686357BA141002F200DF4CF2 /* CDVPluginResultJSONSerializationTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 686357B9141002F200DF4CF2 /* CDVPluginResultJSONSerializationTests.m */; }; 7E91406017711D88002C6A3F /* CDVWebViewDelegateTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E91405F17711D88002C6A3F /* CDVWebViewDelegateTests.m */; }; @@ -54,6 +56,8 @@ 30B342F415224B360070E6A5 /* CDVWebViewTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CDVWebViewTest.m; sourceTree = "<group>"; }; 30D1B08B15A2B36D0060C291 /* CDVBase64Tests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CDVBase64Tests.m; sourceTree = "<group>"; }; 30F8AE1C152129DA006625B3 /* www */ = {isa = PBXFileReference; lastKnownFileType = folder; path = www; sourceTree = "<group>"; }; + 5C4C91751C2ACE450055AFC3 /* CDVViewControllerTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CDVViewControllerTest.m; sourceTree = "<group>"; }; + 5C4C91771C2ACF130055AFC3 /* config-custom.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = "config-custom.xml"; sourceTree = "<group>"; }; 686357A9141002F100DF4CF2 /* CordovaLibTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = CordovaLibTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 686357B2141002F200DF4CF2 /* CordovaLibTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "CordovaLibTests-Info.plist"; sourceTree = "<group>"; }; 686357B4141002F200DF4CF2 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; }; @@ -104,6 +108,7 @@ children = ( 7EF33BD61911ABA20048544E /* [email protected] */, F8EB14D0165FFD3200616F39 /* config.xml */, + 5C4C91771C2ACF130055AFC3 /* config-custom.xml */, EB3B34F4161B585D003DBE7D /* CordovaLibTests */, 303A406D152124BB00182201 /* CordovaLibApp */, 0867D69AFE84028FC02AAC07 /* Frameworks */, @@ -156,18 +161,19 @@ EB3B34F4161B585D003DBE7D /* CordovaLibTests */ = { isa = PBXGroup; children = ( + 30D1B08B15A2B36D0060C291 /* CDVBase64Tests.m */, 30610C9119AD9B95000B3781 /* CDVCommandDelegateTests.m */, - EBA7F20417962CCD001A0CE6 /* CDVStartPageTests.m */, - 7E91405F17711D88002C6A3F /* CDVWebViewDelegateTests.m */, - EB96677116ADBCF500D86CDF /* CDVUserAgentTest.m */, EBA3554415A731F100F4DE24 /* CDVFakeFileManager.h */, EBA3554515A731F100F4DE24 /* CDVFakeFileManager.m */, - EBA3550F15A5F18900F4DE24 /* CDVWebViewTest.h */, - 30B342F415224B360070E6A5 /* CDVWebViewTest.m */, - 30D1B08B15A2B36D0060C291 /* CDVBase64Tests.m */, EB89634915FE66EA00E12277 /* CDVInvokedUrlCommandTests.m */, 3062D1AD151D4D9D000D9128 /* CDVLocalStorageTests.m */, 686357B9141002F200DF4CF2 /* CDVPluginResultJSONSerializationTests.m */, + EBA7F20417962CCD001A0CE6 /* CDVStartPageTests.m */, + EB96677116ADBCF500D86CDF /* CDVUserAgentTest.m */, + 5C4C91751C2ACE450055AFC3 /* CDVViewControllerTest.m */, + 7E91405F17711D88002C6A3F /* CDVWebViewDelegateTests.m */, + EBA3550F15A5F18900F4DE24 /* CDVWebViewTest.h */, + 30B342F415224B360070E6A5 /* CDVWebViewTest.m */, 30356213141049E1006C2D43 /* CDVWhitelistTests.m */, 686357B1141002F200DF4CF2 /* Supporting Files */, ); @@ -253,6 +259,7 @@ 7EF33BD71911ABA20048544E /* [email protected] in Resources */, 303A4072152124BB00182201 /* InfoPlist.strings in Resources */, 30F8AE1D152129DA006625B3 /* www in Resources */, + 5C4C917B1C2AD44E0055AFC3 /* config-custom.xml in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -319,6 +326,7 @@ 30B342F515224B360070E6A5 /* CDVWebViewTest.m in Sources */, 30D1B08C15A2B36D0060C291 /* CDVBase64Tests.m in Sources */, EBA3554615A731F100F4DE24 /* CDVFakeFileManager.m in Sources */, + 5C4C91761C2ACE450055AFC3 /* CDVViewControllerTest.m in Sources */, EB89634A15FE66EA00E12277 /* CDVInvokedUrlCommandTests.m in Sources */, EB96677216ADBCF500D86CDF /* CDVUserAgentTest.m in Sources */, 7E91406017711D88002C6A3F /* CDVWebViewDelegateTests.m in Sources */, http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/48dfb42b/tests/CordovaLibTests/config-custom.xml ---------------------------------------------------------------------- diff --git a/tests/CordovaLibTests/config-custom.xml b/tests/CordovaLibTests/config-custom.xml new file mode 100644 index 0000000..18cf6a4 --- /dev/null +++ b/tests/CordovaLibTests/config-custom.xml @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + --> +<widget> + <!-- This settings is just used by the CDVViewControllerTest to assert which config file has been loaded --> + <preference name="test_CDVConfigFile" value="config-custom.xml" /> +</widget> --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
