Revision cc176feb asi-http-request-with-pithos/Classes/Tests/ASIDownloadCacheTests.m

b/asi-http-request-with-pithos/Classes/Tests/ASIDownloadCacheTests.m
298 298
	GHAssertTrue(success,@"Failed to use cached response");
299 299
}
300 300

  
301
- (void)testExtensionHandling
302
{
303
	NSArray *extensions = [ASIDownloadCache fileExtensionsToHandleAsHTML];
304
	for (NSString *extension in extensions) {
305
		NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://allseeing-i.com/file.%@",extension]];
306
		ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
307
		NSString *path = [[ASIDownloadCache sharedCache] pathToStoreCachedResponseDataForRequest:request];
308
		BOOL success = [[path pathExtension] isEqualToString:@"html"];
309
		GHAssertTrue(success, @"Failed to use html extension on cached path for a resource we know a webview won't be able to open locally");
310
	}
311

  
312
	NSURL *url = [NSURL URLWithString:@"http://allseeing-i.com/"];
313
	ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
314
	NSString *path = [[ASIDownloadCache sharedCache] pathToStoreCachedResponseDataForRequest:request];
315
	BOOL success = [[path pathExtension] isEqualToString:@"html"];
316
	GHAssertTrue(success, @"Failed to use html extension on cached path for a url without an extension");
317

  
318
	url = [NSURL URLWithString:@"http://allseeing-i.com/i/logo.png"];
319
	request = [ASIHTTPRequest requestWithURL:url];
320
	path = [[ASIDownloadCache sharedCache] pathToStoreCachedResponseDataForRequest:request];
321
	success = [[path pathExtension] isEqualToString:@"png"];
322
	GHAssertTrue(success, @"Failed to preserve file extension on cached path");
323
}
324

  
301 325
- (void)testCustomExpiry
302 326
{
303 327
	[[ASIDownloadCache sharedCache] clearCachedResponsesForStoragePolicy:ASICacheForSessionDurationCacheStoragePolicy];
......
506 530
	[request redirectToURL:newURL];
507 531
}
508 532

  
533
- (void)testCachedFileOverwritten
534
{
535
	// Test for https://github.com/pokeb/asi-http-request/pull/211
536
	// This test ensures that items in the cache are correctly overwritten when a downloadDestinationPath is set,
537
	// and they need to be copied to the cache at the end of the request
538

  
539
	// This url returns different content every time
540
	NSURL *url = [NSURL URLWithString:@"http://asi/ASIHTTPRequest/tests/random-content"];
541
	ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
542
	[request setDownloadCache:[ASIDownloadCache sharedCache]];
543
	[request setSecondsToCache:0.5f];
544
	[request startSynchronous];
545

  
546
	NSString *path = [[ASIDownloadCache sharedCache] pathToCachedResponseDataForURL:url];
547
	NSString *content = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:NULL];
548

  
549
	sleep(1);
550

  
551
	request = [ASIHTTPRequest requestWithURL:url];
552
	[request setDownloadCache:[ASIDownloadCache sharedCache]];
553
	[request setDownloadDestinationPath:[[self filePathForTemporaryTestFiles] stringByAppendingPathComponent:@"test.html"]];
554
	[request startSynchronous];
555

  
556
	NSString *content2 = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:NULL];
557

  
558
	BOOL success = ![content isEqualToString:content2];
559
	GHAssertTrue(success, @"Failed to overwrite response in cache");
560
}
561

  
509 562
@end

Also available in: Unified diff