2012-08-03 20:21:32 +00:00
|
|
|
<?php
|
|
|
|
|
2016-08-31 17:18:12 +00:00
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Shared;
|
2012-08-03 20:21:32 +00:00
|
|
|
|
2016-08-31 17:18:12 +00:00
|
|
|
use PhpOffice\PhpSpreadsheet\Shared\Font;
|
2017-11-08 15:48:01 +00:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2016-08-14 04:08:43 +00:00
|
|
|
|
2017-11-08 15:48:01 +00:00
|
|
|
class FontTest extends TestCase
|
2012-08-03 20:21:32 +00:00
|
|
|
{
|
2020-05-18 04:49:57 +00:00
|
|
|
public function testGetAutoSizeMethod(): void
|
2015-05-17 13:00:02 +00:00
|
|
|
{
|
2016-08-14 04:08:43 +00:00
|
|
|
$expectedResult = Font::AUTOSIZE_METHOD_APPROX;
|
2012-08-03 20:21:32 +00:00
|
|
|
|
2016-08-26 06:39:29 +00:00
|
|
|
$result = Font::getAutoSizeMethod();
|
2017-09-20 05:55:42 +00:00
|
|
|
self::assertEquals($expectedResult, $result);
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
2012-08-03 20:21:32 +00:00
|
|
|
|
2020-05-18 04:49:57 +00:00
|
|
|
public function testSetAutoSizeMethod(): void
|
2015-05-17 13:00:02 +00:00
|
|
|
{
|
2016-08-16 15:33:57 +00:00
|
|
|
$autosizeMethodValues = [
|
2016-08-14 04:08:43 +00:00
|
|
|
Font::AUTOSIZE_METHOD_EXACT,
|
|
|
|
Font::AUTOSIZE_METHOD_APPROX,
|
2016-08-16 15:33:57 +00:00
|
|
|
];
|
2015-05-17 13:00:02 +00:00
|
|
|
|
|
|
|
foreach ($autosizeMethodValues as $autosizeMethodValue) {
|
2016-08-26 06:39:29 +00:00
|
|
|
$result = Font::setAutoSizeMethod($autosizeMethodValue);
|
2017-09-20 05:55:42 +00:00
|
|
|
self::assertTrue($result);
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
|
|
|
}
|
2012-08-03 20:21:32 +00:00
|
|
|
|
2020-05-18 04:49:57 +00:00
|
|
|
public function testSetAutoSizeMethodWithInvalidValue(): void
|
2015-05-17 13:00:02 +00:00
|
|
|
{
|
|
|
|
$unsupportedAutosizeMethod = 'guess';
|
2012-08-03 20:21:32 +00:00
|
|
|
|
2016-08-26 06:39:29 +00:00
|
|
|
$result = Font::setAutoSizeMethod($unsupportedAutosizeMethod);
|
2017-09-20 05:55:42 +00:00
|
|
|
self::assertFalse($result);
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
2012-08-03 20:21:32 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerFontSizeToPixels
|
2017-01-23 05:49:10 +00:00
|
|
|
*
|
|
|
|
* @param mixed $expectedResult
|
2012-08-03 20:21:32 +00:00
|
|
|
*/
|
2020-05-18 04:49:57 +00:00
|
|
|
public function testFontSizeToPixels($expectedResult, ...$args): void
|
2015-05-17 13:00:02 +00:00
|
|
|
{
|
2017-01-23 05:49:10 +00:00
|
|
|
$result = Font::fontSizeToPixels(...$args);
|
2017-09-20 05:55:42 +00:00
|
|
|
self::assertEquals($expectedResult, $result);
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
2012-08-03 20:21:32 +00:00
|
|
|
|
|
|
|
public function providerFontSizeToPixels()
|
|
|
|
{
|
2020-05-17 09:35:55 +00:00
|
|
|
return require 'tests/data/Shared/FontSizeToPixels.php';
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
2012-08-03 20:21:32 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerInchSizeToPixels
|
2017-01-23 05:49:10 +00:00
|
|
|
*
|
|
|
|
* @param mixed $expectedResult
|
2012-08-03 20:21:32 +00:00
|
|
|
*/
|
2020-05-18 04:49:57 +00:00
|
|
|
public function testInchSizeToPixels($expectedResult, ...$args): void
|
2015-05-17 13:00:02 +00:00
|
|
|
{
|
2017-01-23 05:49:10 +00:00
|
|
|
$result = Font::inchSizeToPixels(...$args);
|
2017-09-20 05:55:42 +00:00
|
|
|
self::assertEquals($expectedResult, $result);
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
2012-08-03 20:21:32 +00:00
|
|
|
|
|
|
|
public function providerInchSizeToPixels()
|
|
|
|
{
|
2020-05-17 09:35:55 +00:00
|
|
|
return require 'tests/data/Shared/InchSizeToPixels.php';
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
2012-08-03 20:21:32 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerCentimeterSizeToPixels
|
2017-01-23 05:49:10 +00:00
|
|
|
*
|
|
|
|
* @param mixed $expectedResult
|
2012-08-03 20:21:32 +00:00
|
|
|
*/
|
2020-05-18 04:49:57 +00:00
|
|
|
public function testCentimeterSizeToPixels($expectedResult, ...$args): void
|
2015-05-17 13:00:02 +00:00
|
|
|
{
|
2017-01-23 05:49:10 +00:00
|
|
|
$result = Font::centimeterSizeToPixels(...$args);
|
2017-09-20 05:55:42 +00:00
|
|
|
self::assertEquals($expectedResult, $result);
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
2012-08-03 20:21:32 +00:00
|
|
|
|
|
|
|
public function providerCentimeterSizeToPixels()
|
|
|
|
{
|
2020-05-17 09:35:55 +00:00
|
|
|
return require 'tests/data/Shared/CentimeterSizeToPixels.php';
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
2012-08-03 20:21:32 +00:00
|
|
|
}
|