<?php declare(strict_types=1);

require_once __DIR__ . '/../../src/data/QrbRecipient.php';

use PHPUnit\Framework\TestCase;

final class QrbRecipientTest extends TestCase
{

    public function testParseHeaderDefaultOrder() : void
    {
        $headerNames = array(
            QrbRecipient::HDR_COMPANY,
            QrbRecipient::HDR_SALUTATION,
            QrbRecipient::HDR_FIRST_NAME,
            QrbRecipient::HDR_LAST_NAME,
            QrbRecipient::HDR_STREET,
            QrbRecipient::HDR_BUILDING_NO,
            QrbRecipient::HDR_POSTAL_CODE,
            QrbRecipient::HDR_CITY,
            QrbRecipient::HDR_COUNTRY,
            QrbRecipient::HDR_LANGUAGE,
            QrbRecipient::HDR_MAIL_ADDRESS,
            QrbRecipient::HDR_REFERENCE,
            QrbRecipient::HDR_AMOUNT
        );
        
        $hdr = QrbRecipient::parseHeader($headerNames, true, true, true, true);
        
        $this->assertEquals(0, $hdr[QrbRecipient::HDR_COMPANY]);
        $this->assertEquals(1, $hdr[QrbRecipient::HDR_SALUTATION]);
        $this->assertEquals(2, $hdr[QrbRecipient::HDR_FIRST_NAME]);
        $this->assertEquals(3, $hdr[QrbRecipient::HDR_LAST_NAME]);
        $this->assertEquals(4, $hdr[QrbRecipient::HDR_STREET]);
        $this->assertEquals(5, $hdr[QrbRecipient::HDR_BUILDING_NO]);
        $this->assertEquals(6, $hdr[QrbRecipient::HDR_POSTAL_CODE]);
        $this->assertEquals(7, $hdr[QrbRecipient::HDR_CITY]);
        $this->assertEquals(8, $hdr[QrbRecipient::HDR_COUNTRY]);
        $this->assertEquals(9, $hdr[QrbRecipient::HDR_LANGUAGE]);
        $this->assertEquals(10, $hdr[QrbRecipient::HDR_MAIL_ADDRESS]);
        $this->assertEquals(11, $hdr[QrbRecipient::HDR_REFERENCE]);
        $this->assertEquals(12, $hdr[QrbRecipient::HDR_AMOUNT]);
    }
    
    public function testParseHeaderDefaultOrderMissingLanguage() : void
    {
        $headerNames = array(
            QrbRecipient::HDR_COMPANY,
            QrbRecipient::HDR_SALUTATION,
            QrbRecipient::HDR_FIRST_NAME,
            QrbRecipient::HDR_LAST_NAME,
            QrbRecipient::HDR_STREET,
            QrbRecipient::HDR_BUILDING_NO,
            QrbRecipient::HDR_POSTAL_CODE,
            QrbRecipient::HDR_CITY,
            QrbRecipient::HDR_COUNTRY,
            QrbRecipient::HDR_MAIL_ADDRESS,
            QrbRecipient::HDR_REFERENCE,
            QrbRecipient::HDR_AMOUNT
        );
        
        $this->expectException(QrbException::class);
        $hdr = QrbRecipient::parseHeader($headerNames, true, true, true, true);
    }
    
    public function testValidateHappyDayAllOptionsAreTrue() : void
    {
        $recipient = array(
            "Muster GmbH",
            "Herr",
            "Hans",
            "Muster",
            "Musterstrasse",
            "99",
            "9999",
            "Musterstadt",
            "CH",
            "de",
            "muster@example.com",
            "123456",
            "100"
        );
        $headerNames = array(
            QrbRecipient::HDR_COMPANY,
            QrbRecipient::HDR_SALUTATION,
            QrbRecipient::HDR_FIRST_NAME,
            QrbRecipient::HDR_LAST_NAME,
            QrbRecipient::HDR_STREET,
            QrbRecipient::HDR_BUILDING_NO,
            QrbRecipient::HDR_POSTAL_CODE,
            QrbRecipient::HDR_CITY,
            QrbRecipient::HDR_COUNTRY,
            QrbRecipient::HDR_LANGUAGE,
            QrbRecipient::HDR_MAIL_ADDRESS,
            QrbRecipient::HDR_REFERENCE,
            QrbRecipient::HDR_AMOUNT
        );
        $hdr = QrbRecipient::parseHeader($headerNames, true, true, true, true);
        
        QrbRecipient::validate(1, $recipient, $hdr, true, true, true, true, array("de", "fr", "it", "en"));

        // dummy test for testdox (risky)
        $this->assertEquals("Muster GmbH", $recipient[0]);
    }
    
    public function testValidateHappyDayAmountMandatoryIsFalse() : void
    {
        $recipient = array(
            "Muster GmbH",
            "Herr",
            "Hans",
            "Muster",
            "Musterstrasse",
            "99",
            "9999",
            "Musterstadt",
            "CH",
            "de",
            "muster@example.com",
            "123456"
        );
        $headerNames = array(
            QrbRecipient::HDR_COMPANY,
            QrbRecipient::HDR_SALUTATION,
            QrbRecipient::HDR_FIRST_NAME,
            QrbRecipient::HDR_LAST_NAME,
            QrbRecipient::HDR_STREET,
            QrbRecipient::HDR_BUILDING_NO,
            QrbRecipient::HDR_POSTAL_CODE,
            QrbRecipient::HDR_CITY,
            QrbRecipient::HDR_COUNTRY,
            QrbRecipient::HDR_LANGUAGE,
            QrbRecipient::HDR_MAIL_ADDRESS,
            QrbRecipient::HDR_REFERENCE
        );
        $hdr = QrbRecipient::parseHeader($headerNames, false, true, true, true);
        
        QrbRecipient::validate(1, $recipient, $hdr, false, true, true, true, array("de", "fr", "it", "en"));

        // dummy test for testdox (risky)
        $this->assertEquals("Muster GmbH", $recipient[0]);
    }

    public function testValidateHappyDayCreatePdfIsFalse() : void
    {
        $recipient = array(
            "de",
            "muster@example.com"
        );
        $headerNames = array(
            QrbRecipient::HDR_LANGUAGE,
            QrbRecipient::HDR_MAIL_ADDRESS
        );
        $hdr = QrbRecipient::parseHeader($headerNames, true, false, true, true);
        
        QrbRecipient::validate(1, $recipient, $hdr, true, false, true, true, array("de", "fr", "it", "en"));

        // dummy test for testdox (risky)
        $this->assertEquals("de", $recipient[0]);
    }
    
    public function testValidateHappyDayPrintPaymentSlipIsFalse() : void
    {
        $recipient = array(
            "Muster GmbH",
            "Herr",
            "Hans",
            "Muster",
            "Musterstrasse",
            "99",
            "9999",
            "Musterstadt",
            "CH",
            "de",
            "muster@example.com",
            "100"
        );
        $headerNames = array(
            QrbRecipient::HDR_COMPANY,
            QrbRecipient::HDR_SALUTATION,
            QrbRecipient::HDR_FIRST_NAME,
            QrbRecipient::HDR_LAST_NAME,
            QrbRecipient::HDR_STREET,
            QrbRecipient::HDR_BUILDING_NO,
            QrbRecipient::HDR_POSTAL_CODE,
            QrbRecipient::HDR_CITY,
            QrbRecipient::HDR_COUNTRY,
            QrbRecipient::HDR_LANGUAGE,
            QrbRecipient::HDR_MAIL_ADDRESS,
            QrbRecipient::HDR_AMOUNT
        );
        $hdr = QrbRecipient::parseHeader($headerNames, true, true, false, true);
        
        QrbRecipient::validate(1, $recipient, $hdr, true, true, false, true, array("de", "fr", "it", "en"));

        // dummy test for testdox (risky)
        $this->assertEquals("Muster GmbH", $recipient[0]);
    }
    
    public function testValidateHappyDaySendMailIsFalse() : void
    {
        $recipient = array(
            "Muster GmbH",
            "Herr",
            "Hans",
            "Muster",
            "Musterstrasse",
            "99",
            "9999",
            "Musterstadt",
            "CH",
            "de",
            "123456",
            "100"
        );
        $headerNames = array(
            QrbRecipient::HDR_COMPANY,
            QrbRecipient::HDR_SALUTATION,
            QrbRecipient::HDR_FIRST_NAME,
            QrbRecipient::HDR_LAST_NAME,
            QrbRecipient::HDR_STREET,
            QrbRecipient::HDR_BUILDING_NO,
            QrbRecipient::HDR_POSTAL_CODE,
            QrbRecipient::HDR_CITY,
            QrbRecipient::HDR_COUNTRY,
            QrbRecipient::HDR_LANGUAGE,
            QrbRecipient::HDR_REFERENCE,
            QrbRecipient::HDR_AMOUNT
        );
        $hdr = QrbRecipient::parseHeader($headerNames, true, true, true, false);
        
        QrbRecipient::validate(1, $recipient, $hdr, true, true, true, false, array("de", "fr", "it", "en"));

        // dummy test for testdox (risky)
        $this->assertEquals("Muster GmbH", $recipient[0]);
    }
    
    public function testValidateAdditionalColumns() : void
    {
        $recipient = array(
            "DataOfSomeOtherColumn",
            "Muster GmbH",
            "Herr",
            "Hans",
            "Muster",
            "Musterstrasse",
            "99",
            "9999",
            "Musterstadt",
            "CH",
            "de",
            "muster@example.com",
            "123456",
            "100"
        );
        $headerNames = array(
            "SomeOtherColumn",
            QrbRecipient::HDR_COMPANY,
            QrbRecipient::HDR_SALUTATION,
            QrbRecipient::HDR_FIRST_NAME,
            QrbRecipient::HDR_LAST_NAME,
            QrbRecipient::HDR_STREET,
            QrbRecipient::HDR_BUILDING_NO,
            QrbRecipient::HDR_POSTAL_CODE,
            QrbRecipient::HDR_CITY,
            QrbRecipient::HDR_COUNTRY,
            QrbRecipient::HDR_LANGUAGE,
            QrbRecipient::HDR_MAIL_ADDRESS,
            QrbRecipient::HDR_REFERENCE,
            QrbRecipient::HDR_AMOUNT
        );
        $hdr = QrbRecipient::parseHeader($headerNames, true, true, true, true);
        
        QrbRecipient::validate(1, $recipient, $hdr, true, true, true, true, array("de", "fr", "it", "en"));
        
        $this->assertEquals("Muster GmbH", $recipient[1]);
        $this->assertEquals("muster@example.com", $recipient[11]);
        $this->assertEquals("123456", $recipient[12]);
    }

    public function testValidateTooLessData() : void
    {
        $recipient = array(
            "Muster GmbH",
            "Herr",
            "Hans",
            "Muster",
            "Musterstrasse",
            "99",
            "9999",
            "Musterstadt",
            "CH",
            "de",
            "muster@example.com",
            "123456",
            "100"
        );
        $headerNames = array(
//            QrbRecipient::HDR_COMPANY,
            QrbRecipient::HDR_SALUTATION,
            QrbRecipient::HDR_FIRST_NAME,
            QrbRecipient::HDR_LAST_NAME,
            QrbRecipient::HDR_STREET,
            QrbRecipient::HDR_BUILDING_NO,
            QrbRecipient::HDR_POSTAL_CODE,
            QrbRecipient::HDR_CITY,
            QrbRecipient::HDR_COUNTRY,
            QrbRecipient::HDR_LANGUAGE,
            QrbRecipient::HDR_MAIL_ADDRESS,
            QrbRecipient::HDR_REFERENCE,
            QrbRecipient::HDR_AMOUNT
        );
        $hdr = QrbRecipient::parseHeader($headerNames, true, true, true, true);
        
        $this->expectException(QrbException::class);
        QrbRecipient::validate(1, $recipient, $hdr, true, true, true, true, array("de", "fr", "it", "en"));
    }

    public function testValidateMissingFirstName() : void
    {
        $recipient = array(
            "Muster GmbH",
            "Herr",
//            "Hans",
            "Muster",
            "Musterstrasse",
            "99",
            "9999",
            "Musterstadt",
            "CH",
            "de",
            "muster@example.com",
            "123456",
            "100"
        );
        $headerNames = array(
            QrbRecipient::HDR_COMPANY,
            QrbRecipient::HDR_SALUTATION,
            QrbRecipient::HDR_FIRST_NAME,
            QrbRecipient::HDR_LAST_NAME,
            QrbRecipient::HDR_STREET,
            QrbRecipient::HDR_BUILDING_NO,
            QrbRecipient::HDR_POSTAL_CODE,
            QrbRecipient::HDR_CITY,
            QrbRecipient::HDR_COUNTRY,
            QrbRecipient::HDR_LANGUAGE,
            QrbRecipient::HDR_MAIL_ADDRESS,
            QrbRecipient::HDR_REFERENCE,
            QrbRecipient::HDR_AMOUNT
        );
        $hdr = QrbRecipient::parseHeader($headerNames, true, true, true, true);
        
        $this->expectException(QrbException::class);
        QrbRecipient::validate(1, $recipient, $hdr, true, true, true, true, array("de", "fr", "it", "en"));
    }    

    public function testValidateMissingLastName() : void
    {
        $recipient = array(
            "Muster GmbH",
            "Herr",
            "Hans",
//            "Muster",
            "Musterstrasse",
            "99",
            "9999",
            "Musterstadt",
            "CH",
            "de",
            "muster@example.com",
            "123456",
            "100"
        );
        $headerNames = array(
            QrbRecipient::HDR_COMPANY,
            QrbRecipient::HDR_SALUTATION,
            QrbRecipient::HDR_FIRST_NAME,
            QrbRecipient::HDR_LAST_NAME,
            QrbRecipient::HDR_STREET,
            QrbRecipient::HDR_BUILDING_NO,
            QrbRecipient::HDR_POSTAL_CODE,
            QrbRecipient::HDR_CITY,
            QrbRecipient::HDR_COUNTRY,
            QrbRecipient::HDR_LANGUAGE,
            QrbRecipient::HDR_MAIL_ADDRESS,
            QrbRecipient::HDR_REFERENCE,
            QrbRecipient::HDR_AMOUNT
        );
        $hdr = QrbRecipient::parseHeader($headerNames, true, true, true, true);
        
        $this->expectException(QrbException::class);
        QrbRecipient::validate(1, $recipient, $hdr, true, true, true, true, array("de", "fr", "it", "en"));
    }    

    public function testValidateMissingStreet() : void
    {
        $recipient = array(
            "Muster GmbH",
            "Herr",
            "Hans",
            "Muster",
//            "Musterstrasse",
            "99",
            "9999",
            "Musterstadt",
            "CH",
            "de",
            "muster@example.com",
            "123456",
            "100"
        );
        $headerNames = array(
            QrbRecipient::HDR_COMPANY,
            QrbRecipient::HDR_SALUTATION,
            QrbRecipient::HDR_FIRST_NAME,
            QrbRecipient::HDR_LAST_NAME,
            QrbRecipient::HDR_STREET,
            QrbRecipient::HDR_BUILDING_NO,
            QrbRecipient::HDR_POSTAL_CODE,
            QrbRecipient::HDR_CITY,
            QrbRecipient::HDR_COUNTRY,
            QrbRecipient::HDR_LANGUAGE,
            QrbRecipient::HDR_MAIL_ADDRESS,
            QrbRecipient::HDR_REFERENCE,
            QrbRecipient::HDR_AMOUNT
        );
        $hdr = QrbRecipient::parseHeader($headerNames, true, true, true, true);
        
        $this->expectException(QrbException::class);
        QrbRecipient::validate(1, $recipient, $hdr, true, true, true, true, array("de", "fr", "it", "en"));
    }    

    public function testValidateMissingBuildingNumber() : void
    {
        $recipient = array(
            "Muster GmbH",
            "Herr",
            "Hans",
            "Muster",
            "Musterstrasse",
//            "99",
            "9999",
            "Musterstadt",
            "CH",
            "de",
            "muster@example.com",
            "123456",
            "100"
        );
        $headerNames = array(
            QrbRecipient::HDR_COMPANY,
            QrbRecipient::HDR_SALUTATION,
            QrbRecipient::HDR_FIRST_NAME,
            QrbRecipient::HDR_LAST_NAME,
            QrbRecipient::HDR_STREET,
            QrbRecipient::HDR_BUILDING_NO,
            QrbRecipient::HDR_POSTAL_CODE,
            QrbRecipient::HDR_CITY,
            QrbRecipient::HDR_COUNTRY,
            QrbRecipient::HDR_LANGUAGE,
            QrbRecipient::HDR_MAIL_ADDRESS,
            QrbRecipient::HDR_REFERENCE,
            QrbRecipient::HDR_AMOUNT
        );
        $hdr = QrbRecipient::parseHeader($headerNames, true, true, true, true);
        
        $this->expectException(QrbException::class);
        QrbRecipient::validate(1, $recipient, $hdr, true, true, true, true, array("de", "fr", "it", "en"));
    }    

    public function testValidateMissingPostalCode() : void
    {
        $recipient = array(
            "Muster GmbH",
            "Herr",
            "Hans",
            "Muster",
            "Musterstrasse",
            "99",
//            "9999",
            "Musterstadt",
            "CH",
            "de",
            "muster@example.com",
            "123456",
            "100"
        );
        $headerNames = array(
            QrbRecipient::HDR_COMPANY,
            QrbRecipient::HDR_SALUTATION,
            QrbRecipient::HDR_FIRST_NAME,
            QrbRecipient::HDR_LAST_NAME,
            QrbRecipient::HDR_STREET,
            QrbRecipient::HDR_BUILDING_NO,
            QrbRecipient::HDR_POSTAL_CODE,
            QrbRecipient::HDR_CITY,
            QrbRecipient::HDR_COUNTRY,
            QrbRecipient::HDR_LANGUAGE,
            QrbRecipient::HDR_MAIL_ADDRESS,
            QrbRecipient::HDR_REFERENCE,
            QrbRecipient::HDR_AMOUNT
        );
        $hdr = QrbRecipient::parseHeader($headerNames, true, true, true, true);
        
        $this->expectException(QrbException::class);
        QrbRecipient::validate(1, $recipient, $hdr, true, true, true, true, array("de", "fr", "it", "en"));
    }    

    public function testValidateMissingCity() : void
    {
        $recipient = array(
            "Muster GmbH",
            "Herr",
            "Hans",
            "Muster",
            "Musterstrasse",
            "99",
            "9999",
//            "Musterstadt",
            "CH",
            "de",
            "muster@example.com",
            "123456",
            "100"
        );
        $headerNames = array(
            QrbRecipient::HDR_COMPANY,
            QrbRecipient::HDR_SALUTATION,
            QrbRecipient::HDR_FIRST_NAME,
            QrbRecipient::HDR_LAST_NAME,
            QrbRecipient::HDR_STREET,
            QrbRecipient::HDR_BUILDING_NO,
            QrbRecipient::HDR_POSTAL_CODE,
            QrbRecipient::HDR_CITY,
            QrbRecipient::HDR_COUNTRY,
            QrbRecipient::HDR_LANGUAGE,
            QrbRecipient::HDR_MAIL_ADDRESS,
            QrbRecipient::HDR_REFERENCE,
            QrbRecipient::HDR_AMOUNT
        );
        $hdr = QrbRecipient::parseHeader($headerNames, true, true, true, true);
        
        $this->expectException(QrbException::class);
        QrbRecipient::validate(1, $recipient, $hdr, true, true, true, true, array("de", "fr", "it", "en"));
    }    

    public function testValidateMissingCountry() : void
    {
        $recipient = array(
            "Muster GmbH",
            "Herr",
            "Hans",
            "Muster",
            "Musterstrasse",
            "99",
            "9999",
            "Musterstadt",
//            "CH",
            "de",
            "muster@example.com",
            "123456",
            "100"
        );
        $headerNames = array(
            QrbRecipient::HDR_COMPANY,
            QrbRecipient::HDR_SALUTATION,
            QrbRecipient::HDR_FIRST_NAME,
            QrbRecipient::HDR_LAST_NAME,
            QrbRecipient::HDR_STREET,
            QrbRecipient::HDR_BUILDING_NO,
            QrbRecipient::HDR_POSTAL_CODE,
            QrbRecipient::HDR_CITY,
            QrbRecipient::HDR_COUNTRY,
            QrbRecipient::HDR_LANGUAGE,
            QrbRecipient::HDR_MAIL_ADDRESS,
            QrbRecipient::HDR_REFERENCE,
            QrbRecipient::HDR_AMOUNT
        );
        $hdr = QrbRecipient::parseHeader($headerNames, true, true, true, true);
        
        $this->expectException(QrbException::class);
        QrbRecipient::validate(1, $recipient, $hdr, true, true, true, true, array("de", "fr", "it", "en"));
    }    

    public function testValidateMissingLanguage() : void
    {
        $recipient = array(
            "Muster GmbH",
            "Herr",
            "Hans",
            "Muster",
            "Musterstrasse",
            "99",
            "9999",
            "Musterstadt",
            "CH",
//            "de",
            "muster@example.com",
            "123456",
            "100"
        );
        $headerNames = array(
            QrbRecipient::HDR_COMPANY,
            QrbRecipient::HDR_SALUTATION,
            QrbRecipient::HDR_FIRST_NAME,
            QrbRecipient::HDR_LAST_NAME,
            QrbRecipient::HDR_STREET,
            QrbRecipient::HDR_BUILDING_NO,
            QrbRecipient::HDR_POSTAL_CODE,
            QrbRecipient::HDR_CITY,
            QrbRecipient::HDR_COUNTRY,
            QrbRecipient::HDR_LANGUAGE,
            QrbRecipient::HDR_MAIL_ADDRESS,
            QrbRecipient::HDR_REFERENCE,
            QrbRecipient::HDR_AMOUNT
        );
        $hdr = QrbRecipient::parseHeader($headerNames, true, true, true, true);
        
        $this->expectException(QrbException::class);
        QrbRecipient::validate(1, $recipient, $hdr, true, true, true, true, array("de", "fr", "it", "en"));
    }    

    public function testValidateMissingMailAddress() : void
    {
        $recipient = array(
            "Muster GmbH",
            "Herr",
            "Hans",
            "Muster",
            "Musterstrasse",
            "99",
            "9999",
            "Musterstadt",
            "CH",
            "de",
//            "muster@example.com",
            "123456",
            "100"
        );
        $headerNames = array(
            QrbRecipient::HDR_COMPANY,
            QrbRecipient::HDR_SALUTATION,
            QrbRecipient::HDR_FIRST_NAME,
            QrbRecipient::HDR_LAST_NAME,
            QrbRecipient::HDR_STREET,
            QrbRecipient::HDR_BUILDING_NO,
            QrbRecipient::HDR_POSTAL_CODE,
            QrbRecipient::HDR_CITY,
            QrbRecipient::HDR_COUNTRY,
            QrbRecipient::HDR_LANGUAGE,
            QrbRecipient::HDR_MAIL_ADDRESS,
            QrbRecipient::HDR_REFERENCE,
            QrbRecipient::HDR_AMOUNT
        );
        $hdr = QrbRecipient::parseHeader($headerNames, true, true, true, true);
        
        $this->expectException(QrbException::class);
        QrbRecipient::validate(1, $recipient, $hdr, true, true, true, true, array("de", "fr", "it", "en"));
    }    

    public function testValidateMissingReference() : void
    {
        $recipient = array(
            "Muster GmbH",
            "Herr",
            "Hans",
            "Muster",
            "Musterstrasse",
            "99",
            "9999",
            "Musterstadt",
            "CH",
            "de",
            "muster@example.com",
//            "123456",
            "100"
        );
        $headerNames = array(
            QrbRecipient::HDR_COMPANY,
            QrbRecipient::HDR_SALUTATION,
            QrbRecipient::HDR_FIRST_NAME,
            QrbRecipient::HDR_LAST_NAME,
            QrbRecipient::HDR_STREET,
            QrbRecipient::HDR_BUILDING_NO,
            QrbRecipient::HDR_POSTAL_CODE,
            QrbRecipient::HDR_CITY,
            QrbRecipient::HDR_COUNTRY,
            QrbRecipient::HDR_LANGUAGE,
            QrbRecipient::HDR_MAIL_ADDRESS,
            QrbRecipient::HDR_REFERENCE,
            QrbRecipient::HDR_AMOUNT
        );
        $hdr = QrbRecipient::parseHeader($headerNames, true, true, true, true);
        
        $this->expectException(QrbException::class);
        QrbRecipient::validate(1, $recipient, $hdr, true, true, true, true, array("de", "fr", "it", "en"));
    }    

    public function testValidateMissingAmount() : void
    {
        $recipient = array(
            "Muster GmbH",
            "Herr",
            "Hans",
            "Muster",
            "Musterstrasse",
            "99",
            "9999",
            "Musterstadt",
            "CH",
            "de",
            "muster@example.com",
            "123456",
//            "100"
        );
        $headerNames = array(
            QrbRecipient::HDR_COMPANY,
            QrbRecipient::HDR_SALUTATION,
            QrbRecipient::HDR_FIRST_NAME,
            QrbRecipient::HDR_LAST_NAME,
            QrbRecipient::HDR_STREET,
            QrbRecipient::HDR_BUILDING_NO,
            QrbRecipient::HDR_POSTAL_CODE,
            QrbRecipient::HDR_CITY,
            QrbRecipient::HDR_COUNTRY,
            QrbRecipient::HDR_LANGUAGE,
            QrbRecipient::HDR_MAIL_ADDRESS,
            QrbRecipient::HDR_REFERENCE,
            QrbRecipient::HDR_AMOUNT
        );
        $hdr = QrbRecipient::parseHeader($headerNames, true, true, true, true);
        
        $this->expectException(QrbException::class);
        QrbRecipient::validate(1, $recipient, $hdr, true, true, true, true, array("de", "fr", "it", "en"));
    }    

    public function testValidateInvalidMailAddress() : void
    {
        $recipient = array(
            "Muster GmbH",
            "Herr",
            "Hans",
            "Muster",
            "Musterstrasse",
            "99",
            "9999",
            "Musterstadt",
            "CH",
            "de",
            "www.muster.ch",
            "123456",
            "100"
        );
        $headerNames = array(
            QrbRecipient::HDR_COMPANY,
            QrbRecipient::HDR_SALUTATION,
            QrbRecipient::HDR_FIRST_NAME,
            QrbRecipient::HDR_LAST_NAME,
            QrbRecipient::HDR_STREET,
            QrbRecipient::HDR_BUILDING_NO,
            QrbRecipient::HDR_POSTAL_CODE,
            QrbRecipient::HDR_CITY,
            QrbRecipient::HDR_COUNTRY,
            QrbRecipient::HDR_LANGUAGE,
            QrbRecipient::HDR_MAIL_ADDRESS,
            QrbRecipient::HDR_REFERENCE,
            QrbRecipient::HDR_AMOUNT
        );
        $hdr = QrbRecipient::parseHeader($headerNames, true, true, true, true);
        
        $this->expectException(QrbException::class);
        QrbRecipient::validate(1, $recipient, $hdr, true, true, true, true, array("de", "fr", "it", "en"));
    }

    public function testValidateInvalidReferenceNotNumeric() : void
    {
        $recipient = array(
            "Muster GmbH",
            "Herr",
            "Hans",
            "Muster",
            "Musterstrasse",
            "99",
            "9999",
            "Musterstadt",
            "CH",
            "de",
            "muster@example.com",
            "ABC123456",
            "100"
        );
        $headerNames = array(
            QrbRecipient::HDR_COMPANY,
            QrbRecipient::HDR_SALUTATION,
            QrbRecipient::HDR_FIRST_NAME,
            QrbRecipient::HDR_LAST_NAME,
            QrbRecipient::HDR_STREET,
            QrbRecipient::HDR_BUILDING_NO,
            QrbRecipient::HDR_POSTAL_CODE,
            QrbRecipient::HDR_CITY,
            QrbRecipient::HDR_COUNTRY,
            QrbRecipient::HDR_LANGUAGE,
            QrbRecipient::HDR_MAIL_ADDRESS,
            QrbRecipient::HDR_REFERENCE,
            QrbRecipient::HDR_AMOUNT
        );
        $hdr = QrbRecipient::parseHeader($headerNames, true, true, true, true);
        
        $this->expectException(QrbException::class);
        QrbRecipient::validate(1, $recipient, $hdr, true, true, true, true, array("de", "fr", "it", "en"));
    }    

    public function testValidateInvalidAmountNotNumeric() : void
    {
        $recipient = array(
            "Muster GmbH",
            "Herr",
            "Hans",
            "Muster",
            "Musterstrasse",
            "99",
            "9999",
            "Musterstadt",
            "CH",
            "de",
            "muster@example.com",
            "123456",
            "CHF 100"
        );
        $headerNames = array(
            QrbRecipient::HDR_COMPANY,
            QrbRecipient::HDR_SALUTATION,
            QrbRecipient::HDR_FIRST_NAME,
            QrbRecipient::HDR_LAST_NAME,
            QrbRecipient::HDR_STREET,
            QrbRecipient::HDR_BUILDING_NO,
            QrbRecipient::HDR_POSTAL_CODE,
            QrbRecipient::HDR_CITY,
            QrbRecipient::HDR_COUNTRY,
            QrbRecipient::HDR_LANGUAGE,
            QrbRecipient::HDR_MAIL_ADDRESS,
            QrbRecipient::HDR_REFERENCE,
            QrbRecipient::HDR_AMOUNT
        );
        $hdr = QrbRecipient::parseHeader($headerNames, true, true, true, true);
        
        $this->expectException(QrbException::class);
        QrbRecipient::validate(1, $recipient, $hdr, true, true, true, true, array("de", "fr", "it", "en"));
    }    

    public function testValidateInvalidAmountLessThanZero() : void
    {
        $recipient = array(
            "Muster GmbH",
            "Herr",
            "Hans",
            "Muster",
            "Musterstrasse",
            "99",
            "9999",
            "Musterstadt",
            "CH",
            "de",
            "muster@example.com",
            "123456",
            "-100"
        );
        $headerNames = array(
            QrbRecipient::HDR_COMPANY,
            QrbRecipient::HDR_SALUTATION,
            QrbRecipient::HDR_FIRST_NAME,
            QrbRecipient::HDR_LAST_NAME,
            QrbRecipient::HDR_STREET,
            QrbRecipient::HDR_BUILDING_NO,
            QrbRecipient::HDR_POSTAL_CODE,
            QrbRecipient::HDR_CITY,
            QrbRecipient::HDR_COUNTRY,
            QrbRecipient::HDR_LANGUAGE,
            QrbRecipient::HDR_MAIL_ADDRESS,
            QrbRecipient::HDR_REFERENCE,
            QrbRecipient::HDR_AMOUNT
        );
        $hdr = QrbRecipient::parseHeader($headerNames, true, true, true, true);
        
        $this->expectException(QrbException::class);
        QrbRecipient::validate(1, $recipient, $hdr, true, true, true, true, array("de", "fr", "it", "en"));
    }    
    
    public function testConstructAndCallItsGettersAndToString() : void
    {
        $recipient = array(
            "Sehr geehrter Herr Muster",
            "Muster GmbH",
            "Herr",
            "Hans",
            "Muster",
            "Musterstrasse",
            "99",
            "9999",
            "Musterstadt",
            "CH",
            "de",
            "muster@example.com",
            "123456",
            "100"
        );
        $headerNames = array(
            QrbRecipient::HDR_GREETING,
            QrbRecipient::HDR_COMPANY,
            QrbRecipient::HDR_SALUTATION,
            QrbRecipient::HDR_FIRST_NAME,
            QrbRecipient::HDR_LAST_NAME,
            QrbRecipient::HDR_STREET,
            QrbRecipient::HDR_BUILDING_NO,
            QrbRecipient::HDR_POSTAL_CODE,
            QrbRecipient::HDR_CITY,
            QrbRecipient::HDR_COUNTRY,
            QrbRecipient::HDR_LANGUAGE,
            QrbRecipient::HDR_MAIL_ADDRESS,
            QrbRecipient::HDR_REFERENCE,
            QrbRecipient::HDR_AMOUNT
        );
        $hdr = QrbRecipient::parseHeader($headerNames, true, true, true, true);
    
        $r = new QrbRecipient(1, $recipient, $hdr, true, true, true, true, array("de", "fr", "it", "en"));
        
        $this->assertEquals(1, $r->getIndex());
        $this->assertEquals("Sehr geehrter Herr Muster", $r->getGreeting());
        $this->assertEquals("Muster GmbH", $r->getCompany());
        $this->assertEquals("Herr", $r->getSalutation());
        $this->assertEquals("Hans", $r->getFirstName());
        $this->assertEquals("Muster", $r->getLastName());
        $this->assertEquals("Musterstrasse", $r->getStreet());
        $this->assertEquals("99", $r->getBuildingNo());
        $this->assertEquals("9999", $r->getPostalCode());
        $this->assertEquals("Musterstadt", $r->getCity());
        $this->assertEquals("CH", $r->getCountry());
        $this->assertEquals("de", $r->getLanguage());
        $this->assertEquals("muster@example.com", $r->getMailAddress());
        $this->assertEquals("123456", $r->getReference());
        $this->assertEquals(100, $r->getAmount());
        
        echo $r . "\n";
    }
    
    public function testConstructAndCallItsGettersNoReferenceNoAmount() : void
    {
        $recipient = array(
            "Sehr geehrter Herr Muster",
            "Muster GmbH",
            "Herr",
            "Hans",
            "Muster",
            "Musterstrasse",
            "99",
            "9999",
            "Musterstadt",
            "CH",
            "de",
            "muster@example.com"
        );
        $headerNames = array(
            QrbRecipient::HDR_GREETING,
            QrbRecipient::HDR_COMPANY,
            QrbRecipient::HDR_SALUTATION,
            QrbRecipient::HDR_FIRST_NAME,
            QrbRecipient::HDR_LAST_NAME,
            QrbRecipient::HDR_STREET,
            QrbRecipient::HDR_BUILDING_NO,
            QrbRecipient::HDR_POSTAL_CODE,
            QrbRecipient::HDR_CITY,
            QrbRecipient::HDR_COUNTRY,
            QrbRecipient::HDR_LANGUAGE,
            QrbRecipient::HDR_MAIL_ADDRESS
        );
        $hdr = QrbRecipient::parseHeader($headerNames, false, true, false, true);
    
        $r = new QrbRecipient(1, $recipient, $hdr, false, true, false, true, array("de", "fr", "it", "en"));
        
        $this->assertEquals(1, $r->getIndex());
        $this->assertEquals("Sehr geehrter Herr Muster", $r->getGreeting());
        $this->assertEquals("Muster GmbH", $r->getCompany());
        $this->assertEquals("Herr", $r->getSalutation());
        $this->assertEquals("Hans", $r->getFirstName());
        $this->assertEquals("Muster", $r->getLastName());
        $this->assertEquals("Musterstrasse", $r->getStreet());
        $this->assertEquals("99", $r->getBuildingNo());
        $this->assertEquals("9999", $r->getPostalCode());
        $this->assertEquals("Musterstadt", $r->getCity());
        $this->assertEquals("CH", $r->getCountry());
        $this->assertEquals("de", $r->getLanguage());
        $this->assertEquals("muster@example.com", $r->getMailAddress());
        $this->assertNull($r->getReference());
        $this->assertNull($r->getAmount());
    }
    
    public function testConstructAndCallItsGettersAdditionalColumns() : void
    {
        $recipient = array(
            "DataOfSomeOtherColumn1",
            "Sehr geehrter Herr Muster",
            "Muster GmbH",
            "Herr",
            "Hans",
            "Muster",
            "DataOfSomeOtherColumn2",
            "Musterstrasse",
            "99",
            "9999",
            "Musterstadt",
            "CH",
            "de",
            "muster@example.com",
            "123456",
            "100",
            "DataOfSomeOtherColumn3"
        );
        $headerNames = array(
            "SomeOtherColumn1",
            QrbRecipient::HDR_GREETING,
            QrbRecipient::HDR_COMPANY,
            QrbRecipient::HDR_SALUTATION,
            QrbRecipient::HDR_FIRST_NAME,
            QrbRecipient::HDR_LAST_NAME,
            "SomeOtherColumn2",
            QrbRecipient::HDR_STREET,
            QrbRecipient::HDR_BUILDING_NO,
            QrbRecipient::HDR_POSTAL_CODE,
            QrbRecipient::HDR_CITY,
            QrbRecipient::HDR_COUNTRY,
            QrbRecipient::HDR_LANGUAGE,
            QrbRecipient::HDR_MAIL_ADDRESS,
            QrbRecipient::HDR_REFERENCE,
            QrbRecipient::HDR_AMOUNT,
            "SomeOtherColumn3"
        );
        $hdr = QrbRecipient::parseHeader($headerNames, true, true, true, true);
    
        $r = new QrbRecipient(1, $recipient, $hdr, true, true, true, true, array("de", "fr", "it", "en"));
        
        $this->assertEquals(1, $r->getIndex());
        $this->assertEquals("Sehr geehrter Herr Muster", $r->getGreeting());
        $this->assertEquals("Muster GmbH", $r->getCompany());
        $this->assertEquals("Herr", $r->getSalutation());
        $this->assertEquals("Hans", $r->getFirstName());
        $this->assertEquals("Muster", $r->getLastName());
        $this->assertEquals("Musterstrasse", $r->getStreet());
        $this->assertEquals("99", $r->getBuildingNo());
        $this->assertEquals("9999", $r->getPostalCode());
        $this->assertEquals("Musterstadt", $r->getCity());
        $this->assertEquals("CH", $r->getCountry());
        $this->assertEquals("de", $r->getLanguage());
        $this->assertEquals("muster@example.com", $r->getMailAddress());
        $this->assertEquals("123456", $r->getReference());
        $this->assertEquals(100, $r->getAmount());
    }
    
    public function testSetMailAddress() : void
    {
        $recipient = array(
            "Muster GmbH",
            "Herr",
            "Hans",
            "Muster",
            "Musterstrasse",
            "99",
            "9999",
            "Musterstadt",
            "CH",
            "de",
            "muster@example.com",
            "123456",
            "100"
        );
        $headerNames = array(
            QrbRecipient::HDR_COMPANY,
            QrbRecipient::HDR_SALUTATION,
            QrbRecipient::HDR_FIRST_NAME,
            QrbRecipient::HDR_LAST_NAME,
            QrbRecipient::HDR_STREET,
            QrbRecipient::HDR_BUILDING_NO,
            QrbRecipient::HDR_POSTAL_CODE,
            QrbRecipient::HDR_CITY,
            QrbRecipient::HDR_COUNTRY,
            QrbRecipient::HDR_LANGUAGE,
            QrbRecipient::HDR_MAIL_ADDRESS,
            QrbRecipient::HDR_REFERENCE,
            QrbRecipient::HDR_AMOUNT
        );
        $hdr = QrbRecipient::parseHeader($headerNames, true, true, true, true);
    
        $r = new QrbRecipient(1, $recipient, $hdr, true, true, true, true, array("de", "fr", "it", "en"));
        
        $this->assertEquals(1, $r->getIndex());
        $this->assertEquals("Muster GmbH", $r->getCompany());
        $this->assertEquals("Herr", $r->getSalutation());
        $this->assertEquals("Hans", $r->getFirstName());
        $this->assertEquals("Muster", $r->getLastName());
        $this->assertEquals("Musterstrasse", $r->getStreet());
        $this->assertEquals("99", $r->getBuildingNo());
        $this->assertEquals("9999", $r->getPostalCode());
        $this->assertEquals("Musterstadt", $r->getCity());
        $this->assertEquals("CH", $r->getCountry());
        $this->assertEquals("de", $r->getLanguage());
        $this->assertEquals("muster@example.com", $r->getMailAddress());
        $this->assertEquals("123456", $r->getReference());
        $this->assertEquals(100, $r->getAmount());
        
        $r->setMailAddress("example@example.ch");
        $this->assertEquals("example@example.ch", $r->getMailAddress());
    }
}

?>
