@@ -397,4 +397,46 @@ - (void)testSavesImages API_AVAILABLE(ios(14)) {
397
397
[self waitForExpectationsWithTimeout: 30 handler: nil ];
398
398
}
399
399
400
+ - (void )testPickImageRequestAuthorization API_AVAILABLE(ios(14 )) {
401
+ id mockPhotoLibrary = OCMClassMock ([PHPhotoLibrary class ]);
402
+ OCMStub ([mockPhotoLibrary authorizationStatusForAccessLevel: PHAccessLevelReadWrite])
403
+ .andReturn (PHAuthorizationStatusNotDetermined);
404
+ OCMExpect ([mockPhotoLibrary requestAuthorizationForAccessLevel: PHAccessLevelReadWrite
405
+ handler: OCMOCK_ANY]);
406
+
407
+ FLTImagePickerPlugin *plugin = [[FLTImagePickerPlugin alloc ] init ];
408
+
409
+ [plugin pickImageWithSource: [FLTSourceSpecification makeWithType: FLTSourceTypeGallery
410
+ camera: FLTSourceCameraFront]
411
+ maxSize: [[FLTMaxSize alloc ] init ]
412
+ quality: nil
413
+ fullMetadata: @YES
414
+ completion: ^(NSString *result, FlutterError *error){
415
+ }];
416
+ OCMVerifyAll (mockPhotoLibrary);
417
+ }
418
+
419
+ - (void )testPickImageAuthorizationDenied API_AVAILABLE(ios(14 )) {
420
+ id mockPhotoLibrary = OCMClassMock ([PHPhotoLibrary class ]);
421
+ OCMStub ([mockPhotoLibrary authorizationStatusForAccessLevel: PHAccessLevelReadWrite])
422
+ .andReturn (PHAuthorizationStatusDenied);
423
+
424
+ FLTImagePickerPlugin *plugin = [[FLTImagePickerPlugin alloc ] init ];
425
+
426
+ XCTestExpectation *resultExpectation = [self expectationWithDescription: @" result" ];
427
+
428
+ [plugin pickImageWithSource: [FLTSourceSpecification makeWithType: FLTSourceTypeGallery
429
+ camera: FLTSourceCameraFront]
430
+ maxSize: [[FLTMaxSize alloc ] init ]
431
+ quality: nil
432
+ fullMetadata: @YES
433
+ completion: ^(NSString *result, FlutterError *error) {
434
+ XCTAssertNil (result);
435
+ XCTAssertEqualObjects (error.code , @" photo_access_denied" );
436
+ XCTAssertEqualObjects (error.message , @" The user did not allow photo access." );
437
+ [resultExpectation fulfill ];
438
+ }];
439
+ [self waitForExpectationsWithTimeout: 30 handler: nil ];
440
+ }
441
+
400
442
@end
0 commit comments