FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
contentstack-ios/ContentstackTest/EntryAdvancedTest.m at master · contentstack/contentstack-ios · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
contentstack
/
contentstack-ios
Public
Notifications
You must be signed in to change notification settings
Fork
2
Star
3
Code
Issues
0
Pull requests
1
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
contentstack-ios
/
ContentstackTest
/
EntryAdvancedTest.m
Copy path
More file actions
More file actions
Latest commit
History
History
History
264 lines (206 loc) · 7.43 KB
Breadcrumbs
contentstack-ios
/
ContentstackTest
/
EntryAdvancedTest.m
Copy path
File metadata and controls
264 lines (206 loc) · 7.43 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
//
//
EntryAdvancedTest.m
//
ContentstackTest
//
//
Created by Contentstack on 06/11/25.
//
Copyright © 2025 Contentstack. All rights reserved.
//
#
import
<
XCTest/XCTest.h
>
#
import
"
Contentstack.h
"
#
import
"
Entry.h
"
#
import
"
ContentType.h
"
#
import
"
Config.h
"
#
import
"
CSIOInternalHeaders.h
"
@interface
EntryAdvancedTest
:
XCTestCase
@property
(
nonatomic
,
strong
) Stack *stack;
@property
(
nonatomic
,
strong
) Entry *entry;
@end
@implementation
EntryAdvancedTest
- (
void
)
setUp
{
[
super
setUp
];
NSString
*filePath =
[[NSBundle bundleForClass:[self class]]
pathForResource:
@"
config
"
ofType:
@"
json
"
];
NSData
*data = [
NSData
dataWithContentsOfFile:
filePath];
if
(data) {
NSDictionary
*config = [
NSJSONSerialization
JSONObjectWithData:
data
options:
0
error:
nil
];
Config *conf = [[Config
alloc
]
init
];
conf.
host
= config[
@"
host
"
];
self.
stack
= [Contentstack
stackWithAPIKey:
config[
@"
api_key
"
]
accessToken:
config[
@"
delivery_token
"
]
environmentName:
config[
@"
environment
"
]
config:
conf];
ContentType *contentType = [
self
.stack
contentTypeWithName:
@"
source
"
];
self.
entry
= [contentType
entryWithUID:
@"
test_uid
"
];
}
}
- (
void
)
tearDown
{
self.
entry
=
nil
;
self.
stack
=
nil
;
[
super
tearDown
];
}
- (
NSTimeInterval
)
requestTimeout
{
return
60.0
;
}
- (
void
)
waitForRequest
{
NSDate
*timeoutDate = [
NSDate
dateWithTimeIntervalSinceNow:
[
self
requestTimeout
]];
while
([
self
.entry
valueForKey:
@"
requestOperation
"
] !=
nil
&& [timeoutDate
timeIntervalSinceNow
] >
0
) {
[[
NSRunLoop
currentRunLoop
]
runMode:
NSDefaultRunLoopMode
beforeDate:
[
NSDate
dateWithTimeIntervalSinceNow:
0.01
]];
}
}
#
pragma mark
- Dictionary Access Tests
- (
void
)
testObjectForKeyNonExistent
{
id
value = [
self
.entry
objectForKey:
@"
nonexistent_key
"
];
//
Entry without fetch will return nil
XCTAssertTrue
(value ==
nil
|| [value
isKindOfClass:
[
NSObject
class
]]);
}
- (
void
)
testObjectForKeyedSubscriptNil
{
id
value = self.
entry
[
@"
nonexistent
"
];
//
Entry without fetch will return nil
XCTAssertTrue
(value ==
nil
|| [value
isKindOfClass:
[
NSObject
class
]]);
}
- (
void
)
testObjectForKeyMethod
{
//
Test that objectForKey: method exists and doesn't crash
XCTAssertNoThrow
([
self
.entry
objectForKey:
@"
any_key
"
]);
}
- (
void
)
testObjectForKeyedSubscriptMethod
{
//
Test that subscript access works
XCTAssertNoThrow
(self.
entry
[
@"
any_key
"
]);
}
#
pragma mark
- Has Key Tests
- (
void
)
testHasKeyDoesNotExist
{
//
Without fetch, entry has no data
BOOL
hasKey = [
self
.entry
hasKey:
@"
nonexistent_key
"
];
XCTAssertFalse
(hasKey);
}
- (
void
)
testHasKeyWithNil
{
BOOL
hasKey = [
self
.entry
hasKey:
nil
];
XCTAssertFalse
(hasKey);
}
- (
void
)
testHasKeyMethod
{
//
Test that hasKey: method exists and doesn't crash
XCTAssertNoThrow
([
self
.entry
hasKey:
@"
any_key
"
]);
}
#
pragma mark
- Markdown Conversion Tests
- (
void
)
testHTMLStringForMarkdownKeyNonExistent
{
//
Without data, should return nil
NSString
*html = [
self
.entry
HTMLStringForMarkdownKey:
@"
nonexistent
"
];
XCTAssertNil
(html);
}
- (
void
)
testHTMLStringForMarkdownKeyMethod
{
//
Test that the method exists and doesn't crash
XCTAssertNoThrow
([
self
.entry
HTMLStringForMarkdownKey:
@"
any_key
"
]);
}
- (
void
)
testHTMLArrayForMarkdownKeyNonExistent
{
//
Without data, should return nil
NSArray
*htmlArray = [
self
.entry
HTMLArrayForMarkdownKey:
@"
nonexistent
"
];
XCTAssertNil
(htmlArray);
}
- (
void
)
testHTMLArrayForMarkdownKeyMethod
{
//
Test that the method exists and doesn't crash
XCTAssertNoThrow
([
self
.entry
HTMLArrayForMarkdownKey:
@"
any_key
"
]);
}
#
pragma mark
- Asset Retrieval Tests
- (
void
)
testAssetForKeyNonExistent
{
//
Without data, should return nil
Asset *asset = [
self
.entry
assetForKey:
@"
nonexistent_asset
"
];
XCTAssertNil
(asset);
}
- (
void
)
testAssetForKeyMethod
{
//
Test that the method exists and doesn't crash
XCTAssertNoThrow
([
self
.entry
assetForKey:
@"
any_key
"
]);
}
- (
void
)
testAssetsForKeyNonExistent
{
//
Without data, should return empty array (not nil) for backward compatibility
NSArray
*assets = [
self
.entry
assetsForKey:
@"
nonexistent_assets
"
];
XCTAssertNotNil
(assets);
XCTAssertEqual
(assets.
count
,
0
);
}
- (
void
)
testAssetsForKeyMethod
{
//
Test that the method exists and doesn't crash
XCTAssertNoThrow
([
self
.entry
assetsForKey:
@"
any_key
"
]);
}
#
pragma mark
- Group Retrieval Tests
- (
void
)
testGroupsForKeyNonExistent
{
//
Without data, should return nil
NSArray
*groups = [
self
.entry
groupsForKey:
@"
nonexistent_groups
"
];
XCTAssertNil
(groups);
}
- (
void
)
testGroupsForKeyMethod
{
//
Test that the method exists and doesn't crash
XCTAssertNoThrow
([
self
.entry
groupsForKey:
@"
any_key
"
]);
}
#
pragma mark
- Reference Entry Tests
- (
void
)
testEntriesForKeyWithContentTypeNonExistent
{
//
Without data, should return nil
NSArray
*entries = [
self
.entry
entriesForKey:
@"
nonexistent_ref
"
withContentType:
@"
ref_ct
"
];
XCTAssertNil
(entries);
}
- (
void
)
testEntriesForKeyMethod
{
//
Test that the method exists and doesn't crash
XCTAssertNoThrow
([
self
.entry
entriesForKey:
@"
any_key
"
withContentType:
@"
any_ct
"
]);
}
#
pragma mark
- Description Test
- (
void
)
testEntryDescription
{
NSString
*description = [
self
.entry
description
];
XCTAssertNotNil
(description);
XCTAssertTrue
([description
containsString:
@"
Entry
"
]);
}
#
pragma mark
- Initialization Tests
- (
void
)
testInitWithContentTypeOnly
{
ContentType *contentType = [
self
.stack
contentTypeWithName:
@"
test
"
];
Entry *entry = [contentType
entryWithUID:
@"
test
"
];
XCTAssertNotNil
(entry);
XCTAssertEqualObjects
(entry.
contentTypeName
,
@"
test
"
);
}
- (
void
)
testInitWithTaxonomy
{
Taxonomy *taxonomy = [[Taxonomy
alloc
]
initWithStack:
self
.stack];
Entry *entry = [[Entry
alloc
]
initWithTaxonomy:
taxonomy];
XCTAssertNotNil
(entry);
}
#
pragma mark
- Include Methods Tests
- (
void
)
testIncludeFallback
{
[
self
.entry
includeFallback
];
XCTAssertNotNil
(self.
entry
);
}
- (
void
)
testIncludeMetadata
{
[
self
.entry
includeMetadata
];
XCTAssertNotNil
(self.
entry
);
}
- (
void
)
testIncludeBranch
{
[
self
.entry
includeBranch
];
XCTAssertNotNil
(self.
entry
);
}
- (
void
)
testGroupForKey
{
Group *group = [
self
.entry
groupForKey:
@"
any_group_key
"
];
//
Without data, should return nil
XCTAssertTrue
(group ==
nil
|| [group
isKindOfClass:
[Group
class
]]);
}
- (
void
)
testConfigureWithDictionary
{
NSDictionary
*testDict = @{
@"
title
"
:
@"
Test Title
"
,
@"
description
"
:
@"
Test Description
"
};
[
self
.entry
configureWithDictionary:
testDict];
XCTAssertNotNil
(self.
entry
);
}
- (
void
)
testConfigureWithEmptyDictionary
{
[
self
.entry
configureWithDictionary:
@{}];
XCTAssertNotNil
(self.
entry
);
}
- (
void
)
testEntryProperties
{
//
Test that readonly properties exist and can be accessed
XCTAssertNotNil
(self.
entry
.
uid
);
XCTAssertNotNil
(self.
entry
.
contentTypeName
);
//
Other properties may be nil until fetch
XCTAssertTrue
(
YES
);
}
- (
void
)
testEntryCachePolicy
{
self.
entry
.
cachePolicy
=
CACHE_THEN_NETWORK
;
XCTAssertEqual
(self.
entry
.
cachePolicy
,
CACHE_THEN_NETWORK
);
self.
entry
.
cachePolicy
=
NETWORK_ONLY
;
XCTAssertEqual
(self.
entry
.
cachePolicy
,
NETWORK_ONLY
);
}
- (
void
)
testEntryLocale
{
self.
entry
.
locale
=
@"
en-us
"
;
XCTAssertEqualObjects
(self.
entry
.
locale
,
@"
en-us
"
);
}
@end
Back
|
FazBrowse Home
|
New Git URL