<?php declare(strict_types=1);

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

use PHPUnit\Framework\TestCase;

final class QrbAdditionalInformationTest extends TestCase
{
    public function testValidateHappyDay() : void
    {
        $additionalInformationText = array(
            [
                QrbMultiLanguageText::KEY_LANGUAGE => QrbMultiLanguageText::DEFAULT_KEY,
                QrbMultiLanguageText::KEY_TEXT     => "Deutsch"
            ],
            [
                QrbMultiLanguageText::KEY_LANGUAGE => "en",
                QrbMultiLanguageText::KEY_TEXT     => "English"
            ]
        );
        
        $additionalInformationContents = array();
        $additionalInformationContents[QrbAdditionalInformation::KEY_ADD_INFO_TEXT] = $additionalInformationText;
        
        $additionalInformation = array();
        $additionalInformation[QrbAdditionalInformation::KEY_ADD_INFO] = $additionalInformationContents;
        QrbAdditionalInformation::validate($additionalInformation, array("en"));
        
        // dummy test for testdox (risky)
        $this->assertTrue(array_key_exists(QrbAdditionalInformation::KEY_ADD_INFO, $additionalInformation));
    }
    
    public function testValidateMissingSurroundingKey() : void
    {
        $additionalInformationText = array(
            [
                QrbMultiLanguageText::KEY_LANGUAGE => QrbMultiLanguageText::DEFAULT_KEY,
                QrbMultiLanguageText::KEY_TEXT     => "Deutsch"
            ],
            [
                QrbMultiLanguageText::KEY_LANGUAGE => "en",
                QrbMultiLanguageText::KEY_TEXT     => "English"
            ]
        );
        
        $additionalInformationContents = array();
        $additionalInformationContents[QrbAdditionalInformation::KEY_ADD_INFO_TEXT] = $additionalInformationText;
        
        $this->expectException(QrbException::class);
        QrbCreditorInformation::validate($additionalInformationContents);
    }

    public function testGetterAndToString() : void
    {
        $additionalInformationText = array(
            [
                QrbMultiLanguageText::KEY_LANGUAGE => QrbMultiLanguageText::DEFAULT_KEY,
                QrbMultiLanguageText::KEY_TEXT     => "Deutsch"
            ],
            [
                QrbMultiLanguageText::KEY_LANGUAGE => "en",
                QrbMultiLanguageText::KEY_TEXT     => "English"
            ]
        );
        
        $additionalInformationContents = array();
        $additionalInformationContents[QrbAdditionalInformation::KEY_ADD_INFO_TEXT] = $additionalInformationText;
        
        $additionalInformation = array();
        $additionalInformation[QrbAdditionalInformation::KEY_ADD_INFO] = $additionalInformationContents;
        
        $addinfo = new QrbAdditionalInformation($additionalInformation, array("de", "fr", "it", "en"), array("en"));
        $this->assertEquals("Deutsch", $addinfo->getAdditionalInformation("de"));
        $this->assertEquals("Deutsch", $addinfo->getAdditionalInformation("fr"));
        $this->assertEquals("Deutsch", $addinfo->getAdditionalInformation("it"));
        $this->assertEquals("English", $addinfo->getAdditionalInformation("en"));

        echo $addinfo . "\n";
    }
}

?>
