Skip to content

Commit 77e2bee

Browse files
committed
Add tests for new methods.
1 parent 953182c commit 77e2bee

File tree

2 files changed

+64
-2
lines changed

2 files changed

+64
-2
lines changed

Tests/Unit/FileControllerTests.m

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,33 @@ - (void)testUploadCancel {
497497
[self waitForTestExpectations];
498498
}
499499

500-
- (void)testClearCaches {
500+
- (void)testClearFileCache {
501+
id mockedDataSource = PFStrictProtocolMock(@protocol(PFFileManagerProvider));
502+
id mockedFileManager = PFStrictClassMock([PFFileManager class]);
503+
504+
NSString *temporaryPath = [self temporaryDirectory];
505+
NSString *downloadsPath = [temporaryPath stringByAppendingPathComponent:@"downloads"];
506+
507+
OCMStub([mockedDataSource fileManager]).andReturn(mockedFileManager);
508+
OCMStub([mockedFileManager parseLocalSandboxDataDirectoryPath]).andReturn(temporaryPath);
509+
OCMStub([mockedFileManager parseCacheItemPathForPathComponent:@"PFFileCache"]).andReturn(downloadsPath);
510+
511+
PFFileController *fileController = [PFFileController controllerWithDataSource:mockedDataSource];
512+
PFFileState *fileState = [[PFMutableFileState alloc] initWithName:@"sampleData"
513+
urlString:temporaryPath
514+
mimeType:@"application/octet-stream"];
515+
516+
XCTestExpectation *expectation = [self currentSelectorTestExpectation];
517+
[[fileController clearFileCacheAsyncForFileWithState:fileState] continueWithBlock:^id(BFTask *task) {
518+
XCTAssertNil(task.error);
519+
[expectation fulfill];
520+
return nil;
521+
}];
522+
523+
[self waitForTestExpectations];
524+
}
525+
526+
- (void)testClearAllFilesCache {
501527
id mockedDataSource = PFStrictProtocolMock(@protocol(PFFileManagerProvider));
502528
id mockedFileManager = PFStrictClassMock([PFFileManager class]);
503529

@@ -511,7 +537,7 @@ - (void)testClearCaches {
511537
PFFileController *fileController = [PFFileController controllerWithDataSource:mockedDataSource];
512538

513539
XCTestExpectation *expectation = [self currentSelectorTestExpectation];
514-
[[fileController clearFileCacheAsync] continueWithBlock:^id(BFTask *task) {
540+
[[fileController clearAllFileCacheAsync] continueWithBlock:^id(BFTask *task) {
515541
XCTAssertNil(task.error);
516542
[expectation fulfill];
517543
return nil;

Tests/Unit/FileUnitTests.m

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,4 +508,40 @@ - (void)testCancel {
508508
[self waitForTestExpectations];
509509
}
510510

511+
- (void)testClearCachedData {
512+
id mockedFileController = [Parse _currentManager].coreManager.fileController;
513+
514+
PFFile *file = [PFFile fileWithName:@"a" data:[NSData data]];
515+
OCMExpect([mockedFileController clearFileCacheAsyncForFileWithState:file.state]).andReturn([BFTask taskWithResult:nil]);
516+
517+
XCTestExpectation *expectation = [self currentSelectorTestExpectation];
518+
[[file clearCachedDataInBackground] continueWithBlock:^id _Nullable(BFTask * _Nonnull task) {
519+
XCTAssertNil(task.result);
520+
XCTAssertFalse(task.faulted);
521+
XCTAssertFalse(task.cancelled);
522+
[expectation fulfill];
523+
return nil;
524+
}];
525+
[self waitForTestExpectations];
526+
527+
OCMVerifyAll(mockedFileController);
528+
}
529+
530+
- (void)testClearAllCachedData {
531+
id mockedFileController = [Parse _currentManager].coreManager.fileController;
532+
OCMExpect([mockedFileController clearAllFileCacheAsync]).andReturn([BFTask taskWithResult:nil]);
533+
534+
XCTestExpectation *expectation = [self currentSelectorTestExpectation];
535+
[[PFFile clearAllCachedDataInBackground] continueWithBlock:^id _Nullable(BFTask * _Nonnull task) {
536+
XCTAssertNil(task.result);
537+
XCTAssertFalse(task.faulted);
538+
XCTAssertFalse(task.cancelled);
539+
[expectation fulfill];
540+
return nil;
541+
}];
542+
[self waitForTestExpectations];
543+
544+
OCMVerifyAll(mockedFileController);
545+
}
546+
511547
@end

0 commit comments

Comments
 (0)