1
0
mirror of https://github.com/Intervention/image.git synced 2025-01-17 20:28:21 +01:00

Add test for TextBlock::getBoundingBox()

This commit is contained in:
Oliver Vogel 2022-07-04 19:42:22 +02:00
parent b7371cf9fb
commit d1ce4a3a83

View File

@ -3,8 +3,11 @@
namespace Intervention\Image\Tests\Typography;
use Intervention\Image\Geometry\Point;
use Intervention\Image\Geometry\Polygon;
use Intervention\Image\Interfaces\FontInterface;
use Intervention\Image\Tests\TestCase;
use Intervention\Image\Typography\TextBlock;
use Mockery;
class TextBlockTest extends TestCase
{
@ -37,4 +40,40 @@ class TextBlockTest extends TestCase
$this->assertEquals('FooBar', $block->getLine(1));
$this->assertEquals('bar', $block->getLine(2));
}
public function testLongestLine(): void
{
$block = $this->getTestBlock();
$result = $block->longestLine();
$this->assertEquals('FooBar', (string) $result);
}
public function testGetBoundingBox(): void
{
$block = $this->getTestBlock();
$font = Mockery::mock(FontInterface::class)
->shouldAllowMockingProtectedMethods()
->makePartial();
$font->shouldReceive('getBoxSize')->andReturn(
new Polygon([
new Point(0, 0),
new Point(300, 0),
new Point(300, 150),
new Point(0, 150),
])
);
$font->shouldReceive('leadingInPixels')->andReturn(30);
$font->shouldReceive('getAlign')->andReturn('left');
$font->shouldReceive('getValign')->andReturn('bottom');
$font->shouldReceive('getAngle')->andReturn(0);
$font->shouldReceive('capHeight')->andReturn(22);
$box = $block->getBoundingBox($font, new Point(10, 15));
$this->assertEquals(300, $box->width());
$this->assertEquals(82, $box->height());
$this->assertEquals(10, $box->getPivotPoint()->getX());
$this->assertEquals(15, $box->getPivotPoint()->getY());
}
}