<?php declare(strict_types=1);

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

use PHPUnit\Framework\TestCase;

final class QrbPdfTextAttributeTest extends TestCase
{

    public function testValidateTextAttributeHappyDay() : 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
        );
        
        QrbPdfTextAttribute::validate($textAttribute, "Test");
        
        // dummy test for testdox (risky)
        $this->assertEquals(0, $textAttribute[QrbPdfTextAttribute::KEY_TEXT_COLOR]);
    }

    public function testValidateTextAttributeMissingTextColor() : void
    {
        $textAttribute = array(
            QrbPdfTextAttribute::KEY_LINE_HEIGHT => 6,
            QrbPdfTextAttribute::KEY_FONT_FAMILY => "FontFamily",
            QrbPdfTextAttribute::KEY_FONT_STYLE => "",
            QrbPdfTextAttribute::KEY_FONT_SIZE => 12
        );
        
        $this->expectException(QrbException::class);
        QrbPdfTextAttribute::validate($textAttribute, "Test");
    }

    public function testValidateTextAttributeMissingLineHeight() : void
    {
        $textAttribute = array(
            QrbPdfTextAttribute::KEY_TEXT_COLOR => 0,
            QrbPdfTextAttribute::KEY_FONT_FAMILY => "FontFamily",
            QrbPdfTextAttribute::KEY_FONT_STYLE => "",
            QrbPdfTextAttribute::KEY_FONT_SIZE => 12
        );
        
        $this->expectException(QrbException::class);
        QrbPdfTextAttribute::validate($textAttribute, "Test");
    }

    public function testValidateTextAttributeMissingFontFamily() : void
    {
        $textAttribute = array(
            QrbPdfTextAttribute::KEY_TEXT_COLOR => 0,
            QrbPdfTextAttribute::KEY_LINE_HEIGHT => 6,
            QrbPdfTextAttribute::KEY_FONT_STYLE => "",
            QrbPdfTextAttribute::KEY_FONT_SIZE => 12
        );
        
        $this->expectException(QrbException::class);
        QrbPdfTextAttribute::validate($textAttribute, "Test");
    }

    public function testValidateTextAttributeMissingFontStyle() : void
    {
        $textAttribute = array(
            QrbPdfTextAttribute::KEY_TEXT_COLOR => 0,
            QrbPdfTextAttribute::KEY_LINE_HEIGHT => 6,
            QrbPdfTextAttribute::KEY_FONT_FAMILY => "FontFamily",
            QrbPdfTextAttribute::KEY_FONT_SIZE => 12
        );
        
        $this->expectException(QrbException::class);
        QrbPdfTextAttribute::validate($textAttribute, "Test");
    }

    public function testValidateTextAttributeMissingFontSize() : void
    {
        $textAttribute = array(
            QrbPdfTextAttribute::KEY_TEXT_COLOR => 0,
            QrbPdfTextAttribute::KEY_LINE_HEIGHT => 6,
            QrbPdfTextAttribute::KEY_FONT_FAMILY => "FontFamily",
            QrbPdfTextAttribute::KEY_FONT_STYLE => ""
        );
        
        $this->expectException(QrbException::class);
        QrbPdfTextAttribute::validate($textAttribute, "Test");
    }

    public function testValidateTextAttributeInvalidTextColorNotNumeric() : void
    {
        $textAttribute = array(
            QrbPdfTextAttribute::KEY_TEXT_COLOR => "A",
            QrbPdfTextAttribute::KEY_LINE_HEIGHT => 6,
            QrbPdfTextAttribute::KEY_FONT_FAMILY => "FontFamily",
            QrbPdfTextAttribute::KEY_FONT_STYLE => "",
            QrbPdfTextAttribute::KEY_FONT_SIZE => 12
        );
        
        $this->expectException(QrbException::class);
        QrbPdfTextAttribute::validate($textAttribute, "Test");
    }

    public function testValidateTextAttributeInvalidLineHeightNotNumeric() : void
    {
        $textAttribute = array(
            QrbPdfTextAttribute::KEY_TEXT_COLOR => 0,
            QrbPdfTextAttribute::KEY_LINE_HEIGHT => "B",
            QrbPdfTextAttribute::KEY_FONT_FAMILY => "FontFamily",
            QrbPdfTextAttribute::KEY_FONT_STYLE => "",
            QrbPdfTextAttribute::KEY_FONT_SIZE => 12
        );
        
        $this->expectException(QrbException::class);
        QrbPdfTextAttribute::validate($textAttribute, "Test");
    }

    public function testValidateTextAttributeInvalidFontStyle() : void
    {
        $textAttribute = array(
            QrbPdfTextAttribute::KEY_TEXT_COLOR => 0,
            QrbPdfTextAttribute::KEY_LINE_HEIGHT => 6,
            QrbPdfTextAttribute::KEY_FONT_FAMILY => "FontFamily",
            QrbPdfTextAttribute::KEY_FONT_STYLE => "C",
            QrbPdfTextAttribute::KEY_FONT_SIZE => 12
        );
        
        $this->expectException(QrbException::class);
        QrbPdfTextAttribute::validate($textAttribute, "Test");
    }

    public function testValidateTextAttributeInvalidFontSizeNotNumeric() : 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 => "D"
        );
        
        $this->expectException(QrbException::class);
        QrbPdfTextAttribute::validate($textAttribute, "Test");
    }
    
    public function testConstructTextAttributeAndCallItsGettersAndToString() : void
    {
        $textAttribute = array(
            QrbPdfTextAttribute::KEY_TEXT_COLOR => 0,
            QrbPdfTextAttribute::KEY_LINE_HEIGHT => 6,
            QrbPdfTextAttribute::KEY_FONT_FAMILY => "FontFamily",
            QrbPdfTextAttribute::KEY_FONT_STYLE => "U",
            QrbPdfTextAttribute::KEY_FONT_SIZE => 12
        );
        
        $ta = new QrbPdfTextAttribute($textAttribute, "Test");
        
        $this->assertEquals(0, $ta->getTextColor());
        $this->assertEquals(6, $ta->getLineHeight());
        $this->assertEquals("FontFamily", $ta->getFontFamily());
        $this->assertEquals("U", $ta->getFontStyle());
        $this->assertEquals(12, $ta->getFontSize());
        
        echo $ta . "\n";
    }
}

?>
