77#import < objc/runtime.h>
88
99#import " SPTDataLoaderRequest+Private.h"
10- #import " NSBundleMock .h"
10+ #import " NSLocaleMock .h"
1111
1212@interface SPTDataLoaderRequest ()
1313
@@ -140,24 +140,24 @@ - (void)testCopy
140140 XCTAssertEqual (request.shouldStopRedirection , self.request .shouldStopRedirection , @" The stop redirection was not copied correctly" );
141141}
142142
143- - (void )testAcceptLanguageWithNoEnglishLanguages
143+ - (void )testAcceptLanguage
144144{
145- NSBundleMock *bundleMock = [NSBundleMock new ];
146- bundleMock.mockPreferredLocalizations = @[ @" fr-CA" , @" pt-PT" , @" es-419" ];
145+ // When the language identifier does not contain a region designator, NSLocale uses the user's preferred region.
146+ [NSLocaleMock setPreferredLanguages: @[ @" en-US" , @" fr-SE" , @" ja-SE" , @" sv-SE" , @" mk-SE" , @" nl-SE" ]];
147+
148+ Method originalMethod = class_getClassMethod (NSLocale .class , @selector (preferredLanguages ));
149+ Method fakeMethod = class_getClassMethod (NSLocaleMock.class , @selector (preferredLanguages ));
147150
148- Method originalMethod = class_getClassMethod (NSBundle .class , @selector (mainBundle ));
149151 IMP originalMethodImplementation = method_getImplementation (originalMethod);
152+ IMP fakeMethodImplementation = method_getImplementation (fakeMethod);
150153
151- IMP fakeMethodImplementation = imp_implementationWithBlock (^ {
152- return bundleMock;
153- });
154154 method_setImplementation (originalMethod, fakeMethodImplementation);
155155
156156 NSString *languageValues = [SPTDataLoaderRequest generateLanguageHeaderValue ];
157157
158158 method_setImplementation (originalMethod, originalMethodImplementation);
159159
160- XCTAssertEqualObjects (@" fr-CA, pt-PT ;q=0.50, en ;q=0.01 " , languageValues);
160+ XCTAssertEqualObjects (@" en-US;q=1.00, fr-SE;q=0.83, ja-SE ;q=0.67, sv-SE;q=0. 50, mk-SE ;q=0.33, nl-SE;q=0.17 " , languageValues);
161161}
162162
163163- (void )testDescription
@@ -170,46 +170,6 @@ - (void)testDescription
170170 @" The description should contain the URL of the request." );
171171}
172172
173- - (void )testAcceptLanguageWithMultipleLanguagesContainingEnglish
174- {
175- NSBundleMock *bundleMock = [NSBundleMock new ];
176- bundleMock.mockPreferredLocalizations = @[ @" fr-CA" , @" en" , @" pt-PT" ];
177-
178- Method originalMethod = class_getClassMethod (NSBundle .class , @selector (mainBundle ));
179- IMP originalMethodImplementation = method_getImplementation (originalMethod);
180-
181- IMP fakeMethodImplementation = imp_implementationWithBlock (^ {
182- return bundleMock;
183- });
184- method_setImplementation (originalMethod, fakeMethodImplementation);
185-
186- NSString *languageValues = [SPTDataLoaderRequest generateLanguageHeaderValue ];
187-
188- method_setImplementation (originalMethod, originalMethodImplementation);
189-
190- XCTAssertEqualObjects (@" fr-CA, en;q=0.50" , languageValues);
191- }
192-
193- - (void )testAcceptLanguageRemovesDuplicateLocalizations
194- {
195- NSBundleMock *bundleMock = [NSBundleMock new ];
196- bundleMock.mockPreferredLocalizations = @[ @" es-419" , @" es-419" , @" pt-PT" ];
197-
198- Method originalMethod = class_getClassMethod (NSBundle .class , @selector (mainBundle ));
199- IMP originalMethodImplementation = method_getImplementation (originalMethod);
200-
201- IMP fakeMethodImplementation = imp_implementationWithBlock (^ {
202- return bundleMock;
203- });
204- method_setImplementation (originalMethod, fakeMethodImplementation);
205-
206- NSString *languageValues = [SPTDataLoaderRequest generateLanguageHeaderValue ];
207-
208- method_setImplementation (originalMethod, originalMethodImplementation);
209-
210- XCTAssertEqualObjects (@" es-419, pt-PT;q=0.50, en;q=0.01" , languageValues);
211- }
212-
213173- (void )testDeleteMethod
214174{
215175 self.request .method = SPTDataLoaderRequestMethodDelete;
0 commit comments