Skip to content
This repository was archived by the owner on Sep 15, 2025. It is now read-only.

Commit dac09cd

Browse files
committed
Move remaining tests to CoreAPITests/
1 parent 576a820 commit dac09cd

26 files changed

+242
-199
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ let package = Package(
4242
],
4343
path: "Tests/CoreAPITests",
4444
resources: [
45-
// .process("Stubs") // Relative to path
45+
.process("Stubs") // Relative to path
4646
]
4747
),
4848
]
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import Foundation
2+
3+
/// Error domain of `NSError` instances that are converted from `WordPressComRestApiEndpointError`
4+
/// and `WordPressAPIError<WordPressComRestApiEndpointError>` instances.
5+
///
6+
/// See `extension WordPressComRestApiEndpointError: CustomNSError` for context.
7+
let WordPressComRestApiErrorDomain = "WordPressKit.WordPressComRestApiError"
8+
9+
// WordPressComRestApiErrorDomain is accessible only in Swift and, since it's a global, cannot be made @objc.
10+
// As a workaround, here is a builder to init NSError with that domain and a method to check the domain.
11+
@objc
12+
public extension NSError {
13+
14+
@objc
15+
static func wordPressComRestApiError(
16+
code: Int,
17+
userInfo: [String: Any]?
18+
) -> NSError {
19+
NSError(
20+
domain: WordPressComRestApiErrorDomain,
21+
code: code,
22+
userInfo: userInfo
23+
)
24+
}
25+
26+
@objc
27+
func hasWordPressComRestApiErrorDomain() -> Bool {
28+
domain == WordPressComRestApiErrorDomain
29+
}
30+
}

Sources/WordPressKit/Services/MediaServiceRemoteREST.m

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,8 @@ - (NSError *)processMediaUploadErrors:(NSArray *)errorList {
244244
errorMessage = errorInfo[@"message"];
245245
}
246246
NSDictionary *errorDictionary = @{NSLocalizedDescriptionKey: errorMessage};
247-
error = [NSError errorWithDomain:WordPressComRestApiErrorDomain code:WordPressComRestApiErrorCodeUploadFailed userInfo:errorDictionary];
247+
error = [NSError wordPressComRestApiErrorWithCode:WordPressComRestApiErrorCodeUploadFailed
248+
userInfo:errorDictionary];
248249
}
249250
return error;
250251
}
@@ -296,9 +297,8 @@ - (void)deleteMedia:(RemoteMedia *)media
296297
}
297298
} else {
298299
if (failure) {
299-
NSError *error = [NSError errorWithDomain:WordPressComRestApiErrorDomain
300-
code:WordPressComRestApiErrorCodeUnknown
301-
userInfo:nil];
300+
NSError *error = [NSError wordPressComRestApiErrorWithCode:WordPressComRestApiErrorCodeUnknown
301+
userInfo:nil];
302302
failure(error);
303303
}
304304
}
@@ -369,9 +369,8 @@ -(void)getVideoPressToken:(NSString *)videoPressID
369369
}
370370
} else {
371371
if (failure) {
372-
NSError *error = [NSError errorWithDomain:WordPressComRestApiErrorDomain
373-
code:WordPressComRestApiErrorCodeUnknown
374-
userInfo:nil];
372+
NSError *error = [NSError wordPressComRestApiErrorWithCode:WordPressComRestApiErrorCodeUnknown
373+
userInfo:nil];
375374
failure(error);
376375
}
377376
}

Sources/WordPressKit/Services/WordPressComServiceRemote.m

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,9 @@ - (void)createWPComBlogWithUrl:(NSString *)blogUrl
179179
NSMutableDictionary *userInfo = [[NSMutableDictionary alloc] init];
180180
userInfo[WordPressComRestApi.ErrorKeyErrorMessage] = localizedErrorMessage;
181181
userInfo[NSLocalizedDescriptionKey] = localizedErrorMessage;
182-
NSError *errorWithLocalizedMessage = [[NSError alloc] initWithDomain:WordPressComRestApiErrorDomain
183-
code:WordPressComRestApiErrorCodeUnknown
184-
userInfo:userInfo];
185-
182+
NSError *errorWithLocalizedMessage = [NSError wordPressComRestApiErrorWithCode:WordPressComRestApiErrorCodeUnknown
183+
userInfo:userInfo];
184+
186185
failure(errorWithLocalizedMessage);
187186
} else {
188187
success(responseObject);
@@ -229,7 +228,7 @@ - (void)createWPComBlogWithUrl:(NSString *)blogUrl
229228

230229
- (NSError *)errorWithLocalizedMessage:(NSError *)error {
231230
NSError *errorWithLocalizedMessage = error;
232-
if ([error.domain isEqualToString:WordPressComRestApiErrorDomain] &&
231+
if ([error hasWordPressComRestApiErrorDomain] &&
233232
[error.userInfo objectForKey:WordPressComRestApi.ErrorKeyErrorCode] != nil) {
234233

235234
NSString *localizedErrorMessage = [self errorMessageForError:error];

Sources/WordPressKit/Utility/Constants.h

Lines changed: 0 additions & 7 deletions
This file was deleted.

Sources/WordPressKit/Utility/Constants.m

Lines changed: 0 additions & 7 deletions
This file was deleted.

Sources/WordPressKit/Utility/HTTPProtocolHelpers.swift

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,5 @@
11
import Foundation
22

3-
extension String.Encoding {
4-
/// See: https://www.iana.org/assignments/character-sets/character-sets.xhtml
5-
init?(ianaCharsetName: String) {
6-
let encoding: CFStringEncoding = CFStringConvertIANACharSetNameToEncoding(ianaCharsetName as CFString)
7-
guard encoding != kCFStringEncodingInvalidId,
8-
let builtInEncoding = CFStringBuiltInEncodings(rawValue: encoding)
9-
else {
10-
return nil
11-
}
12-
13-
switch builtInEncoding {
14-
case .macRoman:
15-
self = .macOSRoman
16-
case .windowsLatin1:
17-
self = .windowsCP1252
18-
case .isoLatin1:
19-
self = .isoLatin1
20-
case .nextStepLatin:
21-
self = .nextstep
22-
case .ASCII:
23-
self = .ascii
24-
case .unicode:
25-
self = .unicode
26-
case .UTF8:
27-
self = .utf8
28-
case .nonLossyASCII:
29-
self = .nonLossyASCII
30-
case .UTF16BE:
31-
self = .utf16BigEndian
32-
case .UTF16LE:
33-
self = .utf16LittleEndian
34-
case .UTF32:
35-
self = .utf32
36-
case .UTF32BE:
37-
self = .utf32BigEndian
38-
case .UTF32LE:
39-
self = .utf32LittleEndian
40-
@unknown default:
41-
return nil
42-
}
43-
}
44-
}
45-
463
extension HTTPURLResponse {
474

485
/// Return parameter value in a header field.

Sources/WordPressKit/WordPressKit.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,3 @@ FOUNDATION_EXPORT const unsigned char WordPressKitVersionString[];
5353
#import <WordPressKit/NSString+MD5.h>
5454

5555
#import <WordPressKit/WPKitLogging.h>
56-
#import <WordPressKit/Constants.h>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import XCTest
2+
#if SWIFT_PACKAGE
3+
@testable import CoreAPI
4+
#else
25
@testable import WordPressKit
6+
#endif
37

48
final class AppTransportSecuritySettingsTests: XCTestCase {
59

Tests/WordPressKitTests/Fakes/FakeInfoDictionaryObjectProvider.swift renamed to Tests/CoreAPITests/FakeInfoDictionaryObjectProvider.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
import Foundation
1+
#if SWIFT_PACKAGE
2+
@testable import CoreAPI
3+
#else
24
@testable import WordPressKit
5+
#endif
36

47
class FakeInfoDictionaryObjectProvider: InfoDictionaryObjectProvider {
58
private let appTransportSecurity: [String: Any]?

0 commit comments

Comments
 (0)