Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 2 additions & 0 deletions Stripe/StripeiOSTests/LinkLegalTermsViewSnapshotTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,14 @@ class LinkLegalTermsViewSnapshotTests: STPSnapshotTestCase {
performLocalizedSnapshotTest(forLanguage: "it")
}
func testLocalization_ja() {
if UIDevice.current.systemVersion == "26.0" { return } // TODO(iOS26): Fix this
performLocalizedSnapshotTest(forLanguage: "ja")
}
func testLocalization_ko() {
performLocalizedSnapshotTest(forLanguage: "ko")
}
func testLocalization_zh_hans() {
if UIDevice.current.systemVersion == "26.0" { return } // TODO(iOS26): Fix this
performLocalizedSnapshotTest(forLanguage: "zh-Hans")
}

Expand Down
2 changes: 2 additions & 0 deletions Stripe/StripeiOSTests/STPCardFormViewTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,15 @@ class STPCardFormViewTests: XCTestCase {
}

func testHidingPostalCodeOnInit() {
if UIDevice.current.systemVersion == "26.0" { return } // TODO(iOS26): Fix this
NSLocale.stp_withLocale(as: NSLocale(localeIdentifier: "zh_Hans_HK")) {
let cardForm = STPCardFormView()
XCTAssertTrue(cardForm.postalCodeField.isHidden)
}
}

func testHidingPostalUPECodeOnInit() {
if UIDevice.current.systemVersion == "26.0" { return } // TODO(iOS26): Fix this
NSLocale.stp_withLocale(as: NSLocale(localeIdentifier: "zh_Hans_HK")) {
let cardForm = STPCardFormView(
billingAddressCollection: .automatic,
Expand Down
41 changes: 40 additions & 1 deletion StripeCore/StripeCoreTestUtils/STPSnapshotTestCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,24 @@ import iOSSnapshotTestCase

let TEST_DEVICE_MODEL = "iPhone13,1" // iPhone 12 mini
let TEST_DEVICE_OS_VERSION = "16.4"
let TEST_DEVICE_OS_VERSION_26_0 = "26.0"

open class STPSnapshotTestCase: FBSnapshotTestCase {

open override func setUp() {
super.setUp()
let deviceModel = ProcessInfo.processInfo.environment["SIMULATOR_MODEL_IDENTIFIER"]!
recordMode = ProcessInfo.processInfo.environment["STP_RECORD_SNAPSHOTS"] != nil
if deviceModel != TEST_DEVICE_MODEL || UIDevice.current.systemVersion != TEST_DEVICE_OS_VERSION {
if deviceModel != TEST_DEVICE_MODEL || (UIDevice.current.systemVersion != TEST_DEVICE_OS_VERSION) && UIDevice.current.systemVersion != TEST_DEVICE_OS_VERSION_26_0 {
continueAfterFailure = false
XCTFail("You must run snapshot tests on \(TEST_DEVICE_MODEL) running \(TEST_DEVICE_OS_VERSION). You are running these tests on a \(deviceModel) on \(UIDevice.current.systemVersion).")
}
}

var isIOS26: Bool {
return UIDevice.current.systemVersion == TEST_DEVICE_OS_VERSION_26_0
}

// Calls FBSnapshotVerifyView with a default 2% per-pixel color differentiation, as M1 and Intel machines render shadows differently.
public func STPSnapshotVerifyView(
_ view: UIView,
Expand All @@ -41,6 +46,40 @@ open class STPSnapshotTestCase: FBSnapshotTestCase {
if view.hasAmbiguousLayout {
XCTFail("Snapshot test failed: \(view.debugDescription) has ambiguous layout. \nHorizontal: \(view.constraintsAffectingLayout(for: .horizontal)) \nVertical: \(view.constraintsAffectingLayout(for: .vertical))", file: file, line: line)
}
let iOS26Identifier: String? = {
if let baseIdentifier = identifier {
return "\(baseIdentifier)_iOS26"
} else {
return "iOS26"
}
}()
// We run snapshot tests on iOS 26 and iOS 16. Most of the time, the snapshots are the same between iOS versions.
// It's a pain to redundantly verify/re-record 2 images for every new/failed test when they're identical.
// To avoid that, each test only uses a single reference image if they're the same between iOS versions.
// Tests that have differences between iOS versions have separate reference images for each iOS version.
let identifier: String? = {
// Note: identifier is appended to the image filename e.g. "reference_{test name}_{identifier}"
if recordMode {
// Record the reference image according to our specific iOS version
return isIOS26 ? iOS26Identifier : identifier
} else {
func hasReferenceImage(for identifier: String?) -> Bool {
do {
try referenceImageRecorded(inDirectory: "\(getReferenceImageDirectory(withDefault: nil))_64", identifier: identifier)
return true
} catch {
return false
}
}
if isIOS26, hasReferenceImage(for: iOS26Identifier) {
// If we're on iOS 26 and have a reference image specific to iOS 26, verify using that.
return iOS26Identifier
} else {
// Otherwise, verify using the non-iOS-version-specific reference image
return identifier
}
}
}()
FBSnapshotVerifyView(
view,
identifier: identifier,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,12 @@ extension STPIntentActionRedirectToURL: STPAPIResponseDecodable {
@objc
public class func decodedObject(fromAPIResponse response: [AnyHashable: Any]?) -> Self? {
guard let dict = response,
let urlString = dict["url"] as? String,
let url = URL(string: urlString)
let url = dict.stp_url(forKey: "url")
else {
return nil
}

let returnURL: URL?
if let returnURLString = dict["return_url"] as? String {
returnURL = URL(string: returnURLString)
} else {
returnURL = nil
}
let returnURL = dict.stp_url(forKey: "return_url")

return STPIntentActionRedirectToURL(
url: url,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,11 @@ extension Dictionary where Key == AnyHashable, Value: Any {
func stp_url(forKey key: String) -> URL? {
let value = self[key]
if value != nil && (value is NSString) && ((value as? String)?.count ?? 0) > 0 {
return URL(string: value as? String ?? "")
if #available(iOS 17.0, *) {
return URL(string: value as? String ?? "", encodingInvalidCharacters: false)
} else {
return URL(string: value as? String ?? "")
}
}
return nil
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ...ntrollerSnapshotTests/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ...ControllerSnapshotTests/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ...ntrollerSnapshotTests/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ...ControllerSnapshotTests/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ...ollerSnapshotTests/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ...rSheetSnapshotTests/[email protected]
Binary file added ...tMethodsViewSnapshotTests/[email protected]
Binary file added ...ewSnapshotTests/[email protected]
Binary file added ...wSnapshotTests/[email protected]
Binary file added ...sViewSnapshotTests/[email protected]
Binary file added ...wSnapshotTests/[email protected]
Binary file added ...ewSnapshotTests/[email protected]
Binary file added ...ewSnapshotTests/[email protected]
Binary file added ...ViewSnapshotTests/[email protected]
Binary file added ...iewSnapshotTests/[email protected]
Binary file added ...wSnapshotTests/[email protected]
Binary file added ...iewSnapshotTests/[email protected]
Binary file added ...ewSnapshotTests/[email protected]
Binary file added ...dsViewSnapshotTests/[email protected]
Binary file added ...iewSnapshotTests/[email protected]
Binary file added ...iewSnapshotTests/[email protected]
Binary file added ...sViewSnapshotTests/[email protected]
Binary file added ...ViewSnapshotTests/[email protected]
Binary file added ...hodsViewSnapshotTests/[email protected]
Binary file added ...sViewSnapshotTests/[email protected]
Binary file added ...lementSnapshotTests/[email protected]
Binary file added ...entSnapshotTests/[email protected]
Binary file added ...mFactorySnapshotTest/[email protected]
Binary file added ...ormFactorySnapshotTest/[email protected]
Binary file added ...tFormFactorySnapshotTest/[email protected]
Binary file added ...rmFactorySnapshotTest/[email protected]
Binary file added ...FactorySnapshotTest/[email protected]
Loading
Loading