-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5bed9ff
commit cf439d8
Showing
9 changed files
with
550 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
<?php | ||
/* | ||
* This file is part of the Calculation package. | ||
* | ||
* (c) bibi.nu <bibi@bibi.nu> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Tests\Pdf\Html; | ||
|
||
use App\Pdf\Html\HtmlPageBreakChunk; | ||
use App\Pdf\Html\HtmlParentChunk; | ||
use App\Pdf\Html\HtmlTag; | ||
use PHPUnit\Framework\Attributes\CoversClass; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
#[CoversClass(HtmlParentChunk::class)] | ||
class HtmlParentChunkTest extends TestCase | ||
{ | ||
public function testAdd(): void | ||
{ | ||
$actual = new HtmlParentChunk('body'); | ||
$chunk = new HtmlPageBreakChunk('fake'); | ||
$actual->add($chunk); | ||
self::assertCount(1, $actual); | ||
|
||
$actual->add($chunk); | ||
self::assertCount(1, $actual); | ||
} | ||
|
||
public function testDefault(): void | ||
{ | ||
$actual = new HtmlParentChunk('body'); | ||
self::assertCount(0, $actual); | ||
self::assertEmpty($actual->getChildren()); | ||
self::assertNull($actual->getParent()); | ||
self::assertNull($actual->findChild(HtmlTag::BOLD)); | ||
self::assertTrue($actual->isEmpty()); | ||
self::assertFalse($actual->isNewLine()); | ||
|
||
$chunk = new HtmlPageBreakChunk('fake'); | ||
self::assertSame(-1, $actual->indexOf($chunk)); | ||
} | ||
|
||
public function testFind(): void | ||
{ | ||
$parent = new HtmlParentChunk(HtmlTag::BODY->value); | ||
$actual = $parent->findChild(HtmlTag::H1); | ||
self::assertNull($actual); | ||
|
||
$span = new HtmlParentChunk(HtmlTag::SPAN->value); | ||
$parent->add($span); | ||
|
||
$pageBreak = new HtmlPageBreakChunk(HtmlTag::PAGE_BREAK->value); | ||
$parent->add($pageBreak); | ||
|
||
$actual = $parent->findChild(HtmlTag::SPAN); | ||
self::assertNotNull($actual); | ||
|
||
$actual = $parent->findChild(HtmlTag::PAGE_BREAK); | ||
self::assertNotNull($actual); | ||
|
||
$actual = $parent->findChild(HtmlTag::H1); | ||
self::assertNull($actual); | ||
} | ||
|
||
public function testFindRecursive(): void | ||
{ | ||
$parent = new HtmlParentChunk(HtmlTag::BODY->value); | ||
$actual = $parent->findChild(HtmlTag::BOLD); | ||
self::assertNull($actual); | ||
|
||
$h1 = new HtmlParentChunk(HtmlTag::H1->value); | ||
$parent->add($h1); | ||
|
||
$h2 = new HtmlParentChunk(HtmlTag::H2->value); | ||
$h1->add($h2); | ||
|
||
$actual = $parent->findChild(HtmlTag::H1); | ||
self::assertNotNull($actual); | ||
|
||
$actual = $parent->findChild(HtmlTag::H2); | ||
self::assertNotNull($actual); | ||
} | ||
|
||
public function testRemove(): void | ||
{ | ||
$actual = new HtmlParentChunk(HtmlTag::BODY->value); | ||
$chunk = new HtmlPageBreakChunk(HtmlTag::PAGE_BREAK->value); | ||
|
||
$actual->add($chunk); | ||
self::assertCount(1, $actual); | ||
$actual->remove($chunk); | ||
self::assertCount(0, $actual); | ||
|
||
$actual->remove($chunk); | ||
self::assertCount(0, $actual); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
<?php | ||
/* | ||
* This file is part of the Calculation package. | ||
* | ||
* (c) bibi.nu <bibi@bibi.nu> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Tests\Pdf\Html; | ||
|
||
use App\Pdf\Html\HtmlBrChunk; | ||
use App\Pdf\Html\HtmlLiChunk; | ||
use App\Pdf\Html\HtmlOlChunk; | ||
use App\Pdf\Html\HtmlPageBreakChunk; | ||
use App\Pdf\Html\HtmlParentChunk; | ||
use App\Pdf\Html\HtmlParser; | ||
use App\Pdf\Html\HtmlTextChunk; | ||
use App\Pdf\Html\HtmlUlChunk; | ||
use PHPUnit\Framework\Attributes\CoversClass; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
#[CoversClass(HtmlParser::class)] | ||
class HtmlParserTest extends TestCase | ||
{ | ||
public function testBrChunk(): void | ||
{ | ||
$parser = new HtmlParser('<body><br></body>'); | ||
$actual = $parser->parse(); | ||
self::assertInstanceOf(HtmlParentChunk::class, $actual); | ||
self::assertNotEmpty($actual->getChildren()); | ||
self::assertCount(1, $actual); | ||
$actual = $actual->getChildren()[0]; | ||
self::assertInstanceOf(HtmlBrChunk::class, $actual); | ||
} | ||
|
||
public function testEmpty(): void | ||
{ | ||
$parser = new HtmlParser(''); | ||
$actual = $parser->parse(); | ||
self::assertNull($actual); | ||
} | ||
|
||
public function testEmptyBody(): void | ||
{ | ||
$parser = new HtmlParser('<html><body></body></html>'); | ||
$actual = $parser->parse(); | ||
self::assertNull($actual); | ||
} | ||
|
||
public function testLiChunk(): void | ||
{ | ||
$parser = new HtmlParser('<body><li></li></body>'); | ||
$actual = $parser->parse(); | ||
self::assertInstanceOf(HtmlParentChunk::class, $actual); | ||
self::assertNotEmpty($actual->getChildren()); | ||
self::assertCount(1, $actual); | ||
$actual = $actual->getChildren()[0]; | ||
self::assertInstanceOf(HtmlLiChunk::class, $actual); | ||
} | ||
|
||
public function testNoBody(): void | ||
{ | ||
$parser = new HtmlParser('<html></html>'); | ||
$actual = $parser->parse(); | ||
self::assertNull($actual); | ||
} | ||
|
||
public function testOlChunk(): void | ||
{ | ||
$parser = new HtmlParser('<body><ol></ol></body>'); | ||
$actual = $parser->parse(); | ||
self::assertInstanceOf(HtmlParentChunk::class, $actual); | ||
self::assertNotEmpty($actual->getChildren()); | ||
self::assertCount(1, $actual); | ||
$actual = $actual->getChildren()[0]; | ||
self::assertInstanceOf(HtmlOlChunk::class, $actual); | ||
} | ||
|
||
public function testPageBreakChunk(): void | ||
{ | ||
$parser = new HtmlParser('<body><div class="page-break"></div></body>'); | ||
$actual = $parser->parse(); | ||
self::assertInstanceOf(HtmlParentChunk::class, $actual); | ||
self::assertNotEmpty($actual->getChildren()); | ||
self::assertCount(1, $actual); | ||
$actual = $actual->getChildren()[0]; | ||
self::assertInstanceOf(HtmlPageBreakChunk::class, $actual); | ||
} | ||
|
||
public function testTextChunk(): void | ||
{ | ||
$parser = new HtmlParser('<body><p>My Text</p></body>'); | ||
$actual = $parser->parse(); | ||
self::assertInstanceOf(HtmlParentChunk::class, $actual); | ||
self::assertNotEmpty($actual->getChildren()); | ||
self::assertCount(1, $actual); | ||
|
||
$actual = $actual->getChildren()[0]; | ||
self::assertInstanceOf(HtmlParentChunk::class, $actual); | ||
self::assertNotEmpty($actual->getChildren()); | ||
self::assertCount(1, $actual); | ||
|
||
$actual = $actual->getChildren()[0]; | ||
self::assertInstanceOf(HtmlTextChunk::class, $actual); | ||
} | ||
|
||
public function testUlChunk(): void | ||
{ | ||
$parser = new HtmlParser('<body><ul></ul></body>'); | ||
$actual = $parser->parse(); | ||
self::assertInstanceOf(HtmlParentChunk::class, $actual); | ||
self::assertNotEmpty($actual->getChildren()); | ||
self::assertCount(1, $actual); | ||
$actual = $actual->getChildren()[0]; | ||
self::assertInstanceOf(HtmlUlChunk::class, $actual); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
/* | ||
* This file is part of the Calculation package. | ||
* | ||
* (c) bibi.nu <bibi@bibi.nu> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Tests\Pdf\Traits; | ||
|
||
use App\Pdf\PdfColumn; | ||
use App\Pdf\PdfDocument; | ||
use App\Pdf\PdfTable; | ||
use App\Pdf\Traits\PdfCellTranslatorTrait; | ||
use PHPUnit\Framework\Attributes\CoversClass; | ||
use PHPUnit\Framework\MockObject\Exception; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Contracts\Translation\TranslatorInterface; | ||
|
||
#[CoversClass(PdfCellTranslatorTrait::class)] | ||
class PdfCellTranslatorTraitTest extends TestCase | ||
{ | ||
/** | ||
* @throws Exception | ||
*/ | ||
public function testRender(): void | ||
{ | ||
$document = new PdfDocument(); | ||
$translator = $this->createMock(TranslatorInterface::class); | ||
|
||
$table = new class($document, $translator) extends PdfTable { | ||
use PdfCellTranslatorTrait; | ||
|
||
public function __construct(PdfDocument $parent, private readonly TranslatorInterface $translator) | ||
{ | ||
parent::__construct($parent); | ||
} | ||
|
||
public function render(): bool | ||
{ | ||
$this->addColumn(PdfColumn::left('', 10.0)); | ||
$this->startRow(); | ||
$this->addCellTrans('id'); | ||
$this->endRow(); | ||
|
||
return true; | ||
} | ||
|
||
public function getTranslator(): TranslatorInterface | ||
{ | ||
return $this->translator; | ||
} | ||
}; | ||
$document->resetStyle() | ||
->addPage(); | ||
$actual = $table->render(); | ||
self::assertTrue($actual); | ||
} | ||
} |
Oops, something went wrong.