From 6d9b2d24cacda10ab107814e1defc2f4391ae2dd Mon Sep 17 00:00:00 2001 From: Deepak Mantena Date: Wed, 24 Feb 2021 12:44:04 -0800 Subject: [PATCH] Add `Nocilla` to unit tests target. --- Wikipedia.xcodeproj/project.pbxproj | 258 ++++++++++++++++++ .../Code/LSStubResponseDSL+WithJSON.h | 2 +- .../Code/WMFNotificationTests.m | 2 +- .../Code/WikipediaUnitTests-Bridging-Header.h | 2 +- .../Nocilla/Categories/NSData+Nocilla.h | 6 + .../Nocilla/Categories/NSData+Nocilla.m | 9 + .../Nocilla/Categories/NSString+Nocilla.h | 8 + .../Nocilla/Categories/NSString+Nocilla.m | 18 ++ .../DSL/LSHTTPRequestDSLRepresentation.h | 6 + .../DSL/LSHTTPRequestDSLRepresentation.m | 39 +++ .../Nocilla/DSL/LSStubRequestDSL.h | 39 +++ .../Nocilla/DSL/LSStubRequestDSL.m | 72 +++++ .../Nocilla/DSL/LSStubResponseDSL.h | 19 ++ .../Nocilla/DSL/LSStubResponseDSL.m | 40 +++ .../Nocilla/Diff/LSHTTPRequestDiff.h | 8 + .../Nocilla/Diff/LSHTTPRequestDiff.m | 114 ++++++++ .../Hooks/ASIHTTPRequest/ASIHTTPRequestStub.h | 8 + .../Hooks/ASIHTTPRequest/ASIHTTPRequestStub.m | 52 ++++ .../ASIHTTPRequest/LSASIHTTPRequestAdapter.h | 10 + .../ASIHTTPRequest/LSASIHTTPRequestAdapter.m | 42 +++ .../ASIHTTPRequest/LSASIHTTPRequestHook.h | 5 + .../ASIHTTPRequest/LSASIHTTPRequestHook.m | 48 ++++ .../Nocilla/Hooks/LSHTTPClientHook.h | 6 + .../Nocilla/Hooks/LSHTTPClientHook.m | 13 + .../NSURLRequest/LSHTTPStubURLProtocol.h | 5 + .../NSURLRequest/LSHTTPStubURLProtocol.m | 67 +++++ .../Nocilla/Hooks/NSURLRequest/LSNSURLHook.h | 5 + .../Nocilla/Hooks/NSURLRequest/LSNSURLHook.m | 14 + .../Hooks/NSURLRequest/NSURLRequest+DSL.h | 5 + .../Hooks/NSURLRequest/NSURLRequest+DSL.m | 9 + .../NSURLRequest/NSURLRequest+LSHTTPRequest.h | 6 + .../NSURLRequest/NSURLRequest+LSHTTPRequest.m | 47 ++++ .../Hooks/NSURLSession/LSNSURLSessionHook.h | 15 + .../Hooks/NSURLSession/LSNSURLSessionHook.m | 40 +++ .../Third Party/Nocilla/LSNocilla.h | 25 ++ .../Third Party/Nocilla/LSNocilla.m | 118 ++++++++ .../Nocilla/Matchers/LSDataMatcher.h | 16 ++ .../Nocilla/Matchers/LSDataMatcher.m | 51 ++++ .../Nocilla/Matchers/LSMatcheable.h | 9 + .../Third Party/Nocilla/Matchers/LSMatcher.h | 9 + .../Third Party/Nocilla/Matchers/LSMatcher.m | 24 ++ .../Nocilla/Matchers/LSRegexMatcher.h | 7 + .../Nocilla/Matchers/LSRegexMatcher.m | 40 +++ .../Nocilla/Matchers/LSStringMatcher.h | 8 + .../Nocilla/Matchers/LSStringMatcher.m | 42 +++ .../Nocilla/Matchers/NSData+Matcheable.h | 14 + .../Nocilla/Matchers/NSData+Matcheable.m | 18 ++ .../Matchers/NSRegularExpression+Matcheable.h | 6 + .../Matchers/NSRegularExpression+Matcheable.m | 10 + .../Nocilla/Matchers/NSString+Matcheable.h | 6 + .../Nocilla/Matchers/NSString+Matcheable.m | 10 + .../Third Party/Nocilla/Model/LSHTTPBody.h | 5 + .../Third Party/Nocilla/Model/LSHTTPRequest.h | 10 + .../Nocilla/Model/LSHTTPResponse.h | 7 + .../Third Party/Nocilla/Nocilla-Prefix.pch | 7 + .../Third Party/Nocilla/Nocilla.h | 27 ++ .../Third Party/Nocilla/Stubs/LSStubRequest.h | 24 ++ .../Third Party/Nocilla/Stubs/LSStubRequest.m | 130 +++++++++ .../Nocilla/Stubs/LSStubResponse.h | 18 ++ .../Nocilla/Stubs/LSStubResponse.m | 81 ++++++ 60 files changed, 1758 insertions(+), 3 deletions(-) create mode 100644 WikipediaUnitTests/Third Party/Nocilla/Categories/NSData+Nocilla.h create mode 100644 WikipediaUnitTests/Third Party/Nocilla/Categories/NSData+Nocilla.m create mode 100644 WikipediaUnitTests/Third Party/Nocilla/Categories/NSString+Nocilla.h create mode 100644 WikipediaUnitTests/Third Party/Nocilla/Categories/NSString+Nocilla.m create mode 100644 WikipediaUnitTests/Third Party/Nocilla/DSL/LSHTTPRequestDSLRepresentation.h create mode 100644 WikipediaUnitTests/Third Party/Nocilla/DSL/LSHTTPRequestDSLRepresentation.m create mode 100644 WikipediaUnitTests/Third Party/Nocilla/DSL/LSStubRequestDSL.h create mode 100644 WikipediaUnitTests/Third Party/Nocilla/DSL/LSStubRequestDSL.m create mode 100644 WikipediaUnitTests/Third Party/Nocilla/DSL/LSStubResponseDSL.h create mode 100644 WikipediaUnitTests/Third Party/Nocilla/DSL/LSStubResponseDSL.m create mode 100644 WikipediaUnitTests/Third Party/Nocilla/Diff/LSHTTPRequestDiff.h create mode 100644 WikipediaUnitTests/Third Party/Nocilla/Diff/LSHTTPRequestDiff.m create mode 100644 WikipediaUnitTests/Third Party/Nocilla/Hooks/ASIHTTPRequest/ASIHTTPRequestStub.h create mode 100644 WikipediaUnitTests/Third Party/Nocilla/Hooks/ASIHTTPRequest/ASIHTTPRequestStub.m create mode 100644 WikipediaUnitTests/Third Party/Nocilla/Hooks/ASIHTTPRequest/LSASIHTTPRequestAdapter.h create mode 100644 WikipediaUnitTests/Third Party/Nocilla/Hooks/ASIHTTPRequest/LSASIHTTPRequestAdapter.m create mode 100644 WikipediaUnitTests/Third Party/Nocilla/Hooks/ASIHTTPRequest/LSASIHTTPRequestHook.h create mode 100644 WikipediaUnitTests/Third Party/Nocilla/Hooks/ASIHTTPRequest/LSASIHTTPRequestHook.m create mode 100644 WikipediaUnitTests/Third Party/Nocilla/Hooks/LSHTTPClientHook.h create mode 100644 WikipediaUnitTests/Third Party/Nocilla/Hooks/LSHTTPClientHook.m create mode 100644 WikipediaUnitTests/Third Party/Nocilla/Hooks/NSURLRequest/LSHTTPStubURLProtocol.h create mode 100644 WikipediaUnitTests/Third Party/Nocilla/Hooks/NSURLRequest/LSHTTPStubURLProtocol.m create mode 100644 WikipediaUnitTests/Third Party/Nocilla/Hooks/NSURLRequest/LSNSURLHook.h create mode 100644 WikipediaUnitTests/Third Party/Nocilla/Hooks/NSURLRequest/LSNSURLHook.m create mode 100644 WikipediaUnitTests/Third Party/Nocilla/Hooks/NSURLRequest/NSURLRequest+DSL.h create mode 100644 WikipediaUnitTests/Third Party/Nocilla/Hooks/NSURLRequest/NSURLRequest+DSL.m create mode 100644 WikipediaUnitTests/Third Party/Nocilla/Hooks/NSURLRequest/NSURLRequest+LSHTTPRequest.h create mode 100644 WikipediaUnitTests/Third Party/Nocilla/Hooks/NSURLRequest/NSURLRequest+LSHTTPRequest.m create mode 100644 WikipediaUnitTests/Third Party/Nocilla/Hooks/NSURLSession/LSNSURLSessionHook.h create mode 100644 WikipediaUnitTests/Third Party/Nocilla/Hooks/NSURLSession/LSNSURLSessionHook.m create mode 100644 WikipediaUnitTests/Third Party/Nocilla/LSNocilla.h create mode 100644 WikipediaUnitTests/Third Party/Nocilla/LSNocilla.m create mode 100644 WikipediaUnitTests/Third Party/Nocilla/Matchers/LSDataMatcher.h create mode 100644 WikipediaUnitTests/Third Party/Nocilla/Matchers/LSDataMatcher.m create mode 100644 WikipediaUnitTests/Third Party/Nocilla/Matchers/LSMatcheable.h create mode 100644 WikipediaUnitTests/Third Party/Nocilla/Matchers/LSMatcher.h create mode 100644 WikipediaUnitTests/Third Party/Nocilla/Matchers/LSMatcher.m create mode 100644 WikipediaUnitTests/Third Party/Nocilla/Matchers/LSRegexMatcher.h create mode 100644 WikipediaUnitTests/Third Party/Nocilla/Matchers/LSRegexMatcher.m create mode 100644 WikipediaUnitTests/Third Party/Nocilla/Matchers/LSStringMatcher.h create mode 100644 WikipediaUnitTests/Third Party/Nocilla/Matchers/LSStringMatcher.m create mode 100644 WikipediaUnitTests/Third Party/Nocilla/Matchers/NSData+Matcheable.h create mode 100644 WikipediaUnitTests/Third Party/Nocilla/Matchers/NSData+Matcheable.m create mode 100644 WikipediaUnitTests/Third Party/Nocilla/Matchers/NSRegularExpression+Matcheable.h create mode 100644 WikipediaUnitTests/Third Party/Nocilla/Matchers/NSRegularExpression+Matcheable.m create mode 100644 WikipediaUnitTests/Third Party/Nocilla/Matchers/NSString+Matcheable.h create mode 100644 WikipediaUnitTests/Third Party/Nocilla/Matchers/NSString+Matcheable.m create mode 100644 WikipediaUnitTests/Third Party/Nocilla/Model/LSHTTPBody.h create mode 100644 WikipediaUnitTests/Third Party/Nocilla/Model/LSHTTPRequest.h create mode 100644 WikipediaUnitTests/Third Party/Nocilla/Model/LSHTTPResponse.h create mode 100644 WikipediaUnitTests/Third Party/Nocilla/Nocilla-Prefix.pch create mode 100644 WikipediaUnitTests/Third Party/Nocilla/Nocilla.h create mode 100644 WikipediaUnitTests/Third Party/Nocilla/Stubs/LSStubRequest.h create mode 100644 WikipediaUnitTests/Third Party/Nocilla/Stubs/LSStubRequest.m create mode 100644 WikipediaUnitTests/Third Party/Nocilla/Stubs/LSStubResponse.h create mode 100644 WikipediaUnitTests/Third Party/Nocilla/Stubs/LSStubResponse.m diff --git a/Wikipedia.xcodeproj/project.pbxproj b/Wikipedia.xcodeproj/project.pbxproj index 5d4fe6e9c72..bd6ae74e535 100644 --- a/Wikipedia.xcodeproj/project.pbxproj +++ b/Wikipedia.xcodeproj/project.pbxproj @@ -107,6 +107,31 @@ 0042813E25E6E841004945B3 /* NYTPhotosViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 0042811325E6E841004945B3 /* NYTPhotosViewController.m */; }; 0042813F25E6E841004945B3 /* NYTPhotosViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 0042811325E6E841004945B3 /* NYTPhotosViewController.m */; }; 0042814025E6E841004945B3 /* NYTPhotosViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 0042811325E6E841004945B3 /* NYTPhotosViewController.m */; }; + 004281B225E6EFC4004945B3 /* LSStubRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = 0042817125E6EFC4004945B3 /* LSStubRequest.m */; }; + 004281B325E6EFC4004945B3 /* LSStubResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = 0042817225E6EFC4004945B3 /* LSStubResponse.m */; }; + 004281B425E6EFC4004945B3 /* LSNocilla.m in Sources */ = {isa = PBXBuildFile; fileRef = 0042817525E6EFC4004945B3 /* LSNocilla.m */; }; + 004281B525E6EFC4004945B3 /* LSHTTPRequestDiff.m in Sources */ = {isa = PBXBuildFile; fileRef = 0042817825E6EFC4004945B3 /* LSHTTPRequestDiff.m */; }; + 004281B625E6EFC4004945B3 /* LSHTTPClientHook.m in Sources */ = {isa = PBXBuildFile; fileRef = 0042817C25E6EFC4004945B3 /* LSHTTPClientHook.m */; }; + 004281B725E6EFC4004945B3 /* NSURLRequest+LSHTTPRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = 0042817F25E6EFC4004945B3 /* NSURLRequest+LSHTTPRequest.m */; }; + 004281B825E6EFC4004945B3 /* LSNSURLHook.m in Sources */ = {isa = PBXBuildFile; fileRef = 0042818425E6EFC4004945B3 /* LSNSURLHook.m */; }; + 004281B925E6EFC4004945B3 /* NSURLRequest+DSL.m in Sources */ = {isa = PBXBuildFile; fileRef = 0042818525E6EFC4004945B3 /* NSURLRequest+DSL.m */; }; + 004281BA25E6EFC4004945B3 /* LSHTTPStubURLProtocol.m in Sources */ = {isa = PBXBuildFile; fileRef = 0042818625E6EFC4004945B3 /* LSHTTPStubURLProtocol.m */; }; + 004281BB25E6EFC4004945B3 /* ASIHTTPRequestStub.m in Sources */ = {isa = PBXBuildFile; fileRef = 0042818925E6EFC4004945B3 /* ASIHTTPRequestStub.m */; }; + 004281BC25E6EFC4004945B3 /* LSASIHTTPRequestHook.m in Sources */ = {isa = PBXBuildFile; fileRef = 0042818B25E6EFC4004945B3 /* LSASIHTTPRequestHook.m */; }; + 004281BD25E6EFC4004945B3 /* LSASIHTTPRequestAdapter.m in Sources */ = {isa = PBXBuildFile; fileRef = 0042818C25E6EFC4004945B3 /* LSASIHTTPRequestAdapter.m */; }; + 004281BE25E6EFC4004945B3 /* LSNSURLSessionHook.m in Sources */ = {isa = PBXBuildFile; fileRef = 0042819025E6EFC4004945B3 /* LSNSURLSessionHook.m */; }; + 004281BF25E6EFC4004945B3 /* NSRegularExpression+Matcheable.m in Sources */ = {isa = PBXBuildFile; fileRef = 0042819A25E6EFC4004945B3 /* NSRegularExpression+Matcheable.m */; }; + 004281C025E6EFC4004945B3 /* NSString+Matcheable.m in Sources */ = {isa = PBXBuildFile; fileRef = 0042819C25E6EFC4004945B3 /* NSString+Matcheable.m */; }; + 004281C125E6EFC4004945B3 /* NSData+Matcheable.m in Sources */ = {isa = PBXBuildFile; fileRef = 0042819D25E6EFC4004945B3 /* NSData+Matcheable.m */; }; + 004281C225E6EFC4004945B3 /* LSDataMatcher.m in Sources */ = {isa = PBXBuildFile; fileRef = 0042819E25E6EFC4004945B3 /* LSDataMatcher.m */; }; + 004281C325E6EFC4004945B3 /* LSMatcher.m in Sources */ = {isa = PBXBuildFile; fileRef = 0042819F25E6EFC4004945B3 /* LSMatcher.m */; }; + 004281C425E6EFC4004945B3 /* LSRegexMatcher.m in Sources */ = {isa = PBXBuildFile; fileRef = 004281A025E6EFC4004945B3 /* LSRegexMatcher.m */; }; + 004281C525E6EFC4004945B3 /* LSStringMatcher.m in Sources */ = {isa = PBXBuildFile; fileRef = 004281A225E6EFC4004945B3 /* LSStringMatcher.m */; }; + 004281C625E6EFC4004945B3 /* NSString+Nocilla.m in Sources */ = {isa = PBXBuildFile; fileRef = 004281A825E6EFC4004945B3 /* NSString+Nocilla.m */; }; + 004281C725E6EFC4004945B3 /* NSData+Nocilla.m in Sources */ = {isa = PBXBuildFile; fileRef = 004281A925E6EFC4004945B3 /* NSData+Nocilla.m */; }; + 004281C825E6EFC4004945B3 /* LSHTTPRequestDSLRepresentation.m in Sources */ = {isa = PBXBuildFile; fileRef = 004281AC25E6EFC4004945B3 /* LSHTTPRequestDSLRepresentation.m */; }; + 004281C925E6EFC4004945B3 /* LSStubResponseDSL.m in Sources */ = {isa = PBXBuildFile; fileRef = 004281AE25E6EFC4004945B3 /* LSStubResponseDSL.m */; }; + 004281CA25E6EFC4004945B3 /* LSStubRequestDSL.m in Sources */ = {isa = PBXBuildFile; fileRef = 004281AF25E6EFC4004945B3 /* LSStubRequestDSL.m */; }; 0062597324DE0A2500C95037 /* WidgetController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0062597224DE0A2500C95037 /* WidgetController.swift */; }; 006D273524D8BAFB00947551 /* View+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 006D273424D8BAFB00947551 /* View+Extensions.swift */; }; 006D273724D8D8D100947551 /* Date+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 006D273624D8D8D100947551 /* Date+Extensions.swift */; }; @@ -3419,6 +3444,62 @@ 0042811225E6E841004945B3 /* NYTPhoto.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NYTPhoto.h; sourceTree = ""; }; 0042811325E6E841004945B3 /* NYTPhotosViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NYTPhotosViewController.m; sourceTree = ""; }; 0042811425E6E841004945B3 /* NYTPhotosDataSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NYTPhotosDataSource.h; sourceTree = ""; }; + 0042817125E6EFC4004945B3 /* LSStubRequest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LSStubRequest.m; sourceTree = ""; }; + 0042817225E6EFC4004945B3 /* LSStubResponse.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LSStubResponse.m; sourceTree = ""; }; + 0042817325E6EFC4004945B3 /* LSStubResponse.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LSStubResponse.h; sourceTree = ""; }; + 0042817425E6EFC4004945B3 /* LSStubRequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LSStubRequest.h; sourceTree = ""; }; + 0042817525E6EFC4004945B3 /* LSNocilla.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LSNocilla.m; sourceTree = ""; }; + 0042817625E6EFC4004945B3 /* Nocilla-Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "Nocilla-Prefix.pch"; sourceTree = ""; }; + 0042817825E6EFC4004945B3 /* LSHTTPRequestDiff.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LSHTTPRequestDiff.m; sourceTree = ""; }; + 0042817925E6EFC4004945B3 /* LSHTTPRequestDiff.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LSHTTPRequestDiff.h; sourceTree = ""; }; + 0042817A25E6EFC4004945B3 /* Nocilla.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Nocilla.h; sourceTree = ""; }; + 0042817C25E6EFC4004945B3 /* LSHTTPClientHook.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LSHTTPClientHook.m; sourceTree = ""; }; + 0042817D25E6EFC4004945B3 /* LSHTTPClientHook.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LSHTTPClientHook.h; sourceTree = ""; }; + 0042817F25E6EFC4004945B3 /* NSURLRequest+LSHTTPRequest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSURLRequest+LSHTTPRequest.m"; sourceTree = ""; }; + 0042818025E6EFC4004945B3 /* NSURLRequest+DSL.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSURLRequest+DSL.h"; sourceTree = ""; }; + 0042818125E6EFC4004945B3 /* LSNSURLHook.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LSNSURLHook.h; sourceTree = ""; }; + 0042818225E6EFC4004945B3 /* LSHTTPStubURLProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LSHTTPStubURLProtocol.h; sourceTree = ""; }; + 0042818325E6EFC4004945B3 /* NSURLRequest+LSHTTPRequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSURLRequest+LSHTTPRequest.h"; sourceTree = ""; }; + 0042818425E6EFC4004945B3 /* LSNSURLHook.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LSNSURLHook.m; sourceTree = ""; }; + 0042818525E6EFC4004945B3 /* NSURLRequest+DSL.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSURLRequest+DSL.m"; sourceTree = ""; }; + 0042818625E6EFC4004945B3 /* LSHTTPStubURLProtocol.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LSHTTPStubURLProtocol.m; sourceTree = ""; }; + 0042818825E6EFC4004945B3 /* LSASIHTTPRequestHook.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LSASIHTTPRequestHook.h; sourceTree = ""; }; + 0042818925E6EFC4004945B3 /* ASIHTTPRequestStub.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ASIHTTPRequestStub.m; sourceTree = ""; }; + 0042818A25E6EFC4004945B3 /* LSASIHTTPRequestAdapter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LSASIHTTPRequestAdapter.h; sourceTree = ""; }; + 0042818B25E6EFC4004945B3 /* LSASIHTTPRequestHook.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LSASIHTTPRequestHook.m; sourceTree = ""; }; + 0042818C25E6EFC4004945B3 /* LSASIHTTPRequestAdapter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LSASIHTTPRequestAdapter.m; sourceTree = ""; }; + 0042818D25E6EFC4004945B3 /* ASIHTTPRequestStub.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASIHTTPRequestStub.h; sourceTree = ""; }; + 0042818F25E6EFC4004945B3 /* LSNSURLSessionHook.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LSNSURLSessionHook.h; sourceTree = ""; }; + 0042819025E6EFC4004945B3 /* LSNSURLSessionHook.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LSNSURLSessionHook.m; sourceTree = ""; }; + 0042819225E6EFC4004945B3 /* LSHTTPBody.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LSHTTPBody.h; sourceTree = ""; }; + 0042819325E6EFC4004945B3 /* LSHTTPRequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LSHTTPRequest.h; sourceTree = ""; }; + 0042819425E6EFC4004945B3 /* LSHTTPResponse.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LSHTTPResponse.h; sourceTree = ""; }; + 0042819525E6EFC4004945B3 /* LSNocilla.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LSNocilla.h; sourceTree = ""; }; + 0042819725E6EFC4004945B3 /* LSMatcheable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LSMatcheable.h; sourceTree = ""; }; + 0042819825E6EFC4004945B3 /* LSMatcher.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LSMatcher.h; sourceTree = ""; }; + 0042819925E6EFC4004945B3 /* LSStringMatcher.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LSStringMatcher.h; sourceTree = ""; }; + 0042819A25E6EFC4004945B3 /* NSRegularExpression+Matcheable.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSRegularExpression+Matcheable.m"; sourceTree = ""; }; + 0042819B25E6EFC4004945B3 /* LSRegexMatcher.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LSRegexMatcher.h; sourceTree = ""; }; + 0042819C25E6EFC4004945B3 /* NSString+Matcheable.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+Matcheable.m"; sourceTree = ""; }; + 0042819D25E6EFC4004945B3 /* NSData+Matcheable.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSData+Matcheable.m"; sourceTree = ""; }; + 0042819E25E6EFC4004945B3 /* LSDataMatcher.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LSDataMatcher.m; sourceTree = ""; }; + 0042819F25E6EFC4004945B3 /* LSMatcher.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LSMatcher.m; sourceTree = ""; }; + 004281A025E6EFC4004945B3 /* LSRegexMatcher.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LSRegexMatcher.m; sourceTree = ""; }; + 004281A125E6EFC4004945B3 /* NSRegularExpression+Matcheable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSRegularExpression+Matcheable.h"; sourceTree = ""; }; + 004281A225E6EFC4004945B3 /* LSStringMatcher.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LSStringMatcher.m; sourceTree = ""; }; + 004281A325E6EFC4004945B3 /* NSString+Matcheable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+Matcheable.h"; sourceTree = ""; }; + 004281A425E6EFC4004945B3 /* LSDataMatcher.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LSDataMatcher.h; sourceTree = ""; }; + 004281A525E6EFC4004945B3 /* NSData+Matcheable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSData+Matcheable.h"; sourceTree = ""; }; + 004281A725E6EFC4004945B3 /* NSData+Nocilla.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSData+Nocilla.h"; sourceTree = ""; }; + 004281A825E6EFC4004945B3 /* NSString+Nocilla.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+Nocilla.m"; sourceTree = ""; }; + 004281A925E6EFC4004945B3 /* NSData+Nocilla.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSData+Nocilla.m"; sourceTree = ""; }; + 004281AA25E6EFC4004945B3 /* NSString+Nocilla.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+Nocilla.h"; sourceTree = ""; }; + 004281AC25E6EFC4004945B3 /* LSHTTPRequestDSLRepresentation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LSHTTPRequestDSLRepresentation.m; sourceTree = ""; }; + 004281AD25E6EFC4004945B3 /* LSStubRequestDSL.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LSStubRequestDSL.h; sourceTree = ""; }; + 004281AE25E6EFC4004945B3 /* LSStubResponseDSL.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LSStubResponseDSL.m; sourceTree = ""; }; + 004281AF25E6EFC4004945B3 /* LSStubRequestDSL.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LSStubRequestDSL.m; sourceTree = ""; }; + 004281B025E6EFC4004945B3 /* LSHTTPRequestDSLRepresentation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LSHTTPRequestDSLRepresentation.h; sourceTree = ""; }; + 004281B125E6EFC4004945B3 /* LSStubResponseDSL.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LSStubResponseDSL.h; sourceTree = ""; }; 0062597224DE0A2500C95037 /* WidgetController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WidgetController.swift; sourceTree = ""; usesTabs = 0; }; 006D273424D8BAFB00947551 /* View+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "View+Extensions.swift"; sourceTree = ""; usesTabs = 0; }; 006D273624D8D8D100947551 /* Date+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Date+Extensions.swift"; sourceTree = ""; usesTabs = 0; }; @@ -5308,6 +5389,157 @@ path = Protocols; sourceTree = ""; }; + 0042816E25E6EF58004945B3 /* Third Party */ = { + isa = PBXGroup; + children = ( + 0042816F25E6EFC4004945B3 /* Nocilla */, + ); + path = "Third Party"; + sourceTree = ""; + }; + 0042816F25E6EFC4004945B3 /* Nocilla */ = { + isa = PBXGroup; + children = ( + 0042817025E6EFC4004945B3 /* Stubs */, + 0042817525E6EFC4004945B3 /* LSNocilla.m */, + 0042817625E6EFC4004945B3 /* Nocilla-Prefix.pch */, + 0042817725E6EFC4004945B3 /* Diff */, + 0042817A25E6EFC4004945B3 /* Nocilla.h */, + 0042817B25E6EFC4004945B3 /* Hooks */, + 0042819125E6EFC4004945B3 /* Model */, + 0042819525E6EFC4004945B3 /* LSNocilla.h */, + 0042819625E6EFC4004945B3 /* Matchers */, + 004281A625E6EFC4004945B3 /* Categories */, + 004281AB25E6EFC4004945B3 /* DSL */, + ); + path = Nocilla; + sourceTree = ""; + }; + 0042817025E6EFC4004945B3 /* Stubs */ = { + isa = PBXGroup; + children = ( + 0042817125E6EFC4004945B3 /* LSStubRequest.m */, + 0042817225E6EFC4004945B3 /* LSStubResponse.m */, + 0042817325E6EFC4004945B3 /* LSStubResponse.h */, + 0042817425E6EFC4004945B3 /* LSStubRequest.h */, + ); + path = Stubs; + sourceTree = ""; + }; + 0042817725E6EFC4004945B3 /* Diff */ = { + isa = PBXGroup; + children = ( + 0042817825E6EFC4004945B3 /* LSHTTPRequestDiff.m */, + 0042817925E6EFC4004945B3 /* LSHTTPRequestDiff.h */, + ); + path = Diff; + sourceTree = ""; + }; + 0042817B25E6EFC4004945B3 /* Hooks */ = { + isa = PBXGroup; + children = ( + 0042817C25E6EFC4004945B3 /* LSHTTPClientHook.m */, + 0042817D25E6EFC4004945B3 /* LSHTTPClientHook.h */, + 0042817E25E6EFC4004945B3 /* NSURLRequest */, + 0042818725E6EFC4004945B3 /* ASIHTTPRequest */, + 0042818E25E6EFC4004945B3 /* NSURLSession */, + ); + path = Hooks; + sourceTree = ""; + }; + 0042817E25E6EFC4004945B3 /* NSURLRequest */ = { + isa = PBXGroup; + children = ( + 0042817F25E6EFC4004945B3 /* NSURLRequest+LSHTTPRequest.m */, + 0042818025E6EFC4004945B3 /* NSURLRequest+DSL.h */, + 0042818125E6EFC4004945B3 /* LSNSURLHook.h */, + 0042818225E6EFC4004945B3 /* LSHTTPStubURLProtocol.h */, + 0042818325E6EFC4004945B3 /* NSURLRequest+LSHTTPRequest.h */, + 0042818425E6EFC4004945B3 /* LSNSURLHook.m */, + 0042818525E6EFC4004945B3 /* NSURLRequest+DSL.m */, + 0042818625E6EFC4004945B3 /* LSHTTPStubURLProtocol.m */, + ); + path = NSURLRequest; + sourceTree = ""; + }; + 0042818725E6EFC4004945B3 /* ASIHTTPRequest */ = { + isa = PBXGroup; + children = ( + 0042818825E6EFC4004945B3 /* LSASIHTTPRequestHook.h */, + 0042818925E6EFC4004945B3 /* ASIHTTPRequestStub.m */, + 0042818A25E6EFC4004945B3 /* LSASIHTTPRequestAdapter.h */, + 0042818B25E6EFC4004945B3 /* LSASIHTTPRequestHook.m */, + 0042818C25E6EFC4004945B3 /* LSASIHTTPRequestAdapter.m */, + 0042818D25E6EFC4004945B3 /* ASIHTTPRequestStub.h */, + ); + path = ASIHTTPRequest; + sourceTree = ""; + }; + 0042818E25E6EFC4004945B3 /* NSURLSession */ = { + isa = PBXGroup; + children = ( + 0042818F25E6EFC4004945B3 /* LSNSURLSessionHook.h */, + 0042819025E6EFC4004945B3 /* LSNSURLSessionHook.m */, + ); + path = NSURLSession; + sourceTree = ""; + }; + 0042819125E6EFC4004945B3 /* Model */ = { + isa = PBXGroup; + children = ( + 0042819225E6EFC4004945B3 /* LSHTTPBody.h */, + 0042819325E6EFC4004945B3 /* LSHTTPRequest.h */, + 0042819425E6EFC4004945B3 /* LSHTTPResponse.h */, + ); + path = Model; + sourceTree = ""; + }; + 0042819625E6EFC4004945B3 /* Matchers */ = { + isa = PBXGroup; + children = ( + 0042819725E6EFC4004945B3 /* LSMatcheable.h */, + 0042819825E6EFC4004945B3 /* LSMatcher.h */, + 0042819925E6EFC4004945B3 /* LSStringMatcher.h */, + 0042819A25E6EFC4004945B3 /* NSRegularExpression+Matcheable.m */, + 0042819B25E6EFC4004945B3 /* LSRegexMatcher.h */, + 0042819C25E6EFC4004945B3 /* NSString+Matcheable.m */, + 0042819D25E6EFC4004945B3 /* NSData+Matcheable.m */, + 0042819E25E6EFC4004945B3 /* LSDataMatcher.m */, + 0042819F25E6EFC4004945B3 /* LSMatcher.m */, + 004281A025E6EFC4004945B3 /* LSRegexMatcher.m */, + 004281A125E6EFC4004945B3 /* NSRegularExpression+Matcheable.h */, + 004281A225E6EFC4004945B3 /* LSStringMatcher.m */, + 004281A325E6EFC4004945B3 /* NSString+Matcheable.h */, + 004281A425E6EFC4004945B3 /* LSDataMatcher.h */, + 004281A525E6EFC4004945B3 /* NSData+Matcheable.h */, + ); + path = Matchers; + sourceTree = ""; + }; + 004281A625E6EFC4004945B3 /* Categories */ = { + isa = PBXGroup; + children = ( + 004281A725E6EFC4004945B3 /* NSData+Nocilla.h */, + 004281A825E6EFC4004945B3 /* NSString+Nocilla.m */, + 004281A925E6EFC4004945B3 /* NSData+Nocilla.m */, + 004281AA25E6EFC4004945B3 /* NSString+Nocilla.h */, + ); + path = Categories; + sourceTree = ""; + }; + 004281AB25E6EFC4004945B3 /* DSL */ = { + isa = PBXGroup; + children = ( + 004281AC25E6EFC4004945B3 /* LSHTTPRequestDSLRepresentation.m */, + 004281AD25E6EFC4004945B3 /* LSStubRequestDSL.h */, + 004281AE25E6EFC4004945B3 /* LSStubResponseDSL.m */, + 004281AF25E6EFC4004945B3 /* LSStubRequestDSL.m */, + 004281B025E6EFC4004945B3 /* LSHTTPRequestDSLRepresentation.h */, + 004281B125E6EFC4004945B3 /* LSStubResponseDSL.h */, + ); + path = DSL; + sourceTree = ""; + }; 006D273324D8BAE500947551 /* Utilities */ = { isa = PBXGroup; children = ( @@ -7575,6 +7807,7 @@ 6714D6C9245A2B6A00CE5A4A /* Manual Tests */, BCA6764F1AC05FE200A16160 /* Utilities */, BCD67E7D1C1F12F2005179E1 /* Tests */, + 0042816E25E6EF58004945B3 /* Third Party */, ); name = Code; sourceTree = ""; @@ -10088,12 +10321,17 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 004281BE25E6EFC4004945B3 /* LSNSURLSessionHook.m in Sources */, D84649AD1D4514F7009DB4A0 /* WMFTaskGroupTests.m in Sources */, + 004281C125E6EFC4004945B3 /* NSData+Matcheable.m in Sources */, B0E808B61C0D17070065EBC0 /* LSStubResponseDSL+WithJSON.m in Sources */, B0E809371C0D1A420065EBC0 /* MWKLanguageLinkControllerTests.m in Sources */, 673612F224FD7210002A1989 /* ArticleAsLivingDocViewModelTests.swift in Sources */, + 004281C525E6EFC4004945B3 /* LSStringMatcher.m in Sources */, + 004281B925E6EFC4004945B3 /* NSURLRequest+DSL.m in Sources */, B0E809411C0D1A820065EBC0 /* NSURL+WMFLinkParsingTests.m in Sources */, B0E808981C0D16430065EBC0 /* XCTestCase+WMFLocaleTesting.m in Sources */, + 004281B825E6EFC4004945B3 /* LSNSURLHook.m in Sources */, BC45FF4B1C1B22C200BAE501 /* NSObject+WMFReflection.m in Sources */, A452F9FD24081B0200D8ED09 /* MockUIDevice.swift in Sources */, B0E808741C0D154C0065EBC0 /* NSBundle+TestAssets.m in Sources */, @@ -10112,15 +10350,19 @@ 679F0AA92456FADE00EF4A6A /* ArticleCacheReadingTests.swift in Sources */, 67E3992C24786E6D00441831 /* TalkPageManualPerformanceTests.swift in Sources */, B0C06B9F218240CA00E481CC /* Collection+AsyncMapTests.swift in Sources */, + 004281CA25E6EFC4004945B3 /* LSStubRequestDSL.m in Sources */, BC62AE621C58FC810064C589 /* NSProcessInfo+WMFTestEnvironment.m in Sources */, D8BDA8C11E71C0760031F4BF /* WMFBlocksKitTests.m in Sources */, B0E8092F1C0D1A0B0065EBC0 /* NSURL+WMFExtrasTests.m in Sources */, B39427441E71F79700D3146D /* NSDictionaryBlocksKitTest.m in Sources */, 6790AAF522D6861500D442D6 /* TalkPageControllerTests.swift in Sources */, B0E808771C0D155A0065EBC0 /* XCTestCase+WMFBundleConvenience.m in Sources */, + 004281BC25E6EFC4004945B3 /* LSASIHTTPRequestHook.m in Sources */, B389CFCB1E6784B600483C06 /* WMFDatabaseHousekeeperTests.swift in Sources */, B0E809601C0D1BA30065EBC0 /* WMFSearchFetcherTests.m in Sources */, + 004281C325E6EFC4004945B3 /* LSMatcher.m in Sources */, D820F78B1DD0E5E100806045 /* WMFNotificationTests.m in Sources */, + 004281B325E6EFC4004945B3 /* LSStubResponse.m in Sources */, B01662B31D1B8CAB006F4544 /* NSURL+WMFQueryParametersTests.m in Sources */, D8D550811DF0D2BD00B90177 /* NSArray+WMFMatching.m in Sources */, 8330533323F0388E00123141 /* DataStoreTests.swift in Sources */, @@ -10129,32 +10371,42 @@ B0E8087D1C0D15760065EBC0 /* WMFRandomFileUtilities.m in Sources */, BC90DE791C57C5AD007E0E81 /* WMFWelcomeLanguageViewControllerVisualTests.m in Sources */, B0E809551C0D1B510065EBC0 /* CLLocation+WMFBearingTests.m in Sources */, + 004281BF25E6EFC4004945B3 /* NSRegularExpression+Matcheable.m in Sources */, 679FA104242E651C0095F3C6 /* ArticleManualPerformanceTests.swift in Sources */, + 004281B725E6EFC4004945B3 /* NSURLRequest+LSHTTPRequest.m in Sources */, D858A7DF1DA6A04A009C3DEB /* WMFDateCalculationTests.m in Sources */, + 004281BA25E6EFC4004945B3 /* LSHTTPStubURLProtocol.m in Sources */, B0E809051C0D18A00065EBC0 /* CircularBitwiseRotationTests.m in Sources */, B0E8095E1C0D1B930065EBC0 /* WMFMTLModelSerializationTests.m in Sources */, D8EC64031D007B1F00C286EE /* WMFLinkParsingTests.m in Sources */, + 004281C725E6EFC4004945B3 /* NSData+Nocilla.m in Sources */, B0E809131C0D19090065EBC0 /* WMFDateFormatterTests.m in Sources */, 83BBBE5623F56F9400AD0994 /* LocaleTests.swift in Sources */, B39427451E71F79700D3146D /* NSSetBlocksKitTest.m in Sources */, 67ED8EB124F99FF400DD5D39 /* SignificantEventsFetcherTests.swift in Sources */, B0E808B91C0D17160065EBC0 /* WMFHTTPHangingProtocol.m in Sources */, BC52D0F71C207D3300F625A9 /* TWNStringsTests.m in Sources */, + 004281BD25E6EFC4004945B3 /* LSASIHTTPRequestAdapter.m in Sources */, B0E808A91C0D16A00065EBC0 /* UIView+VisualTestSizingUtils.m in Sources */, BC45FF481C1B1F9F00BAE501 /* NSUserDefaults+WMFReset.m in Sources */, + 004281BB25E6EFC4004945B3 /* ASIHTTPRequestStub.m in Sources */, 6714D6CB245A2B9700CE5A4A /* ArticleCacheReadingManualTests.swift in Sources */, + 004281C825E6EFC4004945B3 /* LSHTTPRequestDSLRepresentation.m in Sources */, B02F96661DFA11DC007DA007 /* WMFArticleListTableViewCell+DynamicTypeFontTests.swift in Sources */, + 004281B625E6EFC4004945B3 /* LSHTTPClientHook.m in Sources */, B0E809351C0D1A2F0065EBC0 /* WMFGeometryTests.m in Sources */, 6714D6CD245A2C1D00CE5A4A /* ArticleTestHelpers.swift in Sources */, B0E8090B1C0D18D90065EBC0 /* NSString+FormattedAttributedStringTests.m in Sources */, D8396D1B22CF7052005625D8 /* WMFArticleTests.swift in Sources */, B0E8090D1C0D18E70065EBC0 /* WMFImageURLParsingTests.m in Sources */, 6790AAF722D6861500D442D6 /* TalkPageLocalHandlerTests.swift in Sources */, + 004281B525E6EFC4004945B3 /* LSHTTPRequestDiff.m in Sources */, A452F9F924081A5500D8ED09 /* MockCLHeading.swift in Sources */, 6790AAF322D6861500D442D6 /* TalkPageNetworkDataTests.swift in Sources */, B0E8089C1C0D165B0065EBC0 /* XCTestCase+SwiftDefaults.swift in Sources */, BCD3200A1C6EC6BC00317D08 /* NSTimeZone+WMFTestingUtils.m in Sources */, B0E808831C0D15A20065EBC0 /* MWKDataStore+TemporaryDataStore.m in Sources */, + 004281B425E6EFC4004945B3 /* LSNocilla.m in Sources */, B37B6FE91EEAFE11007CBB12 /* EventLoggingServiceTests.swift in Sources */, B0E8086D1C0D15170065EBC0 /* WMFCodingStyle.m in Sources */, 830ECAD61FBDE77F0080B1EF /* ReadingListsTests.swift in Sources */, @@ -10163,7 +10415,13 @@ BCD557BB1C45B1600060A51A /* UIApplication+VisualTestUtils.m in Sources */, B0E809091C0D18BC0065EBC0 /* NSString+WMFHTMLParsingTests.m in Sources */, 19A175F095F5197BA20EA8BA /* NSUserActivity+WMFExtensionsTest.m in Sources */, + 004281C925E6EFC4004945B3 /* LSStubResponseDSL.m in Sources */, + 004281B225E6EFC4004945B3 /* LSStubRequest.m in Sources */, 6790AAF622D6861500D442D6 /* TalkPageTestHelpers.swift in Sources */, + 004281C025E6EFC4004945B3 /* NSString+Matcheable.m in Sources */, + 004281C425E6EFC4004945B3 /* LSRegexMatcher.m in Sources */, + 004281C225E6EFC4004945B3 /* LSDataMatcher.m in Sources */, + 004281C625E6EFC4004945B3 /* NSString+Nocilla.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/WikipediaUnitTests/Code/LSStubResponseDSL+WithJSON.h b/WikipediaUnitTests/Code/LSStubResponseDSL+WithJSON.h index cab1c0e614d..5346d65c3b0 100644 --- a/WikipediaUnitTests/Code/LSStubResponseDSL+WithJSON.h +++ b/WikipediaUnitTests/Code/LSStubResponseDSL+WithJSON.h @@ -1,4 +1,4 @@ -#import +#import "Nocilla.h" typedef LSStubResponseDSL * (^WithJSONMethod)(id json); diff --git a/WikipediaUnitTests/Code/WMFNotificationTests.m b/WikipediaUnitTests/Code/WMFNotificationTests.m index acd12028824..770acc9436c 100644 --- a/WikipediaUnitTests/Code/WMFNotificationTests.m +++ b/WikipediaUnitTests/Code/WMFNotificationTests.m @@ -1,7 +1,7 @@ #import #import "MWKDataStore+TemporaryDataStore.h" #import -#import +#import "LSNocilla.h" #import "MWKDataStore+TemporaryDataStore.h" #import "WMFRandomFileUtilities.h" #import "NSUserDefaults+WMFReset.h" diff --git a/WikipediaUnitTests/Code/WikipediaUnitTests-Bridging-Header.h b/WikipediaUnitTests/Code/WikipediaUnitTests-Bridging-Header.h index f01489ec387..c8dc7331c00 100644 --- a/WikipediaUnitTests/Code/WikipediaUnitTests-Bridging-Header.h +++ b/WikipediaUnitTests/Code/WikipediaUnitTests-Bridging-Header.h @@ -3,7 +3,7 @@ #import "MWKDataStore+TemporaryDataStore.h" #import "WMFRandomFileUtilities.h" #import "WMFHTTPHangingProtocol.h" -#import +#import "Nocilla.h" #import "UIViewController+WMFStoryboardUtilities.h" #import "XCTestCase+WMFBundleConvenience.h" #import "NSBundle+TestAssets.h" diff --git a/WikipediaUnitTests/Third Party/Nocilla/Categories/NSData+Nocilla.h b/WikipediaUnitTests/Third Party/Nocilla/Categories/NSData+Nocilla.h new file mode 100644 index 00000000000..92ebbc75c8b --- /dev/null +++ b/WikipediaUnitTests/Third Party/Nocilla/Categories/NSData+Nocilla.h @@ -0,0 +1,6 @@ +#import +#import "LSHTTPBody.h" + +@interface NSData (Nocilla) + +@end diff --git a/WikipediaUnitTests/Third Party/Nocilla/Categories/NSData+Nocilla.m b/WikipediaUnitTests/Third Party/Nocilla/Categories/NSData+Nocilla.m new file mode 100644 index 00000000000..0572aeb50f5 --- /dev/null +++ b/WikipediaUnitTests/Third Party/Nocilla/Categories/NSData+Nocilla.m @@ -0,0 +1,9 @@ +#import "NSData+Nocilla.h" + +@implementation NSData (Nocilla) + +- (NSData *)data { + return self; +} + +@end diff --git a/WikipediaUnitTests/Third Party/Nocilla/Categories/NSString+Nocilla.h b/WikipediaUnitTests/Third Party/Nocilla/Categories/NSString+Nocilla.h new file mode 100644 index 00000000000..cc0df6d8947 --- /dev/null +++ b/WikipediaUnitTests/Third Party/Nocilla/Categories/NSString+Nocilla.h @@ -0,0 +1,8 @@ +#import +#import "LSHTTPBody.h" + +@interface NSString (Nocilla) + +- (NSRegularExpression *)regex; + +@end diff --git a/WikipediaUnitTests/Third Party/Nocilla/Categories/NSString+Nocilla.m b/WikipediaUnitTests/Third Party/Nocilla/Categories/NSString+Nocilla.m new file mode 100644 index 00000000000..be28f78a77d --- /dev/null +++ b/WikipediaUnitTests/Third Party/Nocilla/Categories/NSString+Nocilla.m @@ -0,0 +1,18 @@ +#import "NSString+Nocilla.h" + +@implementation NSString (Nocilla) + +- (NSRegularExpression *)regex { + NSError *error = nil; + NSRegularExpression *regex = [[NSRegularExpression alloc] initWithPattern:self options:0 error:&error]; + if (error) { + [NSException raise:NSInvalidArgumentException format:@"Invalid regex pattern: %@\nError: %@", self, error]; + } + return regex; +} + +- (NSData *)data { + return [self dataUsingEncoding:NSUTF8StringEncoding]; +} + +@end diff --git a/WikipediaUnitTests/Third Party/Nocilla/DSL/LSHTTPRequestDSLRepresentation.h b/WikipediaUnitTests/Third Party/Nocilla/DSL/LSHTTPRequestDSLRepresentation.h new file mode 100644 index 00000000000..6a5fcb10565 --- /dev/null +++ b/WikipediaUnitTests/Third Party/Nocilla/DSL/LSHTTPRequestDSLRepresentation.h @@ -0,0 +1,6 @@ +#import +#import "LSHTTPRequest.h" + +@interface LSHTTPRequestDSLRepresentation : NSObject +- (id)initWithRequest:(id)request; +@end diff --git a/WikipediaUnitTests/Third Party/Nocilla/DSL/LSHTTPRequestDSLRepresentation.m b/WikipediaUnitTests/Third Party/Nocilla/DSL/LSHTTPRequestDSLRepresentation.m new file mode 100644 index 00000000000..bcfbb96cc71 --- /dev/null +++ b/WikipediaUnitTests/Third Party/Nocilla/DSL/LSHTTPRequestDSLRepresentation.m @@ -0,0 +1,39 @@ +#import "LSHTTPRequestDSLRepresentation.h" + +@interface LSHTTPRequestDSLRepresentation () +@property (nonatomic, strong) id request; +@end + +@implementation LSHTTPRequestDSLRepresentation +- (id)initWithRequest:(id)request { + self = [super init]; + if (self) { + _request = request; + } + return self; +} + +- (NSString *)description { + NSMutableString *result = [NSMutableString stringWithFormat:@"stubRequest(@\"%@\", @\"%@\")", self.request.method, [self.request.url absoluteString]]; + if (self.request.headers.count) { + [result appendString:@".\nwithHeaders(@{ "]; + NSMutableArray *headerElements = [NSMutableArray arrayWithCapacity:self.request.headers.count]; + + NSArray *descriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"" ascending:YES]]; + NSArray * sortedHeaders = [[self.request.headers allKeys] sortedArrayUsingDescriptors:descriptors]; + + for (NSString * header in sortedHeaders) { + NSString *value = [self.request.headers objectForKey:header]; + [headerElements addObject:[NSString stringWithFormat:@"@\"%@\": @\"%@\"", header, value]]; + } + [result appendString:[headerElements componentsJoinedByString:@", "]]; + [result appendString:@" })"]; + } + if (self.request.body.length) { + NSString *escapedBody = [[NSString alloc] initWithData:self.request.body encoding:NSUTF8StringEncoding]; + escapedBody = [escapedBody stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""]; + [result appendFormat:@".\nwithBody(@\"%@\")", escapedBody]; + } + return [NSString stringWithFormat:@"%@;", result]; +} +@end diff --git a/WikipediaUnitTests/Third Party/Nocilla/DSL/LSStubRequestDSL.h b/WikipediaUnitTests/Third Party/Nocilla/DSL/LSStubRequestDSL.h new file mode 100644 index 00000000000..d7df7430b34 --- /dev/null +++ b/WikipediaUnitTests/Third Party/Nocilla/DSL/LSStubRequestDSL.h @@ -0,0 +1,39 @@ +#import +#import "NSString+Matcheable.h" +#import "NSRegularExpression+Matcheable.h" +#import "NSData+Matcheable.h" + +@class LSStubRequestDSL; +@class LSStubResponseDSL; +@class LSStubRequest; + +@protocol LSHTTPBody; + +typedef LSStubRequestDSL *(^WithHeaderMethod)(NSString *, NSString *); +typedef LSStubRequestDSL *(^WithHeadersMethod)(NSDictionary *); +typedef LSStubRequestDSL *(^AndBodyMethod)(id); +typedef LSStubResponseDSL *(^AndReturnMethod)(NSInteger); +typedef LSStubResponseDSL *(^AndReturnRawResponseMethod)(NSData *rawResponseData); +typedef void (^AndFailWithErrorMethod)(NSError *error); + +@interface LSStubRequestDSL : NSObject +- (id)initWithRequest:(LSStubRequest *)request; + +@property (nonatomic, strong, readonly) WithHeaderMethod withHeader; +@property (nonatomic, strong, readonly) WithHeadersMethod withHeaders; +@property (nonatomic, strong, readonly) AndBodyMethod withBody; +@property (nonatomic, strong, readonly) AndReturnMethod andReturn; +@property (nonatomic, strong, readonly) AndReturnRawResponseMethod andReturnRawResponse; +@property (nonatomic, strong, readonly) AndFailWithErrorMethod andFailWithError; + +@end + +#ifdef __cplusplus +extern "C" { +#endif + +LSStubRequestDSL * stubRequest(NSString *method, id url); + +#ifdef __cplusplus +} +#endif diff --git a/WikipediaUnitTests/Third Party/Nocilla/DSL/LSStubRequestDSL.m b/WikipediaUnitTests/Third Party/Nocilla/DSL/LSStubRequestDSL.m new file mode 100644 index 00000000000..831e0c0146a --- /dev/null +++ b/WikipediaUnitTests/Third Party/Nocilla/DSL/LSStubRequestDSL.m @@ -0,0 +1,72 @@ +#import "LSStubRequestDSL.h" +#import "LSStubResponseDSL.h" +#import "LSStubRequest.h" +#import "LSNocilla.h" + +@interface LSStubRequestDSL () +@property (nonatomic, strong) LSStubRequest *request; +@end + +@implementation LSStubRequestDSL + +- (id)initWithRequest:(LSStubRequest *)request { + self = [super init]; + if (self) { + _request = request; + } + return self; +} +- (WithHeadersMethod)withHeaders { + return ^(NSDictionary *headers) { + for (NSString *header in headers) { + NSString *value = [headers objectForKey:header]; + [self.request setHeader:header value:value]; + } + return self; + }; +} + +- (WithHeaderMethod)withHeader { + return ^(NSString * header, NSString * value) { + [self.request setHeader:header value:value]; + return self; + }; +} + +- (AndBodyMethod)withBody { + return ^(id body) { + self.request.body = body.matcher; + return self; + }; +} + +- (AndReturnMethod)andReturn { + return ^(NSInteger statusCode) { + self.request.response = [[LSStubResponse alloc] initWithStatusCode:statusCode]; + LSStubResponseDSL *responseDSL = [[LSStubResponseDSL alloc] initWithResponse:self.request.response]; + return responseDSL; + }; +} + +- (AndReturnRawResponseMethod)andReturnRawResponse { + return ^(NSData *rawResponseData) { + self.request.response = [[LSStubResponse alloc] initWithRawResponse:rawResponseData]; + LSStubResponseDSL *responseDSL = [[LSStubResponseDSL alloc] initWithResponse:self.request.response]; + return responseDSL; + }; +} + +- (AndFailWithErrorMethod)andFailWithError { + return ^(NSError *error) { + self.request.response = [[LSStubResponse alloc] initWithError:error]; + }; +} + +@end + +LSStubRequestDSL * stubRequest(NSString *method, id url) { + LSStubRequest *request = [[LSStubRequest alloc] initWithMethod:method urlMatcher:url.matcher]; + LSStubRequestDSL *dsl = [[LSStubRequestDSL alloc] initWithRequest:request]; + [[LSNocilla sharedInstance] addStubbedRequest:request]; + return dsl; +} diff --git a/WikipediaUnitTests/Third Party/Nocilla/DSL/LSStubResponseDSL.h b/WikipediaUnitTests/Third Party/Nocilla/DSL/LSStubResponseDSL.h new file mode 100644 index 00000000000..2ba6b66332c --- /dev/null +++ b/WikipediaUnitTests/Third Party/Nocilla/DSL/LSStubResponseDSL.h @@ -0,0 +1,19 @@ +#import + +@class LSStubResponse; +@class LSStubResponseDSL; + +@protocol LSHTTPBody; + +typedef LSStubResponseDSL *(^ResponseWithBodyMethod)(id); +typedef LSStubResponseDSL *(^ResponseWithHeaderMethod)(NSString *, NSString *); +typedef LSStubResponseDSL *(^ResponseWithHeadersMethod)(NSDictionary *); + +@interface LSStubResponseDSL : NSObject +- (id)initWithResponse:(LSStubResponse *)response; + +@property (nonatomic, strong, readonly) ResponseWithHeaderMethod withHeader; +@property (nonatomic, strong, readonly) ResponseWithHeadersMethod withHeaders; +@property (nonatomic, strong, readonly) ResponseWithBodyMethod withBody; + +@end diff --git a/WikipediaUnitTests/Third Party/Nocilla/DSL/LSStubResponseDSL.m b/WikipediaUnitTests/Third Party/Nocilla/DSL/LSStubResponseDSL.m new file mode 100644 index 00000000000..06e97864467 --- /dev/null +++ b/WikipediaUnitTests/Third Party/Nocilla/DSL/LSStubResponseDSL.m @@ -0,0 +1,40 @@ +#import "LSStubResponseDSL.h" +#import "LSStubResponse.h" +#import "LSHTTPBody.h" + +@interface LSStubResponseDSL () +@property (nonatomic, strong) LSStubResponse *response; +@end + +@implementation LSStubResponseDSL +- (id)initWithResponse:(LSStubResponse *)response { + self = [super init]; + if (self) { + _response = response; + } + return self; +} +- (ResponseWithHeaderMethod)withHeader { + return ^(NSString * header, NSString * value) { + [self.response setHeader:header value:value]; + return self; + }; +} + +- (ResponseWithHeadersMethod)withHeaders; { + return ^(NSDictionary *headers) { + for (NSString *header in headers) { + NSString *value = [headers objectForKey:header]; + [self.response setHeader:header value:value]; + } + return self; + }; +} + +- (ResponseWithBodyMethod)withBody { + return ^(id body) { + self.response.body = [body data]; + return self; + }; +} +@end diff --git a/WikipediaUnitTests/Third Party/Nocilla/Diff/LSHTTPRequestDiff.h b/WikipediaUnitTests/Third Party/Nocilla/Diff/LSHTTPRequestDiff.h new file mode 100644 index 00000000000..2f9b8eac450 --- /dev/null +++ b/WikipediaUnitTests/Third Party/Nocilla/Diff/LSHTTPRequestDiff.h @@ -0,0 +1,8 @@ +#import +#import "LSHTTPRequest.h" + +@interface LSHTTPRequestDiff : NSObject +@property (nonatomic, assign, readonly, getter = isEmpty) BOOL empty; + +- (id)initWithRequest:(id)oneRequest andRequest:(id)anotherRequest; +@end diff --git a/WikipediaUnitTests/Third Party/Nocilla/Diff/LSHTTPRequestDiff.m b/WikipediaUnitTests/Third Party/Nocilla/Diff/LSHTTPRequestDiff.m new file mode 100644 index 00000000000..413121d5721 --- /dev/null +++ b/WikipediaUnitTests/Third Party/Nocilla/Diff/LSHTTPRequestDiff.m @@ -0,0 +1,114 @@ +#import "LSHTTPRequestDiff.h" + +@interface LSHTTPRequestDiff () +@property (nonatomic, strong) idoneRequest; +@property (nonatomic, strong) idanotherRequest; + +- (BOOL)isMethodDifferent; +- (BOOL)isUrlDifferent; +- (BOOL)areHeadersDifferent; +- (BOOL)isBodyDifferent; + +- (void)appendMethodDiff:(NSMutableString *)diff; +- (void)appendUrlDiff:(NSMutableString *)diff; +- (void)appendHeadersDiff:(NSMutableString *)diff; +- (void)appendBodyDiff:(NSMutableString *)diff; +@end + +@implementation LSHTTPRequestDiff +- (id)initWithRequest:(id)oneRequest andRequest:(id)anotherRequest { + self = [super init]; + if (self) { + _oneRequest = oneRequest; + _anotherRequest = anotherRequest; + } + return self; +} + +- (BOOL)isEmpty { + if ([self isMethodDifferent] || + [self isUrlDifferent] || + [self areHeadersDifferent] || + [self isBodyDifferent]) { + return NO; + } + return YES; +} + +- (NSString *)description { + NSMutableString *diff = [@"" mutableCopy]; + if ([self isMethodDifferent]) { + [self appendMethodDiff:diff]; + } + if ([self isUrlDifferent]) { + [self appendUrlDiff:diff]; + } + if([self areHeadersDifferent]) { + [self appendHeadersDiff:diff]; + } + if([self isBodyDifferent]) { + [self appendBodyDiff:diff]; + } + return [NSString stringWithString:diff]; +} + +#pragma mark - Private Methods +- (BOOL)isMethodDifferent { + return ![self.oneRequest.method isEqualToString:self.anotherRequest.method]; +} + +- (BOOL)isUrlDifferent { + return ![self.oneRequest.url isEqual:self.anotherRequest.url]; +} + +- (BOOL)areHeadersDifferent { + return ![self.oneRequest.headers isEqual:self.anotherRequest.headers]; +} + +- (BOOL)isBodyDifferent { + return (((self.oneRequest.body) && (![self.oneRequest.body isEqual:self.anotherRequest.body])) || + ((self.anotherRequest.body) && (![self.anotherRequest.body isEqual:self.oneRequest.body]))); +} + +- (void)appendMethodDiff:(NSMutableString *)diff { + [diff appendFormat:@"- Method: %@\n+ Method: %@\n", self.oneRequest.method, self.anotherRequest.method]; +} + +- (void)appendUrlDiff:(NSMutableString *)diff { + [diff appendFormat:@"- URL: %@\n+ URL: %@\n", [self.oneRequest.url absoluteString], [self.anotherRequest.url absoluteString]]; +} + +- (void)appendHeadersDiff:(NSMutableString *)diff { + [diff appendString:@" Headers:\n"]; + NSSet *headersInOneButNotInTheOther = [self.oneRequest.headers keysOfEntriesPassingTest:^BOOL(id key, id obj, BOOL *stop) { + return ![self.anotherRequest.headers objectForKey:key] || ![obj isEqual:[self.anotherRequest.headers objectForKey:key]]; + }]; + NSSet *headersInTheOtherButNotInOne = [self.anotherRequest.headers keysOfEntriesPassingTest:^BOOL(id key, id obj, BOOL *stop) { + return ![self.oneRequest.headers objectForKey:key] || ![obj isEqual:[self.oneRequest.headers objectForKey:key]]; + }]; + + NSArray *descriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"" ascending:YES]]; + NSArray * sortedHeadersInOneButNotInTheOther = [headersInOneButNotInTheOther sortedArrayUsingDescriptors:descriptors]; + NSArray * sortedHeadersInTheOtherButNotInOne = [headersInTheOtherButNotInOne sortedArrayUsingDescriptors:descriptors]; + for (NSString *header in sortedHeadersInOneButNotInTheOther) { + NSString *value = [self.oneRequest.headers objectForKey:header]; + [diff appendFormat:@"-\t\"%@\": \"%@\"\n", header, value]; + + } + for (NSString *header in sortedHeadersInTheOtherButNotInOne) { + NSString *value = [self.anotherRequest.headers objectForKey:header]; + [diff appendFormat:@"+\t\"%@\": \"%@\"\n", header, value]; + } +} + +- (void)appendBodyDiff:(NSMutableString *)diff { + NSString *oneBody = [[NSString alloc] initWithData:self.oneRequest.body encoding:NSUTF8StringEncoding]; + if (oneBody.length) { + [diff appendFormat:@"- Body: \"%@\"\n", oneBody]; + } + NSString *anotherBody = [[NSString alloc] initWithData:self.anotherRequest.body encoding:NSUTF8StringEncoding]; + if (anotherBody.length) { + [diff appendFormat:@"+ Body: \"%@\"\n", anotherBody]; + } +} +@end diff --git a/WikipediaUnitTests/Third Party/Nocilla/Hooks/ASIHTTPRequest/ASIHTTPRequestStub.h b/WikipediaUnitTests/Third Party/Nocilla/Hooks/ASIHTTPRequest/ASIHTTPRequestStub.h new file mode 100644 index 00000000000..f9ef36aca1e --- /dev/null +++ b/WikipediaUnitTests/Third Party/Nocilla/Hooks/ASIHTTPRequest/ASIHTTPRequestStub.h @@ -0,0 +1,8 @@ +#import + +@interface ASIHTTPRequestStub : NSObject +- (int)stub_responseStatusCode; +- (NSData *)stub_responseData; +- (NSDictionary *)stub_responseHeaders; +- (void)stub_startRequest; +@end diff --git a/WikipediaUnitTests/Third Party/Nocilla/Hooks/ASIHTTPRequest/ASIHTTPRequestStub.m b/WikipediaUnitTests/Third Party/Nocilla/Hooks/ASIHTTPRequest/ASIHTTPRequestStub.m new file mode 100644 index 00000000000..712b4c91651 --- /dev/null +++ b/WikipediaUnitTests/Third Party/Nocilla/Hooks/ASIHTTPRequest/ASIHTTPRequestStub.m @@ -0,0 +1,52 @@ +#import "ASIHTTPRequestStub.h" +#import "LSStubResponse.h" +#import "LSNocilla.h" +#import "LSASIHTTPRequestAdapter.h" +#import + +@interface ASIHTTPRequestStub () +@property (nonatomic, strong) LSStubResponse *stubResponse; +@end + +@interface ASIHTTPRequestStub (Private) +- (void)failWithError:(NSError *)error; +- (void)requestFinished; +- (void)markAsFinished; +@end + +static void const * ASIHTTPRequestStubResponseKey = &ASIHTTPRequestStubResponseKey; + +@implementation ASIHTTPRequestStub + +- (void)setStubResponse:(LSStubResponse *)stubResponse { + objc_setAssociatedObject(self, ASIHTTPRequestStubResponseKey, stubResponse, OBJC_ASSOCIATION_RETAIN); +} + +- (LSStubResponse *)stubResponse { + return objc_getAssociatedObject(self, ASIHTTPRequestStubResponseKey); +} + +- (int)stub_responseStatusCode { + return (int)self.stubResponse.statusCode; +} + +- (NSData *)stub_responseData { + return self.stubResponse.body; +} + +- (NSDictionary *)stub_responseHeaders { + return self.stubResponse.headers; +} + +- (void)stub_startRequest { + self.stubResponse = [[LSNocilla sharedInstance] responseForRequest:[[LSASIHTTPRequestAdapter alloc] initWithASIHTTPRequest:(id)self]]; + + if (self.stubResponse.shouldFail) { + [self failWithError:self.stubResponse.error]; + } else { + [self requestFinished]; + } + [self markAsFinished]; +} + +@end \ No newline at end of file diff --git a/WikipediaUnitTests/Third Party/Nocilla/Hooks/ASIHTTPRequest/LSASIHTTPRequestAdapter.h b/WikipediaUnitTests/Third Party/Nocilla/Hooks/ASIHTTPRequest/LSASIHTTPRequestAdapter.h new file mode 100644 index 00000000000..6cf7b1c4773 --- /dev/null +++ b/WikipediaUnitTests/Third Party/Nocilla/Hooks/ASIHTTPRequest/LSASIHTTPRequestAdapter.h @@ -0,0 +1,10 @@ +#import +#import "LSHTTPRequest.h" + +@class ASIHTTPRequest; + +@interface LSASIHTTPRequestAdapter : NSObject + +- (instancetype)initWithASIHTTPRequest:(ASIHTTPRequest *)request; + +@end diff --git a/WikipediaUnitTests/Third Party/Nocilla/Hooks/ASIHTTPRequest/LSASIHTTPRequestAdapter.m b/WikipediaUnitTests/Third Party/Nocilla/Hooks/ASIHTTPRequest/LSASIHTTPRequestAdapter.m new file mode 100644 index 00000000000..91cf7913c7a --- /dev/null +++ b/WikipediaUnitTests/Third Party/Nocilla/Hooks/ASIHTTPRequest/LSASIHTTPRequestAdapter.m @@ -0,0 +1,42 @@ +#import "LSASIHTTPRequestAdapter.h" + +@interface ASIHTTPRequest + +@property (nonatomic, strong, readonly) NSURL *url; +@property (nonatomic, strong, readonly) NSString *requestMethod; +@property (nonatomic, strong, readonly) NSDictionary *requestHeaders; +@property (nonatomic, strong, readonly) NSData *postBody; + +@end + +@interface LSASIHTTPRequestAdapter () +@property (nonatomic, strong) ASIHTTPRequest *request; +@end + +@implementation LSASIHTTPRequestAdapter + +- (instancetype)initWithASIHTTPRequest:(ASIHTTPRequest *)request { + self = [super init]; + if (self) { + _request = request; + } + return self; +} + +- (NSURL *)url { + return self.request.url; +} + +- (NSString *)method { + return self.request.requestMethod; +} + +- (NSDictionary *)headers { + return self.request.requestHeaders; +} + +- (NSData *)body { + return self.request.postBody; +} + +@end diff --git a/WikipediaUnitTests/Third Party/Nocilla/Hooks/ASIHTTPRequest/LSASIHTTPRequestHook.h b/WikipediaUnitTests/Third Party/Nocilla/Hooks/ASIHTTPRequest/LSASIHTTPRequestHook.h new file mode 100644 index 00000000000..2450072eecf --- /dev/null +++ b/WikipediaUnitTests/Third Party/Nocilla/Hooks/ASIHTTPRequest/LSASIHTTPRequestHook.h @@ -0,0 +1,5 @@ +#import "LSHTTPClientHook.h" + +@interface LSASIHTTPRequestHook : LSHTTPClientHook + +@end diff --git a/WikipediaUnitTests/Third Party/Nocilla/Hooks/ASIHTTPRequest/LSASIHTTPRequestHook.m b/WikipediaUnitTests/Third Party/Nocilla/Hooks/ASIHTTPRequest/LSASIHTTPRequestHook.m new file mode 100644 index 00000000000..1a32a47a06f --- /dev/null +++ b/WikipediaUnitTests/Third Party/Nocilla/Hooks/ASIHTTPRequest/LSASIHTTPRequestHook.m @@ -0,0 +1,48 @@ +#import "LSASIHTTPRequestHook.h" +#import "ASIHTTPRequestStub.h" +#import + +@implementation LSASIHTTPRequestHook + +- (void)load { + if (!NSClassFromString(@"ASIHTTPRequest")) return; + [self swizzleASIHTTPRequest]; +} + +- (void)unload { + if (!NSClassFromString(@"ASIHTTPRequest")) return; + [self swizzleASIHTTPRequest]; +} + +#pragma mark - Internal Methods + +- (void)swizzleASIHTTPRequest { + [self swizzleASIHTTPSelector:NSSelectorFromString(@"responseStatusCode") withSelector:@selector(stub_responseStatusCode)]; + [self swizzleASIHTTPSelector:NSSelectorFromString(@"responseData") withSelector:@selector(stub_responseData)]; + [self swizzleASIHTTPSelector:NSSelectorFromString(@"responseHeaders") withSelector:@selector(stub_responseHeaders)]; + [self swizzleASIHTTPSelector:NSSelectorFromString(@"startRequest") withSelector:@selector(stub_startRequest)]; + [self addMethodToASIHTTPRequest:NSSelectorFromString(@"stubResponse")]; + [self addMethodToASIHTTPRequest:NSSelectorFromString(@"setStubResponse:")]; +} + +- (void)swizzleASIHTTPSelector:(SEL)original withSelector:(SEL)stub { + Class asiHttpRequest = NSClassFromString(@"ASIHTTPRequest"); + Method originalMethod = class_getInstanceMethod(asiHttpRequest, original); + Method stubMethod = class_getInstanceMethod([ASIHTTPRequestStub class], stub); + if (!originalMethod || !stubMethod) { + [self fail]; + } + method_exchangeImplementations(originalMethod, stubMethod); +} + +- (void)addMethodToASIHTTPRequest:(SEL)newMethod { + Method method = class_getInstanceMethod([ASIHTTPRequestStub class], newMethod); + const char *types = method_getTypeEncoding(method); + class_addMethod(NSClassFromString(@"ASIHTTPRequest"), newMethod, class_getMethodImplementation([ASIHTTPRequestStub class], newMethod), types); +} + +- (void)fail { + [NSException raise:NSInternalInconsistencyException format:@"Couldn't load ASIHTTPRequest hook."]; +} + +@end diff --git a/WikipediaUnitTests/Third Party/Nocilla/Hooks/LSHTTPClientHook.h b/WikipediaUnitTests/Third Party/Nocilla/Hooks/LSHTTPClientHook.h new file mode 100644 index 00000000000..80ddc4c22ac --- /dev/null +++ b/WikipediaUnitTests/Third Party/Nocilla/Hooks/LSHTTPClientHook.h @@ -0,0 +1,6 @@ +#import + +@interface LSHTTPClientHook : NSObject +- (void)load; +- (void)unload; +@end diff --git a/WikipediaUnitTests/Third Party/Nocilla/Hooks/LSHTTPClientHook.m b/WikipediaUnitTests/Third Party/Nocilla/Hooks/LSHTTPClientHook.m new file mode 100644 index 00000000000..8256ca66e29 --- /dev/null +++ b/WikipediaUnitTests/Third Party/Nocilla/Hooks/LSHTTPClientHook.m @@ -0,0 +1,13 @@ +#import "LSHTTPClientHook.h" + +@implementation LSHTTPClientHook +- (void)load { + [NSException raise:NSInternalInconsistencyException + format:@"Method '%@' not implemented. Subclass '%@' and override it", NSStringFromSelector(_cmd), NSStringFromClass([self class])]; +} + +- (void)unload { + [NSException raise:NSInternalInconsistencyException + format:@"Method '%@' not implemented. Subclass '%@' and override it", NSStringFromSelector(_cmd), NSStringFromClass([self class])]; +} +@end diff --git a/WikipediaUnitTests/Third Party/Nocilla/Hooks/NSURLRequest/LSHTTPStubURLProtocol.h b/WikipediaUnitTests/Third Party/Nocilla/Hooks/NSURLRequest/LSHTTPStubURLProtocol.h new file mode 100644 index 00000000000..d5a9a1f0987 --- /dev/null +++ b/WikipediaUnitTests/Third Party/Nocilla/Hooks/NSURLRequest/LSHTTPStubURLProtocol.h @@ -0,0 +1,5 @@ +#import + +@interface LSHTTPStubURLProtocol : NSURLProtocol + +@end diff --git a/WikipediaUnitTests/Third Party/Nocilla/Hooks/NSURLRequest/LSHTTPStubURLProtocol.m b/WikipediaUnitTests/Third Party/Nocilla/Hooks/NSURLRequest/LSHTTPStubURLProtocol.m new file mode 100644 index 00000000000..06e925d78ef --- /dev/null +++ b/WikipediaUnitTests/Third Party/Nocilla/Hooks/NSURLRequest/LSHTTPStubURLProtocol.m @@ -0,0 +1,67 @@ +#import "LSHTTPStubURLProtocol.h" +#import "LSNocilla.h" +#import "NSURLRequest+LSHTTPRequest.h" +#import "LSStubRequest.h" +#import "NSURLRequest+DSL.h" + +@implementation LSHTTPStubURLProtocol + ++ (BOOL)canInitWithRequest:(NSURLRequest *)request { + return [@[ @"http", @"https" ] containsObject:request.URL.scheme]; +} + ++ (NSURLRequest *)canonicalRequestForRequest:(NSURLRequest *)request { + return request; +} ++ (BOOL)requestIsCacheEquivalent:(NSURLRequest *)a toRequest:(NSURLRequest *)b { + return NO; +} + +- (void)startLoading { + NSURLRequest* request = [self request]; + id client = [self client]; + + LSStubResponse* stubbedResponse = [[LSNocilla sharedInstance] responseForRequest:request]; + + NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage]; + [cookieStorage setCookies:[NSHTTPCookie cookiesWithResponseHeaderFields:stubbedResponse.headers forURL:request.url] + forURL:request.URL mainDocumentURL:request.URL]; + + if (stubbedResponse.shouldFail) { + [client URLProtocol:self didFailWithError:stubbedResponse.error]; + } else { + NSHTTPURLResponse* urlResponse = [[NSHTTPURLResponse alloc] initWithURL:request.URL + statusCode:stubbedResponse.statusCode + HTTPVersion:nil + headerFields:stubbedResponse.headers]; + + if (stubbedResponse.statusCode < 300 || stubbedResponse.statusCode > 399 + || stubbedResponse.statusCode == 304 || stubbedResponse.statusCode == 305 ) { + NSData *body = stubbedResponse.body; + + [client URLProtocol:self didReceiveResponse:urlResponse + cacheStoragePolicy:NSURLCacheStorageNotAllowed]; + [client URLProtocol:self didLoadData:body]; + [client URLProtocolDidFinishLoading:self]; + } else { + + NSURL *newURL = [NSURL URLWithString:[stubbedResponse.headers objectForKey:@"Location"] relativeToURL:request.URL]; + NSMutableURLRequest *redirectRequest = [NSMutableURLRequest requestWithURL:newURL]; + + [redirectRequest setAllHTTPHeaderFields:[NSHTTPCookie requestHeaderFieldsWithCookies:[cookieStorage cookiesForURL:newURL]]]; + + [client URLProtocol:self + wasRedirectedToRequest:redirectRequest + redirectResponse:urlResponse]; + // According to: https://developer.apple.com/library/ios/samplecode/CustomHTTPProtocol/Listings/CustomHTTPProtocol_Core_Code_CustomHTTPProtocol_m.html + // needs to abort the original request + [client URLProtocol:self didFailWithError:[NSError errorWithDomain:NSCocoaErrorDomain code:NSUserCancelledError userInfo:nil]]; + + } + } +} + +- (void)stopLoading { +} + +@end diff --git a/WikipediaUnitTests/Third Party/Nocilla/Hooks/NSURLRequest/LSNSURLHook.h b/WikipediaUnitTests/Third Party/Nocilla/Hooks/NSURLRequest/LSNSURLHook.h new file mode 100644 index 00000000000..abba2cbfd63 --- /dev/null +++ b/WikipediaUnitTests/Third Party/Nocilla/Hooks/NSURLRequest/LSNSURLHook.h @@ -0,0 +1,5 @@ +#import "LSHTTPClientHook.h" + +@interface LSNSURLHook : LSHTTPClientHook + +@end diff --git a/WikipediaUnitTests/Third Party/Nocilla/Hooks/NSURLRequest/LSNSURLHook.m b/WikipediaUnitTests/Third Party/Nocilla/Hooks/NSURLRequest/LSNSURLHook.m new file mode 100644 index 00000000000..77d70200295 --- /dev/null +++ b/WikipediaUnitTests/Third Party/Nocilla/Hooks/NSURLRequest/LSNSURLHook.m @@ -0,0 +1,14 @@ +#import "LSNSURLHook.h" +#import "LSHTTPStubURLProtocol.h" + +@implementation LSNSURLHook + +- (void)load { + [NSURLProtocol registerClass:[LSHTTPStubURLProtocol class]]; +} + +- (void)unload { + [NSURLProtocol unregisterClass:[LSHTTPStubURLProtocol class]]; +} + +@end diff --git a/WikipediaUnitTests/Third Party/Nocilla/Hooks/NSURLRequest/NSURLRequest+DSL.h b/WikipediaUnitTests/Third Party/Nocilla/Hooks/NSURLRequest/NSURLRequest+DSL.h new file mode 100644 index 00000000000..e13dbbd42b7 --- /dev/null +++ b/WikipediaUnitTests/Third Party/Nocilla/Hooks/NSURLRequest/NSURLRequest+DSL.h @@ -0,0 +1,5 @@ +#import + +@interface NSURLRequest (DSL) +- (NSString *)toNocillaDSL; +@end diff --git a/WikipediaUnitTests/Third Party/Nocilla/Hooks/NSURLRequest/NSURLRequest+DSL.m b/WikipediaUnitTests/Third Party/Nocilla/Hooks/NSURLRequest/NSURLRequest+DSL.m new file mode 100644 index 00000000000..73e249b1433 --- /dev/null +++ b/WikipediaUnitTests/Third Party/Nocilla/Hooks/NSURLRequest/NSURLRequest+DSL.m @@ -0,0 +1,9 @@ +#import "NSURLRequest+DSL.h" +#import "LSHTTPRequestDSLRepresentation.h" +#import "NSURLRequest+LSHTTPRequest.h" + +@implementation NSURLRequest (DSL) +- (NSString *)toNocillaDSL { + return [[[LSHTTPRequestDSLRepresentation alloc] initWithRequest:self] description]; +} +@end diff --git a/WikipediaUnitTests/Third Party/Nocilla/Hooks/NSURLRequest/NSURLRequest+LSHTTPRequest.h b/WikipediaUnitTests/Third Party/Nocilla/Hooks/NSURLRequest/NSURLRequest+LSHTTPRequest.h new file mode 100644 index 00000000000..0ac96b2d81e --- /dev/null +++ b/WikipediaUnitTests/Third Party/Nocilla/Hooks/NSURLRequest/NSURLRequest+LSHTTPRequest.h @@ -0,0 +1,6 @@ +#import +#import "LSHTTPRequest.h" + +@interface NSURLRequest (LSHTTPRequest) + +@end diff --git a/WikipediaUnitTests/Third Party/Nocilla/Hooks/NSURLRequest/NSURLRequest+LSHTTPRequest.m b/WikipediaUnitTests/Third Party/Nocilla/Hooks/NSURLRequest/NSURLRequest+LSHTTPRequest.m new file mode 100644 index 00000000000..a6c3007676c --- /dev/null +++ b/WikipediaUnitTests/Third Party/Nocilla/Hooks/NSURLRequest/NSURLRequest+LSHTTPRequest.m @@ -0,0 +1,47 @@ +#import "NSURLRequest+LSHTTPRequest.h" + +@implementation NSURLRequest (LSHTTPRequest) + +- (NSURL*)url { + return self.URL; +} + +- (NSString *)method { + return self.HTTPMethod; +} + +- (NSDictionary *)headers { + return self.allHTTPHeaderFields; +} + +- (NSData *)body { + if (self.HTTPBodyStream) { + NSInputStream *stream = self.HTTPBodyStream; + NSMutableData *data = [NSMutableData data]; + [stream open]; + size_t bufferSize = 4096; + uint8_t *buffer = malloc(bufferSize); + if (buffer == NULL) { + [NSException raise:@"NocillaMallocFailure" format:@"Could not allocate %zu bytes to read HTTPBodyStream", bufferSize]; + } + while ([stream hasBytesAvailable]) { + NSInteger bytesRead = [stream read:buffer maxLength:bufferSize]; + if (bytesRead > 0) { + NSData *readData = [NSData dataWithBytes:buffer length:bytesRead]; + [data appendData:readData]; + } else if (bytesRead < 0) { + [NSException raise:@"NocillaStreamReadError" format:@"An error occurred while reading HTTPBodyStream (%ld)", (long)bytesRead]; + } else if (bytesRead == 0) { + break; + } + } + free(buffer); + [stream close]; + + return data; + } + + return self.HTTPBody; +} + +@end diff --git a/WikipediaUnitTests/Third Party/Nocilla/Hooks/NSURLSession/LSNSURLSessionHook.h b/WikipediaUnitTests/Third Party/Nocilla/Hooks/NSURLSession/LSNSURLSessionHook.h new file mode 100644 index 00000000000..e6f35511d21 --- /dev/null +++ b/WikipediaUnitTests/Third Party/Nocilla/Hooks/NSURLSession/LSNSURLSessionHook.h @@ -0,0 +1,15 @@ +// +// LSNSURLSessionHook.h +// Nocilla +// +// Created by Luis Solano Bonet on 08/01/14. +// Copyright (c) 2014 Luis Solano Bonet. All rights reserved. +// + +#import "Nocilla.h" + +#import "LSHTTPClientHook.h" + +@interface LSNSURLSessionHook : LSHTTPClientHook + +@end diff --git a/WikipediaUnitTests/Third Party/Nocilla/Hooks/NSURLSession/LSNSURLSessionHook.m b/WikipediaUnitTests/Third Party/Nocilla/Hooks/NSURLSession/LSNSURLSessionHook.m new file mode 100644 index 00000000000..ab584f59ba8 --- /dev/null +++ b/WikipediaUnitTests/Third Party/Nocilla/Hooks/NSURLSession/LSNSURLSessionHook.m @@ -0,0 +1,40 @@ +// +// LSNSURLSessionHook.m +// Nocilla +// +// Created by Luis Solano Bonet on 08/01/14. +// Copyright (c) 2014 Luis Solano Bonet. All rights reserved. +// + +#import "LSNSURLSessionHook.h" +#import "LSHTTPStubURLProtocol.h" +#import + +@implementation LSNSURLSessionHook + +- (void)load { + Class cls = NSClassFromString(@"__NSCFURLSessionConfiguration") ?: NSClassFromString(@"NSURLSessionConfiguration"); + [self swizzleSelector:@selector(protocolClasses) fromClass:cls toClass:[self class]]; +} + +- (void)unload { + Class cls = NSClassFromString(@"__NSCFURLSessionConfiguration") ?: NSClassFromString(@"NSURLSessionConfiguration"); + [self swizzleSelector:@selector(protocolClasses) fromClass:cls toClass:[self class]]; +} + +- (void)swizzleSelector:(SEL)selector fromClass:(Class)original toClass:(Class)stub { + + Method originalMethod = class_getInstanceMethod(original, selector); + Method stubMethod = class_getInstanceMethod(stub, selector); + if (!originalMethod || !stubMethod) { + [NSException raise:NSInternalInconsistencyException format:@"Couldn't load NSURLSession hook."]; + } + method_exchangeImplementations(originalMethod, stubMethod); +} + +- (NSArray *)protocolClasses { + return @[[LSHTTPStubURLProtocol class]]; +} + + +@end diff --git a/WikipediaUnitTests/Third Party/Nocilla/LSNocilla.h b/WikipediaUnitTests/Third Party/Nocilla/LSNocilla.h new file mode 100644 index 00000000000..aa85901e972 --- /dev/null +++ b/WikipediaUnitTests/Third Party/Nocilla/LSNocilla.h @@ -0,0 +1,25 @@ +#import +#import "Nocilla.h" + +@class LSStubRequest; +@class LSStubResponse; +@class LSHTTPClientHook; +@protocol LSHTTPRequest; + +extern NSString * const LSUnexpectedRequest; + +@interface LSNocilla : NSObject ++ (LSNocilla *)sharedInstance; + +@property (nonatomic, strong, readonly) NSArray *stubbedRequests; +@property (nonatomic, assign, readonly, getter = isStarted) BOOL started; + +- (void)start; +- (void)stop; +- (void)addStubbedRequest:(LSStubRequest *)request; +- (void)clearStubs; + +- (void)registerHook:(LSHTTPClientHook *)hook; + +- (LSStubResponse *)responseForRequest:(id)request; +@end diff --git a/WikipediaUnitTests/Third Party/Nocilla/LSNocilla.m b/WikipediaUnitTests/Third Party/Nocilla/LSNocilla.m new file mode 100644 index 00000000000..c3e3fb3141c --- /dev/null +++ b/WikipediaUnitTests/Third Party/Nocilla/LSNocilla.m @@ -0,0 +1,118 @@ +#import "LSNocilla.h" +#import "LSNSURLHook.h" +#import "LSStubRequest.h" +#import "LSHTTPRequestDSLRepresentation.h" +#import "LSASIHTTPRequestHook.h" +#import "LSNSURLSessionHook.h" +#import "LSASIHTTPRequestHook.h" + +NSString * const LSUnexpectedRequest = @"Unexpected Request"; + +@interface LSNocilla () +@property (nonatomic, strong) NSMutableArray *mutableRequests; +@property (nonatomic, strong) NSMutableArray *hooks; +@property (nonatomic, assign, getter = isStarted) BOOL started; + +- (void)loadHooks; +- (void)unloadHooks; +@end + +static LSNocilla *sharedInstace = nil; + +@implementation LSNocilla + ++ (LSNocilla *)sharedInstance { + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + sharedInstace = [[self alloc] init]; + }); + return sharedInstace; +} + +- (id)init { + self = [super init]; + if (self) { + _mutableRequests = [NSMutableArray array]; + _hooks = [NSMutableArray array]; + [self registerHook:[[LSNSURLHook alloc] init]]; + if (NSClassFromString(@"NSURLSession") != nil) { + [self registerHook:[[LSNSURLSessionHook alloc] init]]; + } + [self registerHook:[[LSASIHTTPRequestHook alloc] init]]; + } + return self; +} + +- (NSArray *)stubbedRequests { + return [NSArray arrayWithArray:self.mutableRequests]; +} + +- (void)start { + if (!self.isStarted){ + [self loadHooks]; + self.started = YES; + } +} + +- (void)stop { + [self unloadHooks]; + [self clearStubs]; + self.started = NO; +} + +- (void)addStubbedRequest:(LSStubRequest *)request { + NSUInteger index = [self.mutableRequests indexOfObject:request]; + + if (index == NSNotFound) { + [self.mutableRequests addObject:request]; + return; + } + + [self.mutableRequests replaceObjectAtIndex:index withObject:request]; +} + +- (void)clearStubs { + [self.mutableRequests removeAllObjects]; +} + +- (LSStubResponse *)responseForRequest:(id)actualRequest { + NSArray* requests = [LSNocilla sharedInstance].stubbedRequests; + + for(LSStubRequest *someStubbedRequest in requests) { + if ([someStubbedRequest matchesRequest:actualRequest]) { + return someStubbedRequest.response; + } + } + [NSException raise:@"NocillaUnexpectedRequest" format:@"An unexpected HTTP request was fired.\n\nUse this snippet to stub the request:\n%@\n", [[[LSHTTPRequestDSLRepresentation alloc] initWithRequest:actualRequest] description]]; + + return nil; +} + +- (void)registerHook:(LSHTTPClientHook *)hook { + if (![self hookWasRegistered:hook]) { + [[self hooks] addObject:hook]; + } +} + +- (BOOL)hookWasRegistered:(LSHTTPClientHook *)aHook { + for (LSHTTPClientHook *hook in self.hooks) { + if ([hook isMemberOfClass: [aHook class]]) { + return YES; + } + } + return NO; +} +#pragma mark - Private +- (void)loadHooks { + for (LSHTTPClientHook *hook in self.hooks) { + [hook load]; + } +} + +- (void)unloadHooks { + for (LSHTTPClientHook *hook in self.hooks) { + [hook unload]; + } +} + +@end diff --git a/WikipediaUnitTests/Third Party/Nocilla/Matchers/LSDataMatcher.h b/WikipediaUnitTests/Third Party/Nocilla/Matchers/LSDataMatcher.h new file mode 100644 index 00000000000..f935da5b89d --- /dev/null +++ b/WikipediaUnitTests/Third Party/Nocilla/Matchers/LSDataMatcher.h @@ -0,0 +1,16 @@ +// +// LSDataMatcher.h +// Nocilla +// +// Created by Luis Solano Bonet on 09/11/14. +// Copyright (c) 2014 Luis Solano Bonet. All rights reserved. +// + +#import +#import "LSMatcher.h" + +@interface LSDataMatcher : LSMatcher + +- (instancetype)initWithData:(NSData *)data; + +@end diff --git a/WikipediaUnitTests/Third Party/Nocilla/Matchers/LSDataMatcher.m b/WikipediaUnitTests/Third Party/Nocilla/Matchers/LSDataMatcher.m new file mode 100644 index 00000000000..ed8c8d3746e --- /dev/null +++ b/WikipediaUnitTests/Third Party/Nocilla/Matchers/LSDataMatcher.m @@ -0,0 +1,51 @@ +// +// LSDataMatcher.m +// Nocilla +// +// Created by Luis Solano Bonet on 09/11/14. +// Copyright (c) 2014 Luis Solano Bonet. All rights reserved. +// + +#import "LSDataMatcher.h" + +@interface LSDataMatcher () + +@property (nonatomic, copy) NSData *data; + +@end + +@implementation LSDataMatcher + +- (instancetype)initWithData:(NSData *)data { + self = [super init]; + + if (self) { + _data = data; + } + return self; +} + +- (BOOL)matchesData:(NSData *)data { + return [self.data isEqualToData:data]; +} + + +#pragma mark - Equality + +- (BOOL)isEqual:(id)object { + if (self == object) { + return YES; + } + + if (![object isKindOfClass:[LSDataMatcher class]]) { + return NO; + } + + return [self.data isEqual:((LSDataMatcher *)object).data]; +} + +- (NSUInteger)hash { + return self.data.hash; +} + +@end diff --git a/WikipediaUnitTests/Third Party/Nocilla/Matchers/LSMatcheable.h b/WikipediaUnitTests/Third Party/Nocilla/Matchers/LSMatcheable.h new file mode 100644 index 00000000000..db14c6cb94e --- /dev/null +++ b/WikipediaUnitTests/Third Party/Nocilla/Matchers/LSMatcheable.h @@ -0,0 +1,9 @@ +#import + +@class LSMatcher; + +@protocol LSMatcheable + +- (LSMatcher *)matcher; + +@end diff --git a/WikipediaUnitTests/Third Party/Nocilla/Matchers/LSMatcher.h b/WikipediaUnitTests/Third Party/Nocilla/Matchers/LSMatcher.h new file mode 100644 index 00000000000..bea8305f316 --- /dev/null +++ b/WikipediaUnitTests/Third Party/Nocilla/Matchers/LSMatcher.h @@ -0,0 +1,9 @@ +#import + +@interface LSMatcher : NSObject + +- (BOOL)matches:(NSString *)string; + +- (BOOL)matchesData:(NSData *)data; + +@end diff --git a/WikipediaUnitTests/Third Party/Nocilla/Matchers/LSMatcher.m b/WikipediaUnitTests/Third Party/Nocilla/Matchers/LSMatcher.m new file mode 100644 index 00000000000..30dddde7cca --- /dev/null +++ b/WikipediaUnitTests/Third Party/Nocilla/Matchers/LSMatcher.m @@ -0,0 +1,24 @@ +#import "LSMatcher.h" + +@implementation LSMatcher + +- (BOOL)matches:(NSString *)string { + @throw [NSException exceptionWithName:NSInternalInconsistencyException reason:@"[LSMatcher matches:] is an abstract method" userInfo:nil]; +} + +- (BOOL)matchesData:(NSData *)data { + return [self matches:[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]]; +} + + +#pragma mark - Equality + +- (BOOL)isEqual:(id)object { + @throw [NSException exceptionWithName:NSInternalInconsistencyException reason:@"[LSMatcher isEqual:] is an abstract method" userInfo:nil]; +} + +- (NSUInteger)hash { + @throw [NSException exceptionWithName:NSInternalInconsistencyException reason:@"[LSMatcher hash] an abstract method" userInfo:nil]; +} + +@end diff --git a/WikipediaUnitTests/Third Party/Nocilla/Matchers/LSRegexMatcher.h b/WikipediaUnitTests/Third Party/Nocilla/Matchers/LSRegexMatcher.h new file mode 100644 index 00000000000..7111c8728fb --- /dev/null +++ b/WikipediaUnitTests/Third Party/Nocilla/Matchers/LSRegexMatcher.h @@ -0,0 +1,7 @@ +#import "LSMatcher.h" + +@interface LSRegexMatcher : LSMatcher + +- (instancetype)initWithRegex:(NSRegularExpression *)regex; + +@end diff --git a/WikipediaUnitTests/Third Party/Nocilla/Matchers/LSRegexMatcher.m b/WikipediaUnitTests/Third Party/Nocilla/Matchers/LSRegexMatcher.m new file mode 100644 index 00000000000..b59b3c8d428 --- /dev/null +++ b/WikipediaUnitTests/Third Party/Nocilla/Matchers/LSRegexMatcher.m @@ -0,0 +1,40 @@ +#import "LSRegexMatcher.h" + +@interface LSRegexMatcher () +@property (nonatomic, strong) NSRegularExpression *regex; +@end + +@implementation LSRegexMatcher + +- (instancetype)initWithRegex:(NSRegularExpression *)regex { + self = [super init]; + if (self) { + _regex = regex; + } + return self; +} + +- (BOOL)matches:(NSString *)string { + return [self.regex numberOfMatchesInString:string options:0 range:NSMakeRange(0, string.length)] > 0; +} + + +#pragma mark - Equality + +- (BOOL)isEqual:(id)object { + if (self == object) { + return YES; + } + + if (![object isKindOfClass:[LSRegexMatcher class]]) { + return NO; + } + + return [self.regex isEqual:((LSRegexMatcher *)object).regex]; +} + +- (NSUInteger)hash { + return self.regex.hash; +} + +@end diff --git a/WikipediaUnitTests/Third Party/Nocilla/Matchers/LSStringMatcher.h b/WikipediaUnitTests/Third Party/Nocilla/Matchers/LSStringMatcher.h new file mode 100644 index 00000000000..56af212624e --- /dev/null +++ b/WikipediaUnitTests/Third Party/Nocilla/Matchers/LSStringMatcher.h @@ -0,0 +1,8 @@ +#import +#import "LSMatcher.h" + +@interface LSStringMatcher : LSMatcher + +- (instancetype)initWithString:(NSString *)string; + +@end diff --git a/WikipediaUnitTests/Third Party/Nocilla/Matchers/LSStringMatcher.m b/WikipediaUnitTests/Third Party/Nocilla/Matchers/LSStringMatcher.m new file mode 100644 index 00000000000..8f90526aced --- /dev/null +++ b/WikipediaUnitTests/Third Party/Nocilla/Matchers/LSStringMatcher.m @@ -0,0 +1,42 @@ +#import "LSStringMatcher.h" + +@interface LSStringMatcher () + +@property (nonatomic, copy) NSString *string; + +@end + +@implementation LSStringMatcher + +- (instancetype)initWithString:(NSString *)string { + self = [super init]; + if (self) { + _string = string; + } + return self; +} + +- (BOOL)matches:(NSString *)string { + return [self.string isEqualToString:string]; +} + + +#pragma mark - Equality + +- (BOOL)isEqual:(id)object { + if (self == object) { + return YES; + } + + if (![object isKindOfClass:[LSStringMatcher class]]) { + return NO; + } + + return [self.string isEqualToString:((LSStringMatcher *)object).string]; +} + +- (NSUInteger)hash { + return self.string.hash; +} + +@end diff --git a/WikipediaUnitTests/Third Party/Nocilla/Matchers/NSData+Matcheable.h b/WikipediaUnitTests/Third Party/Nocilla/Matchers/NSData+Matcheable.h new file mode 100644 index 00000000000..c3dfef9444e --- /dev/null +++ b/WikipediaUnitTests/Third Party/Nocilla/Matchers/NSData+Matcheable.h @@ -0,0 +1,14 @@ +// +// NSData+Matcheable.h +// Nocilla +// +// Created by Luis Solano Bonet on 09/11/14. +// Copyright (c) 2014 Luis Solano Bonet. All rights reserved. +// + +#import +#import "LSMatcheable.h" + +@interface NSData (Matcheable) + +@end diff --git a/WikipediaUnitTests/Third Party/Nocilla/Matchers/NSData+Matcheable.m b/WikipediaUnitTests/Third Party/Nocilla/Matchers/NSData+Matcheable.m new file mode 100644 index 00000000000..ab454bc0de5 --- /dev/null +++ b/WikipediaUnitTests/Third Party/Nocilla/Matchers/NSData+Matcheable.m @@ -0,0 +1,18 @@ +// +// NSData+Matcheable.m +// Nocilla +// +// Created by Luis Solano Bonet on 09/11/14. +// Copyright (c) 2014 Luis Solano Bonet. All rights reserved. +// + +#import "NSData+Matcheable.h" +#import "LSDataMatcher.h" + +@implementation NSData (Matcheable) + +- (LSMatcher *)matcher { + return [[LSDataMatcher alloc] initWithData:self]; +} + +@end diff --git a/WikipediaUnitTests/Third Party/Nocilla/Matchers/NSRegularExpression+Matcheable.h b/WikipediaUnitTests/Third Party/Nocilla/Matchers/NSRegularExpression+Matcheable.h new file mode 100644 index 00000000000..9d9717f896c --- /dev/null +++ b/WikipediaUnitTests/Third Party/Nocilla/Matchers/NSRegularExpression+Matcheable.h @@ -0,0 +1,6 @@ +#import +#import "LSMatcheable.h" + +@interface NSRegularExpression (Matcheable) + +@end diff --git a/WikipediaUnitTests/Third Party/Nocilla/Matchers/NSRegularExpression+Matcheable.m b/WikipediaUnitTests/Third Party/Nocilla/Matchers/NSRegularExpression+Matcheable.m new file mode 100644 index 00000000000..39792c51c2b --- /dev/null +++ b/WikipediaUnitTests/Third Party/Nocilla/Matchers/NSRegularExpression+Matcheable.m @@ -0,0 +1,10 @@ +#import "NSRegularExpression+Matcheable.h" +#import "LSRegexMatcher.h" + +@implementation NSRegularExpression (Matcheable) + +- (LSMatcher *)matcher { + return [[LSRegexMatcher alloc] initWithRegex:self]; +} + +@end diff --git a/WikipediaUnitTests/Third Party/Nocilla/Matchers/NSString+Matcheable.h b/WikipediaUnitTests/Third Party/Nocilla/Matchers/NSString+Matcheable.h new file mode 100644 index 00000000000..ca63ec73732 --- /dev/null +++ b/WikipediaUnitTests/Third Party/Nocilla/Matchers/NSString+Matcheable.h @@ -0,0 +1,6 @@ +#import +#import "LSMatcheable.h" + +@interface NSString (Matcheable) + +@end diff --git a/WikipediaUnitTests/Third Party/Nocilla/Matchers/NSString+Matcheable.m b/WikipediaUnitTests/Third Party/Nocilla/Matchers/NSString+Matcheable.m new file mode 100644 index 00000000000..67809e0afbc --- /dev/null +++ b/WikipediaUnitTests/Third Party/Nocilla/Matchers/NSString+Matcheable.m @@ -0,0 +1,10 @@ +#import "NSString+Matcheable.h" +#import "LSStringMatcher.h" + +@implementation NSString (Matcheable) + +- (LSMatcher *)matcher { + return [[LSStringMatcher alloc] initWithString:self]; +} + +@end diff --git a/WikipediaUnitTests/Third Party/Nocilla/Model/LSHTTPBody.h b/WikipediaUnitTests/Third Party/Nocilla/Model/LSHTTPBody.h new file mode 100644 index 00000000000..8c26687f5a6 --- /dev/null +++ b/WikipediaUnitTests/Third Party/Nocilla/Model/LSHTTPBody.h @@ -0,0 +1,5 @@ +#import + +@protocol LSHTTPBody +- (NSData *)data; +@end diff --git a/WikipediaUnitTests/Third Party/Nocilla/Model/LSHTTPRequest.h b/WikipediaUnitTests/Third Party/Nocilla/Model/LSHTTPRequest.h new file mode 100644 index 00000000000..f0e796614d2 --- /dev/null +++ b/WikipediaUnitTests/Third Party/Nocilla/Model/LSHTTPRequest.h @@ -0,0 +1,10 @@ +#import + +@protocol LSHTTPRequest + +@property (nonatomic, strong, readonly) NSURL *url; +@property (nonatomic, strong, readonly) NSString *method; +@property (nonatomic, strong, readonly) NSDictionary *headers; +@property (nonatomic, strong, readonly) NSData *body; + +@end diff --git a/WikipediaUnitTests/Third Party/Nocilla/Model/LSHTTPResponse.h b/WikipediaUnitTests/Third Party/Nocilla/Model/LSHTTPResponse.h new file mode 100644 index 00000000000..db643b70a63 --- /dev/null +++ b/WikipediaUnitTests/Third Party/Nocilla/Model/LSHTTPResponse.h @@ -0,0 +1,7 @@ +#import + +@protocol LSHTTPResponse +@property (nonatomic, assign, readonly) NSInteger statusCode; +@property (nonatomic, strong, readonly) NSDictionary *headers; +@property (nonatomic, strong, readonly) NSData *body; +@end diff --git a/WikipediaUnitTests/Third Party/Nocilla/Nocilla-Prefix.pch b/WikipediaUnitTests/Third Party/Nocilla/Nocilla-Prefix.pch new file mode 100644 index 00000000000..8f4dd673052 --- /dev/null +++ b/WikipediaUnitTests/Third Party/Nocilla/Nocilla-Prefix.pch @@ -0,0 +1,7 @@ +// +// Prefix header for all source files of the 'Nocilla' target in the 'Nocilla' project +// + +#ifdef __OBJC__ + #import +#endif diff --git a/WikipediaUnitTests/Third Party/Nocilla/Nocilla.h b/WikipediaUnitTests/Third Party/Nocilla/Nocilla.h new file mode 100644 index 00000000000..7444ce3bf1c --- /dev/null +++ b/WikipediaUnitTests/Third Party/Nocilla/Nocilla.h @@ -0,0 +1,27 @@ +// +// Nocilla.h +// Nocilla +// +// Created by Robert Böhnke on 26/03/15. +// Copyright (c) 2015 Luis Solano Bonet. All rights reserved. +// + +#import + +//! Project version number for Nocilla. +FOUNDATION_EXPORT double NocillaVersionNumber; + +//! Project version string for Nocilla. +FOUNDATION_EXPORT const unsigned char NocillaVersionString[]; + +#import "LSHTTPBody.h" +#import "LSMatcheable.h" +#import "LSMatcher.h" +#import "LSNocilla.h" +#import "LSStubRequestDSL.h" +#import "LSStubResponseDSL.h" +#import "NSData+Matcheable.h" +#import "NSData+Nocilla.h" +#import "NSRegularExpression+Matcheable.h" +#import "NSString+Matcheable.h" +#import "NSString+Nocilla.h" diff --git a/WikipediaUnitTests/Third Party/Nocilla/Stubs/LSStubRequest.h b/WikipediaUnitTests/Third Party/Nocilla/Stubs/LSStubRequest.h new file mode 100644 index 00000000000..4a2cfe3fc98 --- /dev/null +++ b/WikipediaUnitTests/Third Party/Nocilla/Stubs/LSStubRequest.h @@ -0,0 +1,24 @@ +#import +#import "LSStubResponse.h" +#import "LSHTTPRequest.h" + + +@class LSMatcher; +@class LSStubRequest; +@class LSStubResponse; + +@interface LSStubRequest : NSObject +@property (nonatomic, strong, readonly) NSString *method; +@property (nonatomic, strong, readonly) LSMatcher *urlMatcher; +@property (nonatomic, strong, readonly) NSDictionary *headers; +@property (nonatomic, strong, readwrite) LSMatcher *body; + +@property (nonatomic, strong) LSStubResponse *response; + +- (instancetype)initWithMethod:(NSString *)method url:(NSString *)url; +- (instancetype)initWithMethod:(NSString *)method urlMatcher:(LSMatcher *)urlMatcher; + +- (void)setHeader:(NSString *)header value:(NSString *)value; + +- (BOOL)matchesRequest:(id)request; +@end diff --git a/WikipediaUnitTests/Third Party/Nocilla/Stubs/LSStubRequest.m b/WikipediaUnitTests/Third Party/Nocilla/Stubs/LSStubRequest.m new file mode 100644 index 00000000000..1c29769f4e2 --- /dev/null +++ b/WikipediaUnitTests/Third Party/Nocilla/Stubs/LSStubRequest.m @@ -0,0 +1,130 @@ +#import "LSStubRequest.h" +#import "LSMatcher.h" +#import "NSString+Matcheable.h" + +@interface LSStubRequest () +@property (nonatomic, strong, readwrite) NSString *method; +@property (nonatomic, strong, readwrite) LSMatcher *urlMatcher; +@property (nonatomic, strong, readwrite) NSMutableDictionary *mutableHeaders; + +-(BOOL)matchesMethod:(id)request; +-(BOOL)matchesURL:(id)request; +-(BOOL)matchesHeaders:(id)request; +-(BOOL)matchesBody:(id)request; +@end + +@implementation LSStubRequest + +- (instancetype)initWithMethod:(NSString *)method url:(NSString *)url { + return [self initWithMethod:method urlMatcher:[url matcher]]; +} + +- (instancetype)initWithMethod:(NSString *)method urlMatcher:(LSMatcher *)urlMatcher; { + self = [super init]; + if (self) { + self.method = method; + self.urlMatcher = urlMatcher; + self.mutableHeaders = [NSMutableDictionary dictionary]; + } + return self; +} + +- (void)setHeader:(NSString *)header value:(NSString *)value { + [self.mutableHeaders setValue:value forKey:header]; +} + +- (NSDictionary *)headers { + return [NSDictionary dictionaryWithDictionary:self.mutableHeaders];; +} + +- (NSString *)description { + return [NSString stringWithFormat:@"StubRequest:\nMethod: %@\nURL: %@\nHeaders: %@\nBody: %@\nResponse: %@", + self.method, + self.urlMatcher, + self.headers, + self.body, + self.response]; +} + +- (LSStubResponse *)response { + if (!_response) { + _response = [[LSStubResponse alloc] initDefaultResponse]; + } + return _response; + +} + +- (BOOL)matchesRequest:(id)request { + if ([self matchesMethod:request] + && [self matchesURL:request] + && [self matchesHeaders:request] + && [self matchesBody:request] + ) { + return YES; + } + return NO; +} + +-(BOOL)matchesMethod:(id)request { + if (!self.method || [self.method isEqualToString:request.method]) { + return YES; + } + return NO; +} + +-(BOOL)matchesURL:(id)request { + return [self.urlMatcher matches:[request.url absoluteString]]; +} + +-(BOOL)matchesHeaders:(id)request { + for (NSString *header in self.headers) { + if (![[request.headers objectForKey:header] isEqualToString:[self.headers objectForKey:header]]) { + return NO; + } + } + return YES; +} + +-(BOOL)matchesBody:(id)request { + NSData *reqBody = request.body; + if (!self.body || [self.body matchesData:reqBody]) { + return YES; + } + return NO; +} + + +#pragma mark - Equality + +- (BOOL)isEqual:(id)object { + if (self == object) { + return YES; + } + + if (![object isKindOfClass:[LSStubRequest class]]) { + return NO; + } + + return [self isEqualToStubRequest:object]; +} + +- (BOOL)isEqualToStubRequest:(LSStubRequest *)stubRequest { + if (!stubRequest) { + return NO; + } + + BOOL methodEqual = [self.method isEqualToString:stubRequest.method]; + BOOL urlMatcherEqual = [self.urlMatcher isEqual:stubRequest.urlMatcher]; + BOOL headersEqual = [self.headers isEqual:stubRequest.headers]; + BOOL bodyEqual = (self.body == nil && stubRequest.body == nil) || [self.body isEqual:stubRequest.body]; + + return methodEqual && urlMatcherEqual && headersEqual && bodyEqual; +} + +- (NSUInteger)hash { + return self.method.hash ^ self.urlMatcher.hash ^ self.headers.hash ^ self.body.hash; +} + +@end + + diff --git a/WikipediaUnitTests/Third Party/Nocilla/Stubs/LSStubResponse.h b/WikipediaUnitTests/Third Party/Nocilla/Stubs/LSStubResponse.h new file mode 100644 index 00000000000..d0461db836d --- /dev/null +++ b/WikipediaUnitTests/Third Party/Nocilla/Stubs/LSStubResponse.h @@ -0,0 +1,18 @@ +#import +#import "LSHTTPResponse.h" + +@interface LSStubResponse : NSObject + +@property (nonatomic, assign, readonly) NSInteger statusCode; +@property (nonatomic, strong) NSData *body; +@property (nonatomic, strong, readonly) NSDictionary *headers; + +@property (nonatomic, assign, readonly) BOOL shouldFail; +@property (nonatomic, strong, readonly) NSError *error; + +- (id)initWithError:(NSError *)error; +- (id)initWithStatusCode:(NSInteger)statusCode; +- (id)initWithRawResponse:(NSData *)rawResponseData; +- (id)initDefaultResponse; +- (void)setHeader:(NSString *)header value:(NSString *)value; +@end diff --git a/WikipediaUnitTests/Third Party/Nocilla/Stubs/LSStubResponse.m b/WikipediaUnitTests/Third Party/Nocilla/Stubs/LSStubResponse.m new file mode 100644 index 00000000000..06f67c75868 --- /dev/null +++ b/WikipediaUnitTests/Third Party/Nocilla/Stubs/LSStubResponse.m @@ -0,0 +1,81 @@ +#import "LSStubResponse.h" + +@interface LSStubResponse () +@property (nonatomic, assign, readwrite) NSInteger statusCode; +@property (nonatomic, strong) NSMutableDictionary *mutableHeaders; +@property (nonatomic, assign) UInt64 offset; +@property (nonatomic, assign, getter = isDone) BOOL done; +@property (nonatomic, assign) BOOL shouldFail; +@property (nonatomic, strong) NSError *error; +@end + +@implementation LSStubResponse + +#pragma Initializers +- (id)initDefaultResponse { + self = [super init]; + if (self) { + self.shouldFail = NO; + + self.statusCode = 200; + self.mutableHeaders = [NSMutableDictionary dictionary]; + self.body = [@"" dataUsingEncoding:NSUTF8StringEncoding]; + } + return self; +} + + +- (id)initWithError:(NSError *)error { + self = [super init]; + if (self) { + self.shouldFail = YES; + self.error = error; + } + return self; +} + +-(id)initWithStatusCode:(NSInteger)statusCode { + self = [super init]; + if (self) { + self.shouldFail = NO; + self.statusCode = statusCode; + self.mutableHeaders = [NSMutableDictionary dictionary]; + self.body = [@"" dataUsingEncoding:NSUTF8StringEncoding]; + } + return self; +} + +- (id)initWithRawResponse:(NSData *)rawResponseData { + self = [self initDefaultResponse]; + if (self) { + CFHTTPMessageRef httpMessage = CFHTTPMessageCreateEmpty(kCFAllocatorDefault, FALSE); + if (httpMessage) { + CFHTTPMessageAppendBytes(httpMessage, [rawResponseData bytes], [rawResponseData length]); + + self.body = rawResponseData; // By default + + if (CFHTTPMessageIsHeaderComplete(httpMessage)) { + self.statusCode = (NSInteger)CFHTTPMessageGetResponseStatusCode(httpMessage); + self.mutableHeaders = [NSMutableDictionary dictionaryWithDictionary:(__bridge_transfer NSDictionary *)CFHTTPMessageCopyAllHeaderFields(httpMessage)]; + self.body = (__bridge_transfer NSData *)CFHTTPMessageCopyBody(httpMessage); + } + CFRelease(httpMessage); + } + } + return self; +} + +- (void)setHeader:(NSString *)header value:(NSString *)value { + [self.mutableHeaders setValue:value forKey:header]; +} +- (NSDictionary *)headers { + return [NSDictionary dictionaryWithDictionary:self.mutableHeaders]; +} + +- (NSString *)description { + return [NSString stringWithFormat:@"StubRequest:\nStatus Code: %ld\nHeaders: %@\nBody: %@", + (long)self.statusCode, + self.mutableHeaders, + self.body]; +} +@end