<?php declare(strict_types=1);

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

use PHPUnit\Framework\TestCase;

final class QrbPdfPositionTest extends TestCase
{
    public function testValidatePositionHappyDayDefault() : void
    {
        $pos = array(
            QrbPdfPosition::KEY_POS_X => 0,
            QrbPdfPosition::KEY_POS_Y => 0
        );

        QrbPdfPosition::validate($pos, "Test");

        // dummy test for testdox (risky)
        $this->assertEquals(0, $pos[QrbPdfPosition::KEY_POS_X]);
    }
    
    public function testValidatePositionHappyDay() : void
    {
        $pos = array(
            QrbPdfPosition::KEY_PAGE => 2,
            QrbPdfPosition::KEY_POS_X => 1,
            QrbPdfPosition::KEY_POS_Y => 1
        );

        QrbPdfPosition::validate($pos, "Test");

        // dummy test for testdox (risky)
        $this->assertEquals(1, $pos[QrbPdfPosition::KEY_POS_X]);
    }
    
    public function testValidatePositionMissingPosX() : void
    {
        $pos = array(
            QrbPdfPosition::KEY_POS_Y => 0
        );

        $this->expectException(QrbException::class);
        QrbPdfPosition::validate($pos, "Test");
    }
    
    public function testValidatePositionMissingPosY() : void
    {
        $pos = array(
            QrbPdfPosition::KEY_POS_X => 0
        );

        $this->expectException(QrbException::class);
        QrbPdfPosition::validate($pos, "Test");
    }
    
    public function testValidatePositionInvalidPageNotNumeric() : void
    {
        $pos = array(
            QrbPdfPosition::KEY_PAGE  => "A",
            QrbPdfPosition::KEY_POS_X => 0,
            QrbPdfPosition::KEY_POS_Y => 0
        );

        $this->expectException(QrbException::class);
        QrbPdfPosition::validate($pos, "Test");
    }
    
    public function testValidatePositionInvalidPosXNotNumeric() : void
    {
        $pos = array(
            QrbPdfPosition::KEY_POS_X => "A",
            QrbPdfPosition::KEY_POS_Y => 0
        );

        $this->expectException(QrbException::class);
        QrbPdfPosition::validate($pos, "Test");
    }
    
    public function testValidatePositionInvalidPosYNotNumeric() : void
    {
        $pos = array(
            QrbPdfPosition::KEY_POS_X => 0,
            QrbPdfPosition::KEY_POS_Y => "B"
        );

        $this->expectException(QrbException::class);
        QrbPdfPosition::validate($pos, "Test");
    }
    
    public function testConstructPositionAndCallItsGettersAndToString() : void
    {
        $pos = array(
            QrbPdfPosition::KEY_PAGE  => 1,
            QrbPdfPosition::KEY_POS_X => 2,
            QrbPdfPosition::KEY_POS_Y => 3
        );

        $p = new QrbPdfPosition($pos, "Test");
        
        $this->assertEquals(1, $p->getPage());
        $this->assertEquals(2, $p->getPosX());
        $this->assertEquals(3, $p->getPosY());
        
        echo $p . "\n";
    }
}

?>
