ABTFakeFIRAConditionalUserPropertyController.m 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. // Copyright 2019 Google
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #import "FirebaseABTesting/Tests/Unit/ABTFakeFIRAConditionalUserPropertyController.h"
  15. @implementation ABTFakeFIRAConditionalUserPropertyController {
  16. NSMutableArray<NSDictionary<NSString *, id> *> *_experiments;
  17. }
  18. + (instancetype)sharedInstance {
  19. static ABTFakeFIRAConditionalUserPropertyController *sharedInstance = nil;
  20. static dispatch_once_t onceToken = 0;
  21. dispatch_once(&onceToken, ^{
  22. sharedInstance = [[ABTFakeFIRAConditionalUserPropertyController alloc] init];
  23. });
  24. return sharedInstance;
  25. }
  26. - (instancetype)init {
  27. self = [super init];
  28. if (self) {
  29. _experiments = [[NSMutableArray alloc] init];
  30. }
  31. return self;
  32. }
  33. - (void)setConditionalUserProperty:(NSDictionary<NSString *, id> *)cupProperties {
  34. [_experiments addObject:cupProperties];
  35. }
  36. - (void)clearConditionalUserPropertyWithName:(NSString *)conditionalUserPropertyName {
  37. for (NSDictionary<NSString *, id> *experiment in _experiments) {
  38. if ([experiment[@"name"] isEqualToString:conditionalUserPropertyName]) {
  39. [_experiments removeObject:experiment];
  40. return;
  41. }
  42. }
  43. }
  44. - (NSArray<FIRAConditionalUserProperty *> *)
  45. conditionalUserPropertiesWithNamePrefix:(NSString *)namePrefix
  46. filterByOrigin:(NSString *)origin {
  47. return [_experiments copy];
  48. }
  49. /// Returns the max number of User Properties for the given origin.
  50. - (NSInteger)maxUserPropertiesForOrigin:(NSString *)origin {
  51. return 3;
  52. }
  53. - (void)resetExperiments {
  54. [_experiments removeAllObjects];
  55. }
  56. @end
  57. @implementation FakeAnalytics
  58. - (instancetype)initWithFakeController:
  59. (ABTFakeFIRAConditionalUserPropertyController *)fakeController {
  60. self = [super init];
  61. if (self) {
  62. _fakeController = fakeController;
  63. }
  64. return self;
  65. }
  66. - (nonnull NSArray<FIRAConditionalUserProperty *> *)
  67. conditionalUserProperties:(nonnull NSString *)origin
  68. propertyNamePrefix:(nonnull NSString *)propertyNamePrefix {
  69. return [_fakeController conditionalUserPropertiesWithNamePrefix:propertyNamePrefix
  70. filterByOrigin:origin];
  71. }
  72. - (void)clearConditionalUserProperty:(nonnull NSString *)userPropertyName
  73. forOrigin:(NSString *)origin
  74. clearEventName:(nonnull NSString *)clearEventName
  75. clearEventParameters:
  76. (nonnull NSDictionary<NSString *, NSString *> *)clearEventParameters {
  77. [_fakeController clearConditionalUserPropertyWithName:userPropertyName];
  78. }
  79. - (void)setConditionalUserProperty:(nonnull NSDictionary<NSString *, id> *)conditionalUserProperty {
  80. [_fakeController setConditionalUserProperty:conditionalUserProperty];
  81. }
  82. - (NSInteger)maxUserProperties:(nonnull NSString *)origin {
  83. return 3;
  84. }
  85. - (void)setConditionalUserPropertyControllerProperties:(NSDictionary<NSString *, id> *)properties {
  86. for (NSString *key in properties) {
  87. [[ABTFakeFIRAConditionalUserPropertyController sharedInstance]
  88. setValue:[properties objectForKey:key]
  89. forKey:key];
  90. }
  91. }
  92. - (FIRAEvent *)eventWithOrigin:(NSString *)origin
  93. eventName:(NSString *)eventName
  94. params:(NSDictionary<NSString *, NSString *> *)params {
  95. return nil;
  96. }
  97. // Stubs
  98. - (void)logEventWithOrigin:(nonnull NSString *)origin
  99. name:(nonnull NSString *)name
  100. parameters:(nullable NSDictionary<NSString *, id> *)parameters {
  101. }
  102. - (void)setUserPropertyWithOrigin:(nonnull NSString *)origin
  103. name:(nonnull NSString *)name
  104. value:(nonnull id)value {
  105. }
  106. - (void)checkLastNotificationForOrigin:(nonnull NSString *)origin
  107. queue:(nonnull dispatch_queue_t)queue
  108. callback:(nonnull void (^)(NSString *_Nullable))
  109. currentLastNotificationProperty {
  110. }
  111. - (void)registerAnalyticsListener:(nonnull id<FIRAnalyticsInteropListener>)listener
  112. withOrigin:(nonnull NSString *)origin {
  113. }
  114. - (void)unregisterAnalyticsListenerWithOrigin:(nonnull NSString *)origin {
  115. }
  116. - (void)getUserPropertiesWithCallback:(nonnull FIRAInteropUserPropertiesCallback)callback {
  117. }
  118. @end