Skip to content

Instantly share code, notes, and snippets.

@steipete
Created May 6, 2014 17:05
Show Gist options
  • Save steipete/dd58d4629d8a48f15bda to your computer and use it in GitHub Desktop.
Save steipete/dd58d4629d8a48f15bda to your computer and use it in GitHub Desktop.
Test cases with Aspects! https://github.com/steipete/Aspects
- (void)testRelativeURLs {
PSPDFDocument *document = [[PSPDFTestAssetLoader new] documentWithName:@"Testcase-relative-links.pdf"];
NSArray *annotations = [document annotationsForPage:0 type:PSPDFAnnotationTypeLink];
PSPDFLinkAnnotation *link = annotations[0];
NSString *const referenceString = @"Testcase-relative-links/Simple.txt";
XCTAssertEqualObjects(link.URL.absoluteString, referenceString, @"URL should be correct");
PSPDFViewController *pdfController = [[PSPDFViewController alloc] initWithDocument:document];
__block NSURL *showPreviewURL = nil;
[pdfController aspect_hookSelector:@selector(showPreviewForURL:animated:title:options:sender:) withOptions:AspectOptionAutomaticRemoval usingBlock:^(id instance, NSArray *args) {
showPreviewURL = args.firstObject;
} error:NULL];
[pdfController executePDFAction:link.action inTargetRect:CGRectZero forPage:0 animated:NO actionContainer:link];
NSURL *referenceURL = [document.fileURL.URLByDeletingLastPathComponent URLByAppendingPathComponent:referenceString];
XCTAssertEqualObjects(showPreviewURL, referenceURL, @"URL must be correct");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment