PMCORE-3540 BE: Generate a output document using the header, footer and pagination defined
This commit is contained in:
@@ -0,0 +1,317 @@
|
||||
<?php
|
||||
|
||||
namespace ProcessMaker\PDF;
|
||||
|
||||
use Faker\Factory;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* @covers ProcessMaker\PDF\BasicStruct
|
||||
* @test
|
||||
*/
|
||||
class BasicStructTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Mock for trait test.
|
||||
* @var object
|
||||
*/
|
||||
private $mock;
|
||||
|
||||
/**
|
||||
* Object faker.
|
||||
* @var object
|
||||
*/
|
||||
private $faker;
|
||||
|
||||
/**
|
||||
* setUp method.
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->faker = Factory::create();
|
||||
$this->mock = $this->getMockForTrait('ProcessMaker\PDF\BasicStruct');
|
||||
}
|
||||
|
||||
/**
|
||||
* tearDown method.
|
||||
*/
|
||||
public function tearDown()
|
||||
{
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the getLogo method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::getLogo()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_getLogo()
|
||||
{
|
||||
$this->assertTrue(is_string($this->mock->getLogo()));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the getLogoWidth method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::getLogoWidth()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_getLogoWidth()
|
||||
{
|
||||
$this->assertTrue(is_float($this->mock->getLogoWidth()));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the getLogoPositionX method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::getLogoPositionX()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_getLogoPositionX()
|
||||
{
|
||||
$this->assertTrue(is_float($this->mock->getLogoPositionX()));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the getLogoPositionY method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::getLogoPositionY()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_getLogoPositionY()
|
||||
{
|
||||
$this->assertTrue(is_float($this->mock->getLogoPositionY()));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the getTitle method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::getTitle()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_getTitle()
|
||||
{
|
||||
$this->assertTrue(is_string($this->mock->getTitle()));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the getTitleFontSize method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::getTitleFontSize()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_getTitleFontSize()
|
||||
{
|
||||
$this->assertTrue(is_float($this->mock->getTitleFontSize()));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the getTitleFontPositionX method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::getTitleFontPositionX()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_getTitleFontPositionX()
|
||||
{
|
||||
$this->assertTrue(is_float($this->mock->getTitleFontPositionX()));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the getTitleFontPositionY method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::getTitleFontPositionY()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_getTitleFontPositionY()
|
||||
{
|
||||
$this->assertTrue(is_float($this->mock->getTitleFontPositionY()));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the getPageNumber method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::getPageNumber()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_getPageNumber()
|
||||
{
|
||||
$this->assertTrue(is_bool($this->mock->getPageNumber()));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the getPageNumberTitle method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::getPageNumberTitle()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_getPageNumberTitle()
|
||||
{
|
||||
$this->assertTrue(is_string($this->mock->getPageNumberTitle()));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the getPageNumberTotal method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::getPageNumberTotal()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_getPageNumberTotal()
|
||||
{
|
||||
$this->assertTrue(is_bool($this->mock->getPageNumberTotal()));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the getPageNumberPositionX method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::getPageNumberPositionX()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_getPageNumberPositionX()
|
||||
{
|
||||
$this->assertTrue(is_float($this->mock->getPageNumberPositionX()));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the getPageNumberPositionY method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::getPageNumberPositionY()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_getPageNumberPositionY()
|
||||
{
|
||||
$this->assertTrue(is_float($this->mock->getPageNumberPositionY()));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the setTitle method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::setTitle()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_setTitle()
|
||||
{
|
||||
$this->faker->numberBetween(400, 500);
|
||||
$this->assertEmpty($this->mock->setTitle($this->faker->title));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the setTitleFontSize method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::setTitleFontSize()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_setTitleFontSize()
|
||||
{
|
||||
$this->faker->numberBetween(400, 500);
|
||||
$this->assertEmpty($this->mock->setTitleFontSize($this->faker->randomFloat()));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the setTitleFontPositionX method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::setTitleFontPositionX()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_setTitleFontPositionX()
|
||||
{
|
||||
$this->faker->numberBetween(400, 500);
|
||||
$this->assertEmpty($this->mock->setTitleFontPositionX($this->faker->randomFloat()));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the setTitleFontPositionY method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::setTitleFontPositionY()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_setTitleFontPositionY()
|
||||
{
|
||||
$this->faker->numberBetween(400, 500);
|
||||
$this->assertEmpty($this->mock->setTitleFontPositionY($this->faker->randomFloat()));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the setLogo method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::setLogo()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_setLogo()
|
||||
{
|
||||
$this->faker->numberBetween(400, 500);
|
||||
$this->assertEmpty($this->mock->setLogo($this->faker->word));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the setLogoWidth method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::setLogoWidth()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_setLogoWidth()
|
||||
{
|
||||
$this->faker->numberBetween(400, 500);
|
||||
$this->assertEmpty($this->mock->setLogoWidth($this->faker->randomFloat()));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the setLogoPositionX method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::setLogoPositionX()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_setLogoPositionX()
|
||||
{
|
||||
$this->faker->numberBetween(400, 500);
|
||||
$this->assertEmpty($this->mock->setLogoPositionX($this->faker->randomFloat()));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the setLogoPositionY method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::setLogoPositionY()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_setLogoPositionY()
|
||||
{
|
||||
$this->faker->numberBetween(400, 500);
|
||||
$this->assertEmpty($this->mock->setLogoPositionY($this->faker->randomFloat()));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the setPageNumber method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::setPageNumber()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_setPageNumber()
|
||||
{
|
||||
$this->faker->numberBetween(400, 500);
|
||||
$this->assertEmpty($this->mock->setPageNumber($this->faker->boolean));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the setPageNumberTitle method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::setPageNumberTitle()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_setPageNumberTitle()
|
||||
{
|
||||
$this->faker->numberBetween(400, 500);
|
||||
$this->assertEmpty($this->mock->setPageNumberTitle($this->faker->title));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the setPageNumberTotal method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::setPageNumberTotal()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_setPageNumberTotal()
|
||||
{
|
||||
$this->faker->numberBetween(400, 500);
|
||||
$this->assertEmpty($this->mock->setPageNumberTotal($this->faker->boolean));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the setPageNumberPositionX method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::setPageNumberPositionX()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_setPageNumberPositionX()
|
||||
{
|
||||
$this->faker->numberBetween(400, 500);
|
||||
$this->assertEmpty($this->mock->setPageNumberPositionX($this->faker->randomFloat()));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the setPageNumberPositionY method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::setPageNumberPositionY()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_setPageNumberPositionY()
|
||||
{
|
||||
$this->faker->numberBetween(400, 500);
|
||||
$this->assertEmpty($this->mock->setPageNumberPositionY($this->faker->randomFloat()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,317 @@
|
||||
<?php
|
||||
|
||||
namespace ProcessMaker\PDF;
|
||||
|
||||
use Faker\Factory;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* @covers ProcessMaker\PDF\FooterStruct
|
||||
* @test
|
||||
*/
|
||||
class FooterStructTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* FooterStruct object.
|
||||
* @var FooterStruct
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Object faker.
|
||||
* @var object
|
||||
*/
|
||||
private $faker;
|
||||
|
||||
/**
|
||||
* setUp method.
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->faker = Factory::create();
|
||||
$this->object = new FooterStruct();
|
||||
}
|
||||
|
||||
/**
|
||||
* tearDown method.
|
||||
*/
|
||||
public function tearDown()
|
||||
{
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the getLogo method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::getLogo()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_getLogo()
|
||||
{
|
||||
$this->assertTrue(is_string($this->object->getLogo()));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the getLogoWidth method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::getLogoWidth()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_getLogoWidth()
|
||||
{
|
||||
$this->assertTrue(is_float($this->object->getLogoWidth()));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the getLogoPositionX method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::getLogoPositionX()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_getLogoPositionX()
|
||||
{
|
||||
$this->assertTrue(is_float($this->object->getLogoPositionX()));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the getLogoPositionY method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::getLogoPositionY()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_getLogoPositionY()
|
||||
{
|
||||
$this->assertTrue(is_float($this->object->getLogoPositionY()));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the getTitle method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::getTitle()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_getTitle()
|
||||
{
|
||||
$this->assertTrue(is_string($this->object->getTitle()));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the getTitleFontSize method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::getTitleFontSize()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_getTitleFontSize()
|
||||
{
|
||||
$this->assertTrue(is_float($this->object->getTitleFontSize()));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the getTitleFontPositionX method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::getTitleFontPositionX()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_getTitleFontPositionX()
|
||||
{
|
||||
$this->assertTrue(is_float($this->object->getTitleFontPositionX()));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the getTitleFontPositionY method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::getTitleFontPositionY()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_getTitleFontPositionY()
|
||||
{
|
||||
$this->assertTrue(is_float($this->object->getTitleFontPositionY()));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the getPageNumber method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::getPageNumber()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_getPageNumber()
|
||||
{
|
||||
$this->assertTrue(is_bool($this->object->getPageNumber()));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the getPageNumberTitle method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::getPageNumberTitle()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_getPageNumberTitle()
|
||||
{
|
||||
$this->assertTrue(is_string($this->object->getPageNumberTitle()));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the getPageNumberTotal method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::getPageNumberTotal()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_getPageNumberTotal()
|
||||
{
|
||||
$this->assertTrue(is_bool($this->object->getPageNumberTotal()));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the getPageNumberPositionX method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::getPageNumberPositionX()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_getPageNumberPositionX()
|
||||
{
|
||||
$this->assertTrue(is_float($this->object->getPageNumberPositionX()));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the getPageNumberPositionY method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::getPageNumberPositionY()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_getPageNumberPositionY()
|
||||
{
|
||||
$this->assertTrue(is_float($this->object->getPageNumberPositionY()));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the setTitle method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::setTitle()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_setTitle()
|
||||
{
|
||||
$this->faker->numberBetween(400, 500);
|
||||
$this->assertEmpty($this->object->setTitle($this->faker->title));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the setTitleFontSize method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::setTitleFontSize()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_setTitleFontSize()
|
||||
{
|
||||
$this->faker->numberBetween(400, 500);
|
||||
$this->assertEmpty($this->object->setTitleFontSize($this->faker->randomFloat()));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the setTitleFontPositionX method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::setTitleFontPositionX()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_setTitleFontPositionX()
|
||||
{
|
||||
$this->faker->numberBetween(400, 500);
|
||||
$this->assertEmpty($this->object->setTitleFontPositionX($this->faker->randomFloat()));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the setTitleFontPositionY method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::setTitleFontPositionY()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_setTitleFontPositionY()
|
||||
{
|
||||
$this->faker->numberBetween(400, 500);
|
||||
$this->assertEmpty($this->object->setTitleFontPositionY($this->faker->randomFloat()));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the setLogo method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::setLogo()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_setLogo()
|
||||
{
|
||||
$this->faker->numberBetween(400, 500);
|
||||
$this->assertEmpty($this->object->setLogo($this->faker->word));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the setLogoWidth method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::setLogoWidth()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_setLogoWidth()
|
||||
{
|
||||
$this->faker->numberBetween(400, 500);
|
||||
$this->assertEmpty($this->object->setLogoWidth($this->faker->randomFloat()));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the setLogoPositionX method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::setLogoPositionX()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_setLogoPositionX()
|
||||
{
|
||||
$this->faker->numberBetween(400, 500);
|
||||
$this->assertEmpty($this->object->setLogoPositionX($this->faker->randomFloat()));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the setLogoPositionY method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::setLogoPositionY()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_setLogoPositionY()
|
||||
{
|
||||
$this->faker->numberBetween(400, 500);
|
||||
$this->assertEmpty($this->object->setLogoPositionY($this->faker->randomFloat()));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the setPageNumber method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::setPageNumber()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_setPageNumber()
|
||||
{
|
||||
$this->faker->numberBetween(400, 500);
|
||||
$this->assertEmpty($this->object->setPageNumber($this->faker->boolean));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the setPageNumberTitle method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::setPageNumberTitle()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_setPageNumberTitle()
|
||||
{
|
||||
$this->faker->numberBetween(400, 500);
|
||||
$this->assertEmpty($this->object->setPageNumberTitle($this->faker->title));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the setPageNumberTotal method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::setPageNumberTotal()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_setPageNumberTotal()
|
||||
{
|
||||
$this->faker->numberBetween(400, 500);
|
||||
$this->assertEmpty($this->object->setPageNumberTotal($this->faker->boolean));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the setPageNumberPositionX method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::setPageNumberPositionX()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_setPageNumberPositionX()
|
||||
{
|
||||
$this->faker->numberBetween(400, 500);
|
||||
$this->assertEmpty($this->object->setPageNumberPositionX($this->faker->randomFloat()));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the setPageNumberPositionY method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::setPageNumberPositionY()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_setPageNumberPositionY()
|
||||
{
|
||||
$this->faker->numberBetween(400, 500);
|
||||
$this->assertEmpty($this->object->setPageNumberPositionY($this->faker->randomFloat()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,311 @@
|
||||
<?php
|
||||
|
||||
namespace ProcessMaker\PDF;
|
||||
|
||||
use Faker\Factory;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* @covers ProcessMaker\PDF\HeaderStruct
|
||||
* @test
|
||||
*/
|
||||
class HeaderStructTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* HeaderStruct object.
|
||||
* @var HeaderStruct
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* setUp method.
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->faker = Factory::create();
|
||||
$this->object = new HeaderStruct();
|
||||
}
|
||||
|
||||
/**
|
||||
* tearDown method.
|
||||
*/
|
||||
public function tearDown()
|
||||
{
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the getLogo method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::getLogo()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_getLogo()
|
||||
{
|
||||
$this->assertTrue(is_string($this->object->getLogo()));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the getLogoWidth method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::getLogoWidth()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_getLogoWidth()
|
||||
{
|
||||
$this->assertTrue(is_float($this->object->getLogoWidth()));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the getLogoPositionX method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::getLogoPositionX()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_getLogoPositionX()
|
||||
{
|
||||
$this->assertTrue(is_float($this->object->getLogoPositionX()));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the getLogoPositionY method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::getLogoPositionY()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_getLogoPositionY()
|
||||
{
|
||||
$this->assertTrue(is_float($this->object->getLogoPositionY()));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the getTitle method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::getTitle()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_getTitle()
|
||||
{
|
||||
$this->assertTrue(is_string($this->object->getTitle()));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the getTitleFontSize method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::getTitleFontSize()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_getTitleFontSize()
|
||||
{
|
||||
$this->assertTrue(is_float($this->object->getTitleFontSize()));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the getTitleFontPositionX method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::getTitleFontPositionX()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_getTitleFontPositionX()
|
||||
{
|
||||
$this->assertTrue(is_float($this->object->getTitleFontPositionX()));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the getTitleFontPositionY method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::getTitleFontPositionY()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_getTitleFontPositionY()
|
||||
{
|
||||
$this->assertTrue(is_float($this->object->getTitleFontPositionY()));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the getPageNumber method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::getPageNumber()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_getPageNumber()
|
||||
{
|
||||
$this->assertTrue(is_bool($this->object->getPageNumber()));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the getPageNumberTitle method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::getPageNumberTitle()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_getPageNumberTitle()
|
||||
{
|
||||
$this->assertTrue(is_string($this->object->getPageNumberTitle()));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the getPageNumberTotal method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::getPageNumberTotal()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_getPageNumberTotal()
|
||||
{
|
||||
$this->assertTrue(is_bool($this->object->getPageNumberTotal()));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the getPageNumberPositionX method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::getPageNumberPositionX()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_getPageNumberPositionX()
|
||||
{
|
||||
$this->assertTrue(is_float($this->object->getPageNumberPositionX()));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the getPageNumberPositionY method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::getPageNumberPositionY()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_getPageNumberPositionY()
|
||||
{
|
||||
$this->assertTrue(is_float($this->object->getPageNumberPositionY()));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the setTitle method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::setTitle()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_setTitle()
|
||||
{
|
||||
$this->faker->numberBetween(400, 500);
|
||||
$this->assertEmpty($this->object->setTitle($this->faker->title));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the setTitleFontSize method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::setTitleFontSize()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_setTitleFontSize()
|
||||
{
|
||||
$this->faker->numberBetween(400, 500);
|
||||
$this->assertEmpty($this->object->setTitleFontSize($this->faker->randomFloat()));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the setTitleFontPositionX method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::setTitleFontPositionX()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_setTitleFontPositionX()
|
||||
{
|
||||
$this->faker->numberBetween(400, 500);
|
||||
$this->assertEmpty($this->object->setTitleFontPositionX($this->faker->randomFloat()));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the setTitleFontPositionY method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::setTitleFontPositionY()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_setTitleFontPositionY()
|
||||
{
|
||||
$this->faker->numberBetween(400, 500);
|
||||
$this->assertEmpty($this->object->setTitleFontPositionY($this->faker->randomFloat()));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the setLogo method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::setLogo()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_setLogo()
|
||||
{
|
||||
$this->faker->numberBetween(400, 500);
|
||||
$this->assertEmpty($this->object->setLogo($this->faker->word));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the setLogoWidth method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::setLogoWidth()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_setLogoWidth()
|
||||
{
|
||||
$this->faker->numberBetween(400, 500);
|
||||
$this->assertEmpty($this->object->setLogoWidth($this->faker->randomFloat()));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the setLogoPositionX method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::setLogoPositionX()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_setLogoPositionX()
|
||||
{
|
||||
$this->faker->numberBetween(400, 500);
|
||||
$this->assertEmpty($this->object->setLogoPositionX($this->faker->randomFloat()));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the setLogoPositionY method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::setLogoPositionY()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_setLogoPositionY()
|
||||
{
|
||||
$this->faker->numberBetween(400, 500);
|
||||
$this->assertEmpty($this->object->setLogoPositionY($this->faker->randomFloat()));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the setPageNumber method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::setPageNumber()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_setPageNumber()
|
||||
{
|
||||
$this->faker->numberBetween(400, 500);
|
||||
$this->assertEmpty($this->object->setPageNumber($this->faker->boolean));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the setPageNumberTitle method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::setPageNumberTitle()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_setPageNumberTitle()
|
||||
{
|
||||
$this->faker->numberBetween(400, 500);
|
||||
$this->assertEmpty($this->object->setPageNumberTitle($this->faker->title));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the setPageNumberTotal method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::setPageNumberTotal()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_setPageNumberTotal()
|
||||
{
|
||||
$this->faker->numberBetween(400, 500);
|
||||
$this->assertEmpty($this->object->setPageNumberTotal($this->faker->boolean));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the setPageNumberPositionX method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::setPageNumberPositionX()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_setPageNumberPositionX()
|
||||
{
|
||||
$this->faker->numberBetween(400, 500);
|
||||
$this->assertEmpty($this->object->setPageNumberPositionX($this->faker->randomFloat()));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the setPageNumberPositionY method.
|
||||
* @covers ProcessMaker\PDF\BasicStruct::setPageNumberPositionY()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_method_setPageNumberPositionY()
|
||||
{
|
||||
$this->faker->numberBetween(400, 500);
|
||||
$this->assertEmpty($this->object->setPageNumberPositionY($this->faker->randomFloat()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,173 @@
|
||||
<?php
|
||||
|
||||
namespace ProcessMaker\PDF;
|
||||
|
||||
use stdClass;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* @covers ProcessMaker\PDF\TCPDFHeaderFooter
|
||||
* @test
|
||||
*/
|
||||
class TCPDFHeaderFooterTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* TCPDFHeaderFooter object.
|
||||
* @var TCPDFHeaderFooter
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* setUp method.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->object = new TCPDFHeaderFooter('P', PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
|
||||
$this->object->SetCreator(PDF_CREATOR);
|
||||
$this->object->SetAuthor('admin');
|
||||
$this->object->SetTitle('test');
|
||||
$this->object->SetSubject('test.pdf');
|
||||
$this->object->SetCompression(true);
|
||||
$this->setHeaderData();
|
||||
$this->setFooterData();
|
||||
}
|
||||
|
||||
/**
|
||||
* tearDown method.
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Setting data for header configuration.
|
||||
*/
|
||||
private function setHeaderData()
|
||||
{
|
||||
$header = new stdClass();
|
||||
$header->logo = PATH_TRUNK . "/vendor/tecnickcom/tcpdf/examples/images/logo_example.jpg";
|
||||
$header->logoWidth = 10;
|
||||
$header->logoPositionX = 50;
|
||||
$header->logoPositionY = 0;
|
||||
$header->title = "Test1 Test1";
|
||||
$header->titleFontSize = 60;
|
||||
$header->titleFontPositionX = 10;
|
||||
$header->titleFontPositionY = 0;
|
||||
$header->pageNumber = true;
|
||||
$header->pageNumberTitle = "Pages";
|
||||
$header->pageNumberTotal = true;
|
||||
$header->pageNumberPositionX = 10;
|
||||
$header->pageNumberPositionY = 0;
|
||||
|
||||
$struct = $this->object->getHeaderStruct();
|
||||
$struct->setLogo($header->logo);
|
||||
$struct->setLogoWidth($header->logoWidth);
|
||||
$struct->setLogoPositionX($header->logoPositionX);
|
||||
$struct->setLogoPositionY($header->logoPositionY);
|
||||
|
||||
$struct->setTitle($header->title);
|
||||
$struct->setTitleFontSize($header->titleFontSize);
|
||||
$struct->setTitleFontPositionX($header->titleFontPositionX);
|
||||
$struct->setTitleFontPositionY($header->titleFontPositionY);
|
||||
|
||||
$struct->setPageNumber($header->pageNumber);
|
||||
$struct->setPageNumberTitle($header->pageNumberTitle);
|
||||
$struct->setPageNumberTotal($header->pageNumberTotal);
|
||||
$struct->setPageNumberPositionX($header->pageNumberPositionX);
|
||||
$struct->setPageNumberPositionY($header->pageNumberPositionY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Setting data for footer configuration.
|
||||
*/
|
||||
private function setFooterData()
|
||||
{
|
||||
$footer = new stdClass();
|
||||
$footer->logo = PATH_TRUNK . "/vendor/tecnickcom/tcpdf/examples/images/logo_example.jpg";
|
||||
$footer->logoWidth = 15;
|
||||
$footer->logoPositionX = 10;
|
||||
$footer->logoPositionY = 0;
|
||||
$footer->title = "Hola mundo como estas";
|
||||
$footer->titleFontSize = 20;
|
||||
$footer->titleFontPositionX = 0;
|
||||
$footer->titleFontPositionY = 5;
|
||||
$footer->pageNumber = true;
|
||||
$footer->pageNumberTitle = "Pages";
|
||||
$footer->pageNumberTotal = true;
|
||||
$footer->pageNumberPositionX = 40;
|
||||
$footer->pageNumberPositionY = 5;
|
||||
|
||||
$struct = $this->object->getFooterStruct();
|
||||
$struct->setLogo($footer->logo);
|
||||
$struct->setLogoWidth($footer->logoWidth);
|
||||
$struct->setLogoPositionX($footer->logoPositionX);
|
||||
$struct->setLogoPositionY($footer->logoPositionY);
|
||||
|
||||
$struct->setTitle($footer->title);
|
||||
$struct->setTitleFontSize($footer->titleFontSize);
|
||||
$struct->setTitleFontPositionX($footer->titleFontPositionX);
|
||||
$struct->setTitleFontPositionY($footer->titleFontPositionY);
|
||||
|
||||
$struct->setPageNumber($footer->pageNumber);
|
||||
$struct->setPageNumberTitle($footer->pageNumberTitle);
|
||||
$struct->setPageNumberTotal($footer->pageNumberTotal);
|
||||
$struct->setPageNumberPositionX($footer->pageNumberPositionX);
|
||||
$struct->setPageNumberPositionY($footer->pageNumberPositionY);
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the getHeaderStruct() method.
|
||||
* @covers ProcessMaker\PDF\TCPDFHeaderFooter::getHeaderStruct()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_getHeaderStruct()
|
||||
{
|
||||
$result = $this->object->getHeaderStruct();
|
||||
$this->assertNotNull($result);
|
||||
$this->assertEquals(HeaderStruct::class, get_class($result));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the getFooterStruct() method.
|
||||
* @covers ProcessMaker\PDF\TCPDFHeaderFooter::getFooterStruct()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_getFooterStruct()
|
||||
{
|
||||
$result = $this->object->getFooterStruct();
|
||||
$this->assertNotNull($result);
|
||||
$this->assertEquals(FooterStruct::class, get_class($result));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the Header() method override.
|
||||
* @covers ProcessMaker\PDF\TCPDFHeaderFooter::Header()
|
||||
* @covers ProcessMaker\PDF\TCPDFHeaderFooter::buildHeaderLogo()
|
||||
* @covers ProcessMaker\PDF\TCPDFHeaderFooter::buildHeaderTitle()
|
||||
* @covers ProcessMaker\PDF\TCPDFHeaderFooter::buildHeaderPageNumber()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_Header()
|
||||
{
|
||||
$this->object->AddPage();
|
||||
$result = $this->object->Header();
|
||||
$this->assertEmpty($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ProcessMaker\PDF\TCPDFHeaderFooter::Footer()
|
||||
* @covers ProcessMaker\PDF\TCPDFHeaderFooter::buildFooterLogo()
|
||||
* @covers ProcessMaker\PDF\TCPDFHeaderFooter::buildFooterTitle()
|
||||
* @covers ProcessMaker\PDF\TCPDFHeaderFooter::buildFooterPageNumber()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_Footer()
|
||||
{
|
||||
$this->object->AddPage();
|
||||
$result = $this->object->Footer();
|
||||
$this->assertEmpty($result);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
use Illuminate\Filesystem\Filesystem;
|
||||
use ProcessMaker\Core\System;
|
||||
use ProcessMaker\PDF\TCPDFHeaderFooter;
|
||||
|
||||
class OutputDocument extends BaseOutputDocument
|
||||
{
|
||||
@@ -879,7 +880,7 @@ class OutputDocument extends BaseOutputDocument
|
||||
$content = str_replace("margin-left", "text-indent", $content);
|
||||
|
||||
// Instance the TCPDF library
|
||||
$pdf = new TCPDF($orientation, PDF_UNIT, $media, true, 'UTF-8', false);
|
||||
$pdf = new TCPDFHeaderFooter($orientation, PDF_UNIT, $media, true, 'UTF-8', false);
|
||||
|
||||
// Set document information
|
||||
$pdf->SetCreator(PDF_CREATOR);
|
||||
@@ -896,8 +897,10 @@ class OutputDocument extends BaseOutputDocument
|
||||
$margins["bottom"] = ($margins["bottom"] >= 0) ? $margins["bottom"] : PDF_MARGIN_BOTTOM;
|
||||
|
||||
// Set margins configuration
|
||||
$pdf->setPrintHeader(false);
|
||||
$pdf->setPrintFooter(false);
|
||||
$headerOptions = $this->setHeaderOptions($pdf);
|
||||
$footerOptions = $this->setFooterOptions($pdf);
|
||||
$pdf->setPrintHeader($headerOptions);
|
||||
$pdf->setPrintFooter($footerOptions);
|
||||
$pdf->SetLeftMargin($margins['left']);
|
||||
$pdf->SetTopMargin($margins['top']);
|
||||
$pdf->SetRightMargin($margins['right']);
|
||||
@@ -1362,4 +1365,68 @@ class OutputDocument extends BaseOutputDocument
|
||||
// Save the CSS file
|
||||
file_put_contents(K_PATH_FONTS . 'fonts.css', $css);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set and build if header options exist.
|
||||
* @param TCPDFHeaderFooter $pdf
|
||||
* @return bool
|
||||
*/
|
||||
private function setHeaderOptions(TCPDFHeaderFooter $pdf): bool
|
||||
{
|
||||
if (empty($this->out_doc_header)) {
|
||||
return false;
|
||||
}
|
||||
$header = json_decode($this->out_doc_header);
|
||||
|
||||
$struct = $pdf->getHeaderStruct();
|
||||
|
||||
$struct->setLogo($header->logo);
|
||||
$struct->setLogoWidth($header->logoWidth);
|
||||
$struct->setLogoPositionX($header->logoPositionX);
|
||||
$struct->setLogoPositionY($header->logoPositionY);
|
||||
|
||||
$struct->setTitle($header->title);
|
||||
$struct->setTitleFontSize($header->titleFontSize);
|
||||
$struct->setTitleFontPositionX($header->titleFontPositionX);
|
||||
$struct->setTitleFontPositionY($header->titleFontPositionY);
|
||||
|
||||
$struct->setPageNumber($header->pageNumber);
|
||||
$struct->setPageNumberTitle($header->pageNumberTitle);
|
||||
$struct->setPageNumberTotal($header->pageNumberTotal);
|
||||
$struct->setPageNumberPositionX($header->pageNumberPositionX);
|
||||
$struct->setPageNumberPositionY($header->pageNumberPositionY);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set and build if footer options exist.
|
||||
* @param TCPDFHeaderFooter $pdf
|
||||
* @return bool
|
||||
*/
|
||||
private function setFooterOptions(TCPDFHeaderFooter $pdf): bool
|
||||
{
|
||||
if (empty($this->out_doc_footer)) {
|
||||
return false;
|
||||
}
|
||||
$footer = json_decode($this->out_doc_footer);
|
||||
|
||||
$struct = $pdf->getFooterStruct();
|
||||
|
||||
$struct->setLogo($footer->logo);
|
||||
$struct->setLogoWidth($footer->logoWidth);
|
||||
$struct->setLogoPositionX($footer->logoPositionX);
|
||||
$struct->setLogoPositionY($footer->logoPositionY);
|
||||
|
||||
$struct->setTitle($footer->title);
|
||||
$struct->setTitleFontSize($footer->titleFontSize);
|
||||
$struct->setTitleFontPositionX($footer->titleFontPositionX);
|
||||
$struct->setTitleFontPositionY($footer->titleFontPositionY);
|
||||
|
||||
$struct->setPageNumber($footer->pageNumber);
|
||||
$struct->setPageNumberTitle($footer->pageNumberTitle);
|
||||
$struct->setPageNumberTotal($footer->pageNumberTotal);
|
||||
$struct->setPageNumberPositionX($footer->pageNumberPositionX);
|
||||
$struct->setPageNumberPositionY($footer->pageNumberPositionY);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
336
workflow/engine/src/ProcessMaker/PDF/BasicStruct.php
Normal file
336
workflow/engine/src/ProcessMaker/PDF/BasicStruct.php
Normal file
@@ -0,0 +1,336 @@
|
||||
<?php
|
||||
|
||||
namespace ProcessMaker\PDF;
|
||||
|
||||
/**
|
||||
* Struct for header and footer configuration.
|
||||
*/
|
||||
trait BasicStruct
|
||||
{
|
||||
/**
|
||||
* Path to image file.
|
||||
* @var string
|
||||
*/
|
||||
private $logo = '';
|
||||
|
||||
/**
|
||||
* Width to image file, the height is calculated automatically proportional
|
||||
* to the original dimensions.
|
||||
* @var float
|
||||
*/
|
||||
private $logoWidth = 0;
|
||||
|
||||
/**
|
||||
* Position of the image with respect to the ordinate X since left margin.
|
||||
* @var float
|
||||
*/
|
||||
private $logoPositionX = 0;
|
||||
|
||||
/**
|
||||
* Position of the image with respect to the ordinate Y since top margin.
|
||||
* @var float
|
||||
*/
|
||||
private $logoPositionY = 0;
|
||||
|
||||
/**
|
||||
* Title of the page.
|
||||
* @var string
|
||||
*/
|
||||
private $title = '';
|
||||
|
||||
/**
|
||||
* Font size of the title.
|
||||
* @var float
|
||||
*/
|
||||
private $titleFontSize = 0;
|
||||
|
||||
/**
|
||||
* Position of the title with respect to the ordinate X since left margin.
|
||||
* @var float
|
||||
*/
|
||||
private $titleFontPositionX = 0;
|
||||
|
||||
/**
|
||||
* Position of the title with respect to the ordinate Y since top margin.
|
||||
* @var float
|
||||
*/
|
||||
private $titleFontPositionY = 0;
|
||||
|
||||
/**
|
||||
* Indicates if the page number is displayed.
|
||||
* @var bool
|
||||
*/
|
||||
private $pageNumber = false;
|
||||
|
||||
/**
|
||||
* Alternative text to indicate the numbered page.
|
||||
* @var string
|
||||
*/
|
||||
private $pageNumberTitle = '';
|
||||
|
||||
/**
|
||||
* Indicates if the pages total is displayed.
|
||||
* @var bool
|
||||
*/
|
||||
private $pageNumberTotal = false;
|
||||
|
||||
/**
|
||||
* Position of the page number with respect to the ordinate X since left margin.
|
||||
* @var float
|
||||
*/
|
||||
private $pageNumberPositionX = 0;
|
||||
|
||||
/**
|
||||
* Position of the page number with respect to the ordinate Y since bottom margin.
|
||||
* @var float
|
||||
*/
|
||||
private $pageNumberPositionY = 0;
|
||||
|
||||
/**
|
||||
* Get logo property.
|
||||
* @return string
|
||||
*/
|
||||
public function getLogo(): string
|
||||
{
|
||||
return $this->logo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get logoWidth property.
|
||||
* @return float
|
||||
*/
|
||||
public function getLogoWidth(): float
|
||||
{
|
||||
return $this->logoWidth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get logoPositionX property.
|
||||
* @return float
|
||||
*/
|
||||
public function getLogoPositionX(): float
|
||||
{
|
||||
return $this->logoPositionX;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get logoPositionY property.
|
||||
* @return float
|
||||
*/
|
||||
public function getLogoPositionY(): float
|
||||
{
|
||||
return $this->logoPositionY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get title property.
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle(): string
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get titleFontSize property.
|
||||
* @return float
|
||||
*/
|
||||
public function getTitleFontSize(): float
|
||||
{
|
||||
return $this->titleFontSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get titleFontPositionX property.
|
||||
* @return float
|
||||
*/
|
||||
public function getTitleFontPositionX(): float
|
||||
{
|
||||
return $this->titleFontPositionX;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get titleFontPositionY property.
|
||||
* @return float
|
||||
*/
|
||||
public function getTitleFontPositionY(): float
|
||||
{
|
||||
return $this->titleFontPositionY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get pageNumber property.
|
||||
* @return bool
|
||||
*/
|
||||
public function getPageNumber(): bool
|
||||
{
|
||||
return $this->pageNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get pageNumberTitle property.
|
||||
* @return string
|
||||
*/
|
||||
public function getPageNumberTitle(): string
|
||||
{
|
||||
return $this->pageNumberTitle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get pageNumberTotal property.
|
||||
* @return bool
|
||||
*/
|
||||
public function getPageNumberTotal(): bool
|
||||
{
|
||||
return $this->pageNumberTotal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get pageNumberPositionX property.
|
||||
* @return float
|
||||
*/
|
||||
public function getPageNumberPositionX(): float
|
||||
{
|
||||
return $this->pageNumberPositionX;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get pageNumberPositionY property.
|
||||
* @return float
|
||||
*/
|
||||
public function getPageNumberPositionY(): float
|
||||
{
|
||||
return $this->pageNumberPositionY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set property title.
|
||||
* @param string $title
|
||||
* @return void
|
||||
*/
|
||||
public function setTitle(string $title): void
|
||||
{
|
||||
$this->title = $title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set property titleFontSize.
|
||||
* @param float $titleFontSize
|
||||
* @return void
|
||||
*/
|
||||
public function setTitleFontSize(float $titleFontSize): void
|
||||
{
|
||||
$this->titleFontSize = $titleFontSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set property titleFontPositionX.
|
||||
* @param float $titleFontPositionX
|
||||
* @return void
|
||||
*/
|
||||
public function setTitleFontPositionX(float $titleFontPositionX): void
|
||||
{
|
||||
$this->titleFontPositionX = $titleFontPositionX;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set property titleFontPositionY.
|
||||
* @param float $titleFontPositionY
|
||||
* @return void
|
||||
*/
|
||||
public function setTitleFontPositionY(float $titleFontPositionY): void
|
||||
{
|
||||
$this->titleFontPositionY = $titleFontPositionY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set property logo.
|
||||
* @param string $logo
|
||||
* @return void
|
||||
*/
|
||||
public function setLogo(string $logo): void
|
||||
{
|
||||
$this->logo = $logo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set property logoWidth.
|
||||
* @param float $logoWidth
|
||||
* @return void
|
||||
*/
|
||||
public function setLogoWidth(float $logoWidth): void
|
||||
{
|
||||
$this->logoWidth = $logoWidth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set property logoPositionX.
|
||||
* @param float $logoPositionX
|
||||
* @return void
|
||||
*/
|
||||
public function setLogoPositionX(float $logoPositionX): void
|
||||
{
|
||||
$this->logoPositionX = $logoPositionX;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set property logoPositionY.
|
||||
* @param float $logoPositionY
|
||||
* @return void
|
||||
*/
|
||||
public function setLogoPositionY(float $logoPositionY): void
|
||||
{
|
||||
$this->logoPositionY = $logoPositionY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set property pageNumber.
|
||||
* @param bool $pageNumber
|
||||
* @return void
|
||||
*/
|
||||
public function setPageNumber(bool $pageNumber): void
|
||||
{
|
||||
$this->pageNumber = $pageNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set property pageNumberTitle.
|
||||
* @param string $pageNumberTitle
|
||||
* @return void
|
||||
*/
|
||||
public function setPageNumberTitle(string $pageNumberTitle): void
|
||||
{
|
||||
$this->pageNumberTitle = $pageNumberTitle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set property pageNumberTotal.
|
||||
* @param bool $pageNumberTotal
|
||||
* @return void
|
||||
*/
|
||||
public function setPageNumberTotal(bool $pageNumberTotal): void
|
||||
{
|
||||
$this->pageNumberTotal = $pageNumberTotal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set property pageNumberPositionX.
|
||||
* @param float $pageNumberPositionX
|
||||
* @return void
|
||||
*/
|
||||
public function setPageNumberPositionX(float $pageNumberPositionX): void
|
||||
{
|
||||
$this->pageNumberPositionX = $pageNumberPositionX;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set property pageNumberPositionY.
|
||||
* @param float $pageNumberPositionY
|
||||
* @return void
|
||||
*/
|
||||
public function setPageNumberPositionY(float $pageNumberPositionY): void
|
||||
{
|
||||
$this->pageNumberPositionY = $pageNumberPositionY;
|
||||
}
|
||||
|
||||
}
|
||||
11
workflow/engine/src/ProcessMaker/PDF/FooterStruct.php
Normal file
11
workflow/engine/src/ProcessMaker/PDF/FooterStruct.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace ProcessMaker\PDF;
|
||||
|
||||
class FooterStruct
|
||||
{
|
||||
/**
|
||||
* Using basic struct for footer properties.
|
||||
*/
|
||||
use BasicStruct;
|
||||
}
|
||||
11
workflow/engine/src/ProcessMaker/PDF/HeaderStruct.php
Normal file
11
workflow/engine/src/ProcessMaker/PDF/HeaderStruct.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace ProcessMaker\PDF;
|
||||
|
||||
class HeaderStruct
|
||||
{
|
||||
/**
|
||||
* Using basic struct for header properties.
|
||||
*/
|
||||
use BasicStruct;
|
||||
}
|
||||
242
workflow/engine/src/ProcessMaker/PDF/TCPDFHeaderFooter.php
Normal file
242
workflow/engine/src/ProcessMaker/PDF/TCPDFHeaderFooter.php
Normal file
@@ -0,0 +1,242 @@
|
||||
<?php
|
||||
|
||||
namespace ProcessMaker\PDF;
|
||||
|
||||
use TCPDF;
|
||||
|
||||
class TCPDFHeaderFooter extends TCPDF
|
||||
{
|
||||
/**
|
||||
* Property for configure header element.
|
||||
* @var HeaderStruct
|
||||
*/
|
||||
private $headerStruct;
|
||||
|
||||
/**
|
||||
* Property for configure footer element.
|
||||
* @var FooterStruct
|
||||
*/
|
||||
private $footerStruct;
|
||||
|
||||
/**
|
||||
* Save the original margins configured in the page.
|
||||
* @var array
|
||||
*/
|
||||
private $originalMargins;
|
||||
|
||||
/**
|
||||
* Constructor of the class.
|
||||
* @param string $orientation
|
||||
* @param string $unit
|
||||
* @param string $format
|
||||
* @param bool $unicode
|
||||
* @param string $encoding
|
||||
* @param bool $diskcache
|
||||
* @param bool $pdfa
|
||||
*/
|
||||
public function __construct($orientation = 'P', $unit = 'mm', $format = 'A4', $unicode = true, $encoding = 'UTF-8', $diskcache = false, $pdfa = false)
|
||||
{
|
||||
parent::__construct($orientation, $unit, $format, $unicode, $encoding, $diskcache, $pdfa);
|
||||
$this->headerStruct = new HeaderStruct();
|
||||
$this->footerStruct = new FooterStruct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor of the class.
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
parent::__destruct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an object that contains the properties of the header.
|
||||
* @return HeaderStruct
|
||||
*/
|
||||
public function getHeaderStruct(): HeaderStruct
|
||||
{
|
||||
return $this->headerStruct;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an object that contains the properties of the footer.
|
||||
* @return FooterStruct
|
||||
*/
|
||||
public function getFooterStruct(): FooterStruct
|
||||
{
|
||||
return $this->footerStruct;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is used to render the page header.
|
||||
* This method has been overwritten.
|
||||
*/
|
||||
public function Header()
|
||||
{
|
||||
$heights = [];
|
||||
$struct = $this->getHeaderStruct();
|
||||
|
||||
if (empty($this->originalMargins)) {
|
||||
$this->originalMargins = $this->getMargins();
|
||||
}
|
||||
$margins = $this->originalMargins;
|
||||
|
||||
$this->buildHeaderLogo($struct, $margins, $heights);
|
||||
$this->buildHeaderTitle($struct, $margins, $heights);
|
||||
$this->buildHeaderPageNumber($struct, $margins, $heights);
|
||||
|
||||
//page adjust
|
||||
$newHeight = max($heights);
|
||||
$this->SetTopMargin($newHeight);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build header logo.
|
||||
* @param HeaderStruct $struct
|
||||
* @param array $margins
|
||||
* @param array $heights
|
||||
* @return void
|
||||
*/
|
||||
private function buildHeaderLogo(HeaderStruct $struct, array $margins, array &$heights): void
|
||||
{
|
||||
$path = $struct->getLogo();
|
||||
if (!file_exists($path)) {
|
||||
return;
|
||||
}
|
||||
$pathinfo = pathinfo($path);
|
||||
$imageSize = getimagesize($path);
|
||||
$extension = $pathinfo['extension'];
|
||||
$x = $struct->getLogoPositionX() + $margins['left'];
|
||||
$y = $struct->getLogoPositionY() + $margins['top'];
|
||||
$width = $struct->getLogoWidth();
|
||||
$this->Image($path, $x, $y, $width, 0, $extension, '', '', false, 300, '', false, false, 0, false, false, false);
|
||||
$newImageHeight = ($width * $imageSize[0] / $imageSize[1]);
|
||||
$heights[] = $margins['top'] + $newImageHeight;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build header title.
|
||||
* @param HeaderStruct $struct
|
||||
* @param array $margins
|
||||
* @param array $heights
|
||||
* @return void
|
||||
*/
|
||||
private function buildHeaderTitle(HeaderStruct $struct, array $margins, array &$heights): void
|
||||
{
|
||||
$string = $struct->getTitle();
|
||||
$x = $struct->getTitleFontPositionX() + $margins['left'];
|
||||
$y = $struct->getTitleFontPositionY() + $margins['top'];
|
||||
$fontSize = $struct->getTitleFontSize();
|
||||
$this->SetXY($x, $y);
|
||||
$this->SetFont('helvetica', 'B', $fontSize);
|
||||
$this->MultiCell(0, 0, $string, 0, 'L', false, 1, '', '', true, 0, false, true, 0, 'T', false);
|
||||
$heights[] = $margins['top'] + ($this->getCellHeight($fontSize, false)) / 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build header page number.
|
||||
* @param HeaderStruct $struct
|
||||
* @param array $margins
|
||||
* @param array $heights
|
||||
* @return void
|
||||
*/
|
||||
private function buildHeaderPageNumber(HeaderStruct $struct, array $margins, array &$heights): void
|
||||
{
|
||||
if ($struct->getPageNumber() === true) {
|
||||
$pageString = empty($struct->getPageNumberTitle()) ? 'Page ' : $struct->getPageNumberTitle() . ' ';
|
||||
$pageNumberTotal = $struct->getPageNumberTotal() === true ? ' / ' . $this->getAliasNbPages() : '';
|
||||
$string = $pageString . $this->getAliasNumPage() . $pageNumberTotal;
|
||||
$x = $struct->getPageNumberPositionX() + $margins['left'];
|
||||
$y = $struct->getPageNumberPositionY() + $margins['top'];
|
||||
$fontSize = 8;
|
||||
$this->SetXY($x, $y);
|
||||
$this->SetFont('helvetica', 'I', $fontSize);
|
||||
$this->Cell(0, 0, $string, 0, 0, '', false, '', 0, false, 'T', 'M');
|
||||
$heights[] = $margins['top'] + ($this->getCellHeight($fontSize, false)) / 2;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is used to render the page footer.
|
||||
* This method has been overwritten.
|
||||
*/
|
||||
public function Footer()
|
||||
{
|
||||
$struct = $this->getFooterStruct();
|
||||
|
||||
if (empty($this->originalMargins)) {
|
||||
$this->originalMargins = $this->getMargins();
|
||||
}
|
||||
$margins = $this->originalMargins;
|
||||
|
||||
//page adjust
|
||||
$this->SetY(-1 * ($margins['bottom']));
|
||||
$currentY = $this->GetY();
|
||||
|
||||
$this->buildFooterLogo($margins, $currentY, $struct);
|
||||
$this->buildFooterTitle($margins, $currentY, $struct);
|
||||
$this->buildFooterPageNumber($margins, $currentY, $struct);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build footer logo.
|
||||
* @param array $margins
|
||||
* @param float $currentY
|
||||
* @param HeaderStruct $struct
|
||||
* @return void
|
||||
*/
|
||||
private function buildFooterLogo(array $margins, float $currentY, FooterStruct $struct): void
|
||||
{
|
||||
$path = $struct->getLogo();
|
||||
if (!file_exists($path)) {
|
||||
return;
|
||||
}
|
||||
$pathinfo = pathinfo($path);
|
||||
$extension = $pathinfo['extension'];
|
||||
$x = $struct->getLogoPositionX() + $margins['left'];
|
||||
$y = $struct->getLogoPositionY() + $currentY;
|
||||
$width = $struct->getLogoWidth();
|
||||
$this->Image($path, $x, $y, $width, 0, $extension, '', '', false, 300, '', false, false, 0, false, false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build footer title.
|
||||
* @param array $margins
|
||||
* @param float $currentY
|
||||
* @param HeaderStruct $struct
|
||||
* @return void
|
||||
*/
|
||||
private function buildFooterTitle(array $margins, float $currentY, FooterStruct $struct): void
|
||||
{
|
||||
$string = $struct->getTitle();
|
||||
$x = $struct->getTitleFontPositionX() + $margins['left'];
|
||||
$y = $struct->getTitleFontPositionY() + $currentY;
|
||||
$fontSize = $struct->getTitleFontSize();
|
||||
$this->SetXY($x, $y);
|
||||
$this->SetFont('helvetica', 'B', $fontSize);
|
||||
$this->MultiCell(0, 0, $string, 0, 'L', false, 1, '', '', true, 0, false, true, 0, 'T', false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build footer page number.
|
||||
* @param array $margins
|
||||
* @param float $currentY
|
||||
* @param HeaderStruct $struct
|
||||
* @return void
|
||||
*/
|
||||
private function buildFooterPageNumber(array $margins, float $currentY, FooterStruct $struct): void
|
||||
{
|
||||
if ($struct->getPageNumber() === true) {
|
||||
$pageString = empty($struct->getPageNumberTitle()) ? 'Page ' : $struct->getPageNumberTitle() . ' ';
|
||||
$pageNumberTotal = $struct->getPageNumberTotal() === true ? ' / ' . $this->getAliasNbPages() : '';
|
||||
$string = $pageString . $this->getAliasNumPage() . $pageNumberTotal;
|
||||
$x = $struct->getPageNumberPositionX() + $margins['left'];
|
||||
$y = $struct->getPageNumberPositionY() + $currentY;
|
||||
$fontSize = 8;
|
||||
$this->SetXY($x, $y);
|
||||
$this->SetFont('helvetica', 'I', $fontSize);
|
||||
$this->Cell(0, 0, $string, 0, 0, '', false, '', 0, false, 'T', 'M');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user