+ Start a Discussion
Apex developer 21Apex developer 21 

Help wrinting a tesclass for extended controller attachment PDF

Im a newbie, can someone help me writing a test class for an extended controller PDF attachment see:
public with sharing class attachPDF {
private final Facturatie__c a;
    public attachPDF(ApexPages.StandardController standardPageController) {
        a = (Facturatie__c)standardPageController.getRecord();
    Facturatie__c  currentRecord = [SELECT Id, Accountname__r.Name FROM Facturatie__c WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
    public PageReference attachPDF() {
        PageReference pdfPage = Page.Factuur2PDF;
        Blob pdfBlob = pdfPage.getContent();
        Attachment attach = new Attachment(parentId = a.Id, Name = 'Factuur ' + '-' + currentRecord.Accountname__r.Name +'-'+ date.today().format() +'.pdf', body = pdfBlob); //create the attachment object
        insert attach;
        PageReference pageWhereWeWantToGo = new ApexPages.StandardController(a).view();
        return pageWhereWeWantToGo;