<?php declare(strict_types=1);

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

use PHPUnit\Framework\TestCase;

final class QrbPdfDataEntryTest extends TestCase
{
    public function testValidateHappyDay() : void
    {
        $textAttribute = array(
            QrbPdfTextAttribute::KEY_TEXT_COLOR => 0,
            QrbPdfTextAttribute::KEY_LINE_HEIGHT => 6,
            QrbPdfTextAttribute::KEY_FONT_FAMILY => "FontFamily",
            QrbPdfTextAttribute::KEY_FONT_STYLE => "",
            QrbPdfTextAttribute::KEY_FONT_SIZE => 12
        );
        $pos = array(
            QrbPdfPosition::KEY_POS_X => 0,
            QrbPdfPosition::KEY_POS_Y => 0
        );
        $mlText = array(
            [
                QrbMultiLanguageText::KEY_LANGUAGE => QrbMultiLanguageText::DEFAULT_KEY,
                QrbMultiLanguageText::KEY_TEXT     => "Deutsch"
            ],
            [
                QrbMultiLanguageText::KEY_LANGUAGE => "en",
                QrbMultiLanguageText::KEY_TEXT     => "English"
            ]
        );
    
        $entry[QrbPdfDataEntry::KEY_NAME]           = "test";
        $entry[QrbPdfDataEntry::KEY_TEXT_ATTRIBUTE] = $textAttribute;
        $entry[QrbPdfDataEntry::KEY_POSITION]       = $pos;
        $entry[QrbPdfDataEntry::KEY_TEXT]           = $mlText;
        
        QrbPdfDataEntry::validate($entry, array("en"), "testValidateEntry");
        
        // dummy test for testdox (risky)
        $this->assertEquals("test", $entry[QrbPdfDataEntry::KEY_NAME]);
    }

    public function testConstructHappyDayAndToString() : void
    {
        $textAttribute = array(
            QrbPdfTextAttribute::KEY_TEXT_COLOR => 0,
            QrbPdfTextAttribute::KEY_LINE_HEIGHT => 6,
            QrbPdfTextAttribute::KEY_FONT_FAMILY => "FontFamily",
            QrbPdfTextAttribute::KEY_FONT_STYLE => "",
            QrbPdfTextAttribute::KEY_FONT_SIZE => 12
        );
        $pos = array(
            QrbPdfPosition::KEY_POS_X => 0,
            QrbPdfPosition::KEY_POS_Y => 0
        );
        $mlText = array(
            [
                QrbMultiLanguageText::KEY_LANGUAGE => QrbMultiLanguageText::DEFAULT_KEY,
                QrbMultiLanguageText::KEY_TEXT     => "Deutsch"
            ],
            [
                QrbMultiLanguageText::KEY_LANGUAGE => "en",
                QrbMultiLanguageText::KEY_TEXT     => "English"
            ]
        );

        $entry[QrbPdfDataEntry::KEY_NAME]           = "test";
        $entry[QrbPdfDataEntry::KEY_TEXT_ATTRIBUTE] = $textAttribute;
        $entry[QrbPdfDataEntry::KEY_POSITION]       = $pos;
        $entry[QrbPdfDataEntry::KEY_TEXT]           = $mlText;
        
        $pdEntry = new QrbPdfDataEntry($entry, array("de", "fr", "it", "en"), array("en"), "testConstructEntry");

        $this->assertEquals("test",    $pdEntry->getName());        
        $this->assertEquals(0,         $pdEntry->getTextAttribute()->getTextColor());        
        $this->assertEquals(0,         $pdEntry->getPosition()->getPosX());        
        $this->assertEquals("English", $pdEntry->getMlText()->getText("en"));        

        echo $pdEntry . "\n";
    }
}

?>
