<?php declare(strict_types=1);

require_once __DIR__ . '/../../src/process/QrbPdfCustomizer.php';

use PHPUnit\Framework\TestCase;

final class QrbPdfCustomizerTest extends TestCase
{
    const LANGUAGE_DE = "de";

    public function testBuildSalutationForAddressNoCompany() : void
    {
        $this->assertEquals("Herr", 
                            QrbPdfCustomizer::buildSalutationForAddress($this->createRecipient()));
    }

    public function testBuildSalutationForAddressWithCompany() : void
    {
        $this->assertEquals("Muster AG", 
                            QrbPdfCustomizer::buildSalutationForAddress($this->createRecipientWithCompany()));
    }

    private function createRecipient() : QrbRecipient
    {
        $recipientFile = array(
            array(QrbRecipient::HDR_LANGUAGE, 
                  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_REFERENCE,
                  QrbRecipient::HDR_AMOUNT),
            array(self::LANGUAGE_DE, "", "Herr", "Hans", "Muster", "", "", "", "", "", "123456", "2222.22")
        );
        $headerNames = QrbRecipient::parseHeader($recipientFile[0], true, true, true, false);
        return new QrbRecipient(1, $recipientFile[1], $headerNames, true, true, true, false, array("de", "fr", "it", "en"));
    }

    private function createRecipientWithCompany() : QrbRecipient
    {
        $recipientFile = array(
            array(QrbRecipient::HDR_LANGUAGE, 
                  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_AMOUNT),
            array(self::LANGUAGE_DE, "Muster AG", "", "", "", "", "", "", "", "", "2222.22")
        );
        $headerNames = QrbRecipient::parseHeader($recipientFile[0], true, true, false, false);
        return new QrbRecipient(1, $recipientFile[1], $headerNames, true, true, false, false, array("de", "fr", "it", "en"));
    }
}

?>
