FIRInstanceIDWithFCMTest.m 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * Copyright 2019 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import <OCMock/OCMock.h>
  17. #import <XCTest/XCTest.h>
  18. #import <FirebaseCore/FIRAppInternal.h>
  19. #import <FirebaseInstanceID/FirebaseInstanceID.h>
  20. #import <FirebaseMessaging/FIRMessaging.h>
  21. #import "Firebase/Messaging/FIRMessaging_Private.h"
  22. #import "Example/Messaging/Tests/FIRMessagingTestUtilities.h"
  23. @interface FIRInstanceID (ExposedForTest)
  24. - (BOOL)isFCMAutoInitEnabled;
  25. - (instancetype)initPrivately;
  26. @end
  27. @interface FIRInstanceIDTest : XCTestCase
  28. @property(nonatomic, readwrite, strong) FIRInstanceID *instanceID;
  29. @property(nonatomic, readwrite, strong) id mockFirebaseApp;
  30. @property(nonatomic, readwrite, strong) FIRMessagingTestUtilities *testUtil;
  31. @property(nonatomic, strong) FIRMessaging *messaging;
  32. @end
  33. @implementation FIRInstanceIDTest
  34. - (void)setUp {
  35. [super setUp];
  36. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  37. _testUtil = [[FIRMessagingTestUtilities alloc] initWithUserDefaults:defaults withRMQManager:NO];
  38. _instanceID = _testUtil.instanceID;
  39. _messaging = _testUtil.messaging;
  40. _mockFirebaseApp = OCMClassMock([FIRApp class]);
  41. OCMStub([_mockFirebaseApp defaultApp]).andReturn(_mockFirebaseApp);
  42. }
  43. - (void)tearDown {
  44. [_testUtil cleanupAfterTest];
  45. _instanceID = nil;
  46. _messaging = nil;
  47. [_mockFirebaseApp stopMocking];
  48. [super tearDown];
  49. }
  50. - (void)testFCMAutoInitEnabled {
  51. OCMStub([_mockFirebaseApp isDataCollectionDefaultEnabled]).andReturn(YES);
  52. _messaging.autoInitEnabled = YES;
  53. XCTAssertTrue(
  54. [_instanceID isFCMAutoInitEnabled],
  55. @"When FCM is available, FCM Auto Init Enabled should be FCM's autoInitEnable property.");
  56. _messaging.autoInitEnabled = NO;
  57. XCTAssertFalse(
  58. [_instanceID isFCMAutoInitEnabled],
  59. @"When FCM is available, FCM Auto Init Enabled should be FCM's autoInitEnable property.");
  60. _messaging.autoInitEnabled = YES;
  61. XCTAssertTrue([_instanceID isFCMAutoInitEnabled]);
  62. }
  63. @end