Skip to content

Commit e12a703

Browse files
authored
Move message templates into their individual classes (#338)
1 parent 4eb7bb8 commit e12a703

25 files changed

+1083
-1186
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ osx_image: xcode11.3
33

44
xcode_workspace: Example/Leanplum-SDK.xcworkspace
55
xcode_scheme: Leanplum-SDK-Example
6-
xcode_destination: platform=iOS Simulator,OS=12.4,name=iPhone X
6+
xcode_destination: platform=iOS Simulator,OS=13.3,name=iPhone 11
77

88
cache: cocoapods
99
podfile: Example/Podfile

Example/Leanplum-SDK.xcodeproj/project.pbxproj

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@
104104
A8CB8A36227276A400E1001D /* LeanplumRequestTest.m in Sources */ = {isa = PBXBuildFile; fileRef = A8CB8A35227276A400E1001D /* LeanplumRequestTest.m */; };
105105
A8EEA1AB20E44B0B00FF9A4D /* start_with_variant_debug_info_response.json in Resources */ = {isa = PBXBuildFile; fileRef = A8EEA1AA20E44B0A00FF9A4D /* start_with_variant_debug_info_response.json */; };
106106
A8EEA1AC20E44B0B00FF9A4D /* start_with_variant_debug_info_response.json in Resources */ = {isa = PBXBuildFile; fileRef = A8EEA1AA20E44B0A00FF9A4D /* start_with_variant_debug_info_response.json */; };
107+
A8F5D58823F3488600313C98 /* LPBaseInterstitialMessageTemplateTest.m in Sources */ = {isa = PBXBuildFile; fileRef = A8F5D58623F3483E00313C98 /* LPBaseInterstitialMessageTemplateTest.m */; };
108+
A8F5D58A23F34AD400313C98 /* LPBasePushMessageTemplateTest.m in Sources */ = {isa = PBXBuildFile; fileRef = A8F5D58923F34AD400313C98 /* LPBasePushMessageTemplateTest.m */; };
107109
B449EB2A21F27AB2005C93B6 /* TiedPrioritiesDifferentDelay.json in Resources */ = {isa = PBXBuildFile; fileRef = B449EB2921F27AB2005C93B6 /* TiedPrioritiesDifferentDelay.json */; };
108110
B449EB2B21F27B0B005C93B6 /* TiedPrioritiesDifferentDelay.json in Resources */ = {isa = PBXBuildFile; fileRef = B449EB2921F27AB2005C93B6 /* TiedPrioritiesDifferentDelay.json */; };
109111
/* End PBXBuildFile section */
@@ -208,6 +210,8 @@
208210
A84527FC215C3035001FA20D /* LPRequestTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LPRequestTest.m; sourceTree = "<group>"; };
209211
A8CB8A35227276A400E1001D /* LeanplumRequestTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LeanplumRequestTest.m; sourceTree = "<group>"; };
210212
A8EEA1AA20E44B0A00FF9A4D /* start_with_variant_debug_info_response.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = start_with_variant_debug_info_response.json; sourceTree = "<group>"; };
213+
A8F5D58623F3483E00313C98 /* LPBaseInterstitialMessageTemplateTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LPBaseInterstitialMessageTemplateTest.m; sourceTree = "<group>"; };
214+
A8F5D58923F34AD400313C98 /* LPBasePushMessageTemplateTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LPBasePushMessageTemplateTest.m; sourceTree = "<group>"; };
211215
B449EB2921F27AB2005C93B6 /* TiedPrioritiesDifferentDelay.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = TiedPrioritiesDifferentDelay.json; sourceTree = "<group>"; };
212216
B5CCCA2C1D74B64D005ADEE1 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
213217
B5CCCA2E1D74B64D005ADEE1 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
@@ -268,6 +272,8 @@
268272
07E5C87E1F052B7800A4B092 /* LeanplumTest.m */,
269273
07E5C87F1F052B7800A4B092 /* LPJSONTest.m */,
270274
07E5C8801F052B7800A4B092 /* MessagesTest.m */,
275+
A8F5D58623F3483E00313C98 /* LPBaseInterstitialMessageTemplateTest.m */,
276+
A8F5D58923F34AD400313C98 /* LPBasePushMessageTemplateTest.m */,
271277
07E5C8811F052B7800A4B092 /* LPMessageTemplatesClassTest.m */,
272278
07E5C8821F052B7800A4B092 /* NewsfeedTest.m */,
273279
07E5C8891F052B7800A4B092 /* LPUtilsTest.m */,
@@ -764,13 +770,15 @@
764770
07E5C8B21F052B7800A4B092 /* LPNetworkOperation+Category.m in Sources */,
765771
65E53E982148786C00A05040 /* LPCountAggregatorTest.m in Sources */,
766772
07E5C8B91F052B7800A4B092 /* LPMessageTemplatesClassTest.m in Sources */,
773+
A8F5D58A23F34AD400313C98 /* LPBasePushMessageTemplateTest.m in Sources */,
767774
07E5C8B11F052B7800A4B092 /* LPNetworkEngine+Category.m in Sources */,
768775
07E5C8B61F052B7800A4B092 /* LeanplumTest.m in Sources */,
769776
65E189C6216BDB82005E6B93 /* LPRequestFactoryTest.m in Sources */,
770777
07E5C8AD1F052B7800A4B092 /* LPEventDataManagerTest.m in Sources */,
771778
65E189C421643631005E6B93 /* LPRequestSenderTest.m in Sources */,
772779
07E5C8AE1F052B7800A4B092 /* ExceptionsTest.m in Sources */,
773780
A84527FD215C3035001FA20D /* LPRequestTest.m in Sources */,
781+
A8F5D58823F3488600313C98 /* LPBaseInterstitialMessageTemplateTest.m in Sources */,
774782
07E5C8AC1F052B7800A4B092 /* LPAppIconManagerTest.m in Sources */,
775783
07E5C8BA1F052B7800A4B092 /* NewsfeedTest.m in Sources */,
776784
07E5C8AB1F052B7800A4B092 /* LPActionManagerTest.m in Sources */,
@@ -930,7 +938,7 @@
930938
GCC_PRECOMPILE_PREFIX_HEADER = YES;
931939
GCC_PREFIX_HEADER = "Leanplum-SDK/Leanplum-SDK-Prefix.pch";
932940
INFOPLIST_FILE = "Leanplum-SDK/Leanplum-SDK-Info.plist";
933-
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
941+
IPHONEOS_DEPLOYMENT_TARGET = 13.2;
934942
MODULE_NAME = ExampleApp;
935943
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.${PRODUCT_NAME:rfc1034identifier}";
936944
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -948,7 +956,7 @@
948956
GCC_PRECOMPILE_PREFIX_HEADER = YES;
949957
GCC_PREFIX_HEADER = "Leanplum-SDK/Leanplum-SDK-Prefix.pch";
950958
INFOPLIST_FILE = "Leanplum-SDK/Leanplum-SDK-Info.plist";
951-
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
959+
IPHONEOS_DEPLOYMENT_TARGET = 13.2;
952960
MODULE_NAME = ExampleApp;
953961
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.${PRODUCT_NAME:rfc1034identifier}";
954962
PRODUCT_NAME = "$(TARGET_NAME)";

Example/Tests/Classes/LPActionManagerTest.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ - (void)test_push_token
240240
UIApplication *app = [UIApplication sharedApplication];
241241
XCTestExpectation *expectNewToken = [self expectationWithDescription:@"expectNewToken"];
242242
NSData *token = [@"sample" dataUsingEncoding:NSUTF8StringEncoding];
243-
NSString *formattedToken = [token description];
243+
NSString *formattedToken = [manager hexadecimalStringFromData:token];
244244
formattedToken = [[[formattedToken stringByReplacingOccurrencesOfString:@"<" withString:@""]
245245
stringByReplacingOccurrencesOfString:@">" withString:@""]
246246
stringByReplacingOccurrencesOfString:@" " withString:@""];
@@ -264,7 +264,7 @@ - (void)test_push_token
264264

265265
// Test push token is sent if the token changes.
266266
token = [@"sample2" dataUsingEncoding:NSUTF8StringEncoding];
267-
formattedToken = [token description];
267+
formattedToken = [manager hexadecimalStringFromData:token];
268268
formattedToken = [[[formattedToken stringByReplacingOccurrencesOfString:@"<" withString:@""]
269269
stringByReplacingOccurrencesOfString:@">" withString:@""]
270270
stringByReplacingOccurrencesOfString:@" " withString:@""];
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
//
2+
// LPBaseInterstitialMessageTemplateTest.m
3+
// Leanplum-SDK
4+
//
5+
// Created by Mayank Sanganeria on 2/1/20.
6+
// Copyright © 2020 Leanplum. All rights reserved.
7+
//
8+
// Licensed to the Apache Software Foundation (ASF) under one
9+
// or more contributor license agreements. See the NOTICE file
10+
// distributed with this work for additional information
11+
// regarding copyright ownership. The ASF licenses this file
12+
// to you under the Apache License, Version 2.0 (the "License");
13+
// you may not use this file except in compliance with the License.
14+
// You may obtain a copy of the License at
15+
//
16+
// http://www.apache.org/licenses/LICENSE-2.0
17+
//
18+
// Unless required by applicable law or agreed to in writing,
19+
// software distributed under the License is distributed on an
20+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21+
// KIND, either express or implied. See the License for the
22+
// specific language governing permissions and limitations
23+
// under the License.
24+
25+
26+
#import <XCTest/XCTest.h>
27+
#import <OHHTTPStubs/HTTPStubs.h>
28+
#import <OHHTTPStubs/HTTPStubsPathHelpers.h>
29+
#import "LeanplumHelper.h"
30+
#import "LPBaseInterstitialMessageTemplate.h"
31+
32+
@interface LPBaseInterstitialMessageTemplate (Test)
33+
- (UIImage *)imageFromColor:(UIColor *)color;
34+
- (UIImage *)dismissImage:(UIColor *)color withSize:(int)size;
35+
- (NSString *)urlEncodedStringFromString:(NSString *)urlString;
36+
37+
- (void)setupPopupLayout:(BOOL)isFullscreen isPushAskToAsk:(BOOL)isPushAskToAsk;
38+
- (void)updatePopupLayout;
39+
- (void)showPopup;
40+
41+
@end
42+
43+
44+
@interface LPBaseInterstitialMessageTemplateTest : XCTestCase
45+
46+
@end
47+
48+
@implementation LPBaseInterstitialMessageTemplateTest
49+
50+
+ (void)setUp
51+
{
52+
[super setUp];
53+
// Called only once to setup method swizzling.
54+
[LeanplumHelper setup_method_swizzling];
55+
}
56+
57+
- (void)setUp {
58+
[super setUp];
59+
}
60+
61+
- (void)tearDown {
62+
[super tearDown];
63+
// Clean up after every test.
64+
[LeanplumHelper clean_up];
65+
[HTTPStubs removeAllStubs];
66+
}
67+
68+
- (void)test_image_from_color
69+
{
70+
LPBaseInterstitialMessageTemplate *template = [[LPBaseInterstitialMessageTemplate alloc] init];
71+
UIImage* image = [template imageFromColor:[UIColor blueColor]];
72+
XCTAssertNotNil(image);
73+
}
74+
75+
- (void)test_dismiss_image
76+
{
77+
LPBaseInterstitialMessageTemplate *template = [[LPBaseInterstitialMessageTemplate alloc] init];
78+
UIImage* image = [template dismissImage:[UIColor blueColor] withSize:128];
79+
XCTAssertNotNil(image);
80+
}
81+
82+
- (void)test_popup_setup
83+
{
84+
LPBaseInterstitialMessageTemplate *template = [[LPBaseInterstitialMessageTemplate alloc] init];
85+
// This stub have to be removed when start command is successfully executed.
86+
[HTTPStubs stubRequestsPassingTest:
87+
^BOOL(NSURLRequest * _Nonnull request) {
88+
return [request.URL.host isEqualToString:API_HOST];
89+
} withStubResponse:^HTTPStubsResponse * _Nonnull(NSURLRequest * _Nonnull request) {
90+
NSString *response_file = OHPathForFile(@"simple_start_response.json", self.class);
91+
return [HTTPStubsResponse responseWithFileAtPath:response_file statusCode:200
92+
headers:@{@"Content-Type":@"application/json"}];
93+
}];
94+
95+
XCTAssertTrue([LeanplumHelper start_development_test]);
96+
97+
[template setupPopupLayout:YES isPushAskToAsk:NO];
98+
[template updatePopupLayout];
99+
[template showPopup];
100+
id acceptButton = [template valueForKey:@"_acceptButton"];
101+
XCTAssertNotNil(acceptButton);
102+
}
103+
104+
- (void)test_push_popup_setup
105+
{
106+
107+
LPBaseInterstitialMessageTemplate *template = [[LPBaseInterstitialMessageTemplate alloc] init];
108+
// This stub have to be removed when start command is successfully executed.
109+
[HTTPStubs stubRequestsPassingTest:
110+
^BOOL(NSURLRequest * _Nonnull request) {
111+
return [request.URL.host isEqualToString:API_HOST];
112+
} withStubResponse:^HTTPStubsResponse * _Nonnull(NSURLRequest * _Nonnull request) {
113+
NSString *response_file = OHPathForFile(@"simple_start_response.json", self.class);
114+
return [HTTPStubsResponse responseWithFileAtPath:response_file statusCode:200
115+
headers:@{@"Content-Type":@"application/json"}];
116+
}];
117+
118+
XCTAssertTrue([LeanplumHelper start_development_test]);
119+
120+
[template setupPopupLayout:YES isPushAskToAsk:YES];
121+
[template updatePopupLayout];
122+
[template showPopup];
123+
id acceptButton = [template valueForKey:@"_acceptButton"];
124+
XCTAssertNotNil(acceptButton);
125+
id cancelButton = [template valueForKey:@"_cancelButton"];
126+
XCTAssertNotNil(cancelButton);
127+
}
128+
129+
- (void)test_urlEncodedStringFromString {
130+
LPBaseInterstitialMessageTemplate *template = [[LPBaseInterstitialMessageTemplate alloc] init];
131+
XCTAssertEqualObjects([template urlEncodedStringFromString:@"http://www.leanplum.com"], @"http://www.leanplum.com");
132+
XCTAssertEqualObjects([template urlEncodedStringFromString:@"http://www.leanplum.com?q=simple_english1&test=2"], @"http://www.leanplum.com?q=simple_english1&test=2");
133+
XCTAssertEqualObjects([template urlEncodedStringFromString:@"https://ramsey.tfaforms.net/356302?id={}"], @"https://ramsey.tfaforms.net/356302?id=%7B%7D");
134+
XCTAssertEqualObjects([template urlEncodedStringFromString:@"lomotif://music/月亮"], @"lomotif://music/%E6%9C%88%E4%BA%AE");
135+
}
136+
137+
@end
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
//
2+
// LPBaseInterstitialMessageTemplateTest.m
3+
// Leanplum-SDK
4+
//
5+
// Created by Mayank Sanganeria on 2/1/20.
6+
// Copyright © 2020 Leanplum. All rights reserved.
7+
//
8+
// Licensed to the Apache Software Foundation (ASF) under one
9+
// or more contributor license agreements. See the NOTICE file
10+
// distributed with this work for additional information
11+
// regarding copyright ownership. The ASF licenses this file
12+
// to you under the Apache License, Version 2.0 (the "License");
13+
// you may not use this file except in compliance with the License.
14+
// You may obtain a copy of the License at
15+
//
16+
// http://www.apache.org/licenses/LICENSE-2.0
17+
//
18+
// Unless required by applicable law or agreed to in writing,
19+
// software distributed under the License is distributed on an
20+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21+
// KIND, either express or implied. See the License for the
22+
// specific language governing permissions and limitations
23+
// under the License.
24+
25+
26+
#import <XCTest/XCTest.h>
27+
#import <OHHTTPStubs/HTTPStubs.h>
28+
#import <OHHTTPStubs/HTTPStubsPathHelpers.h>
29+
#import "LeanplumHelper.h"
30+
#import "LPBasePushMessageTemplate.h"
31+
32+
@interface LPBasePushMessageTemplate (Test)
33+
34+
- (void)enableSystemPush;
35+
36+
@end
37+
38+
39+
@interface LPBasePushMessageTemplateTest : XCTestCase
40+
41+
@end
42+
43+
@implementation LPBasePushMessageTemplateTest
44+
45+
- (void)setUp {
46+
[super setUp];
47+
}
48+
49+
- (void)tearDown {
50+
[super tearDown];
51+
}
52+
53+
- (void)test_pushEnableOnce
54+
{
55+
LPBasePushMessageTemplate *template = [[LPBasePushMessageTemplate alloc] init];
56+
[template enableSystemPush];
57+
XCTAssertTrue([[NSUserDefaults standardUserDefaults] boolForKey:@"__Leanplum_asked_to_push"]);
58+
}
59+
60+
@end

Example/Tests/Classes/LPMessageTemplatesClassTest.m

Lines changed: 0 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,6 @@
3535
#import "LPRegisterDevice.h"
3636
#import "LPMessageTemplates.h"
3737

38-
@interface LPMessageTemplatesClass (Test)
39-
+ (UIImage *)imageFromColor:(UIColor *)color;
40-
+ (UIImage *)dismissImage:(UIColor *)color withSize:(int)size;
41-
+ (NSString *)urlEncodedStringFromString:(NSString *)urlString;
42-
43-
- (void)setupPopupLayout:(BOOL)isFullscreen isPushAskToAsk:(BOOL)isPushAskToAsk;
44-
- (void)updatePopupLayout;
45-
- (void)showPopup;
46-
- (void)enableSystemPush;
47-
48-
@end
49-
5038
@interface LPMessageTemplatesClassTest : XCTestCase
5139

5240
@end
@@ -71,79 +59,10 @@ - (void)tearDown {
7159
[HTTPStubs removeAllStubs];
7260
}
7361

74-
- (void)test_image_from_color
75-
{
76-
UIImage* image = [LPMessageTemplatesClass imageFromColor:[UIColor blueColor]];
77-
XCTAssertNotNil(image);
78-
}
79-
80-
- (void)test_dismiss_image
81-
{
82-
UIImage* image = [LPMessageTemplatesClass dismissImage:[UIColor blueColor] withSize:128];
83-
XCTAssertNotNil(image);
84-
}
85-
8662
-(void)test_shared_templates_creation
8763
{
8864
// Previously, this was causing a deadlock.
8965
[LPMessageTemplatesClass sharedTemplates];
9066
}
9167

92-
- (void)test_popup_setup
93-
{
94-
// This stub have to be removed when start command is successfully executed.
95-
[HTTPStubs stubRequestsPassingTest:
96-
^BOOL(NSURLRequest * _Nonnull request) {
97-
return [request.URL.host isEqualToString:API_HOST];
98-
} withStubResponse:^HTTPStubsResponse * _Nonnull(NSURLRequest * _Nonnull request) {
99-
NSString *response_file = OHPathForFile(@"simple_start_response.json", self.class);
100-
return [HTTPStubsResponse responseWithFileAtPath:response_file statusCode:200
101-
headers:@{@"Content-Type":@"application/json"}];
102-
}];
103-
104-
XCTAssertTrue([LeanplumHelper start_development_test]);
105-
106-
[[LPMessageTemplatesClass sharedTemplates] setupPopupLayout:YES isPushAskToAsk:NO];
107-
[[LPMessageTemplatesClass sharedTemplates] updatePopupLayout];
108-
[[LPMessageTemplatesClass sharedTemplates] showPopup];
109-
id acceptButton = [[LPMessageTemplatesClass sharedTemplates] valueForKey:@"_acceptButton"];
110-
XCTAssertNotNil(acceptButton);
111-
}
112-
113-
- (void)test_push_popup_setup
114-
{
115-
// This stub have to be removed when start command is successfully executed.
116-
[HTTPStubs stubRequestsPassingTest:
117-
^BOOL(NSURLRequest * _Nonnull request) {
118-
return [request.URL.host isEqualToString:API_HOST];
119-
} withStubResponse:^HTTPStubsResponse * _Nonnull(NSURLRequest * _Nonnull request) {
120-
NSString *response_file = OHPathForFile(@"simple_start_response.json", self.class);
121-
return [HTTPStubsResponse responseWithFileAtPath:response_file statusCode:200
122-
headers:@{@"Content-Type":@"application/json"}];
123-
}];
124-
125-
XCTAssertTrue([LeanplumHelper start_development_test]);
126-
127-
[[LPMessageTemplatesClass sharedTemplates] setupPopupLayout:YES isPushAskToAsk:YES];
128-
[[LPMessageTemplatesClass sharedTemplates] updatePopupLayout];
129-
[[LPMessageTemplatesClass sharedTemplates] showPopup];
130-
id acceptButton = [[LPMessageTemplatesClass sharedTemplates] valueForKey:@"_acceptButton"];
131-
XCTAssertNotNil(acceptButton);
132-
id cancelButton = [[LPMessageTemplatesClass sharedTemplates] valueForKey:@"_cancelButton"];
133-
XCTAssertNotNil(cancelButton);
134-
}
135-
136-
- (void)test_urlEncodedStringFromString {
137-
XCTAssertEqualObjects([LPMessageTemplatesClass urlEncodedStringFromString:@"http://www.leanplum.com"], @"http://www.leanplum.com");
138-
XCTAssertEqualObjects([LPMessageTemplatesClass urlEncodedStringFromString:@"http://www.leanplum.com?q=simple_english1&test=2"], @"http://www.leanplum.com?q=simple_english1&test=2");
139-
XCTAssertEqualObjects([LPMessageTemplatesClass urlEncodedStringFromString:@"https://ramsey.tfaforms.net/356302?id={}"], @"https://ramsey.tfaforms.net/356302?id=%7B%7D");
140-
XCTAssertEqualObjects([LPMessageTemplatesClass urlEncodedStringFromString:@"lomotif://music/月亮"], @"lomotif://music/%E6%9C%88%E4%BA%AE");
141-
}
142-
143-
- (void)test_pushEnableOnce
144-
{
145-
[[LPMessageTemplatesClass sharedTemplates] enableSystemPush];
146-
XCTAssertTrue([[NSUserDefaults standardUserDefaults] boolForKey:@"__Leanplum_asked_to_push"]);
147-
}
148-
14968
@end

0 commit comments

Comments
 (0)