Files
PhpSpreadsheet/tests/PhpSpreadsheetTests/Style/FontTest.php
Matjaž Drolc 0b0f02206f fix: Set font size to 10 when given 0
This change restored behavior from PHP7 in PHP8. In PHP7 calling
setSize(0) resulted in font size being set to 10. The fix addresses
change to equal comparisons in PHP8. Extra comparison is added to keep
result from PHP7 in PHP8 for the setSize(0) case.
2021-05-29 11:17:25 +02:00

75 lines
2.7 KiB
PHP

<?php
namespace PhpOffice\PhpSpreadsheetTests\Style;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PHPUnit\Framework\TestCase;
class FontTest extends TestCase
{
public function testSuperSubScript(): void
{
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$cell = $sheet->getCell('A1');
$cell->setValue('Cell A1');
$font = $cell->getStyle()->getFont();
$font->setSuperscript(true);
$font->setSubscript(true);
self::assertFalse($font->getSuperscript(), 'Earlier set true loses');
self::assertTrue($font->getSubscript(), 'Last set true wins');
$font->setSubscript(true);
$font->setSuperscript(true);
self::assertTrue($font->getSuperscript(), 'Last set true wins');
self::assertFalse($font->getSubscript(), 'Earlier set true loses');
$font->setSuperscript(false);
$font->setSubscript(false);
self::assertFalse($font->getSuperscript(), 'False remains unchanged');
self::assertFalse($font->getSubscript(), 'False remains unchanged');
$font->setSubscript(false);
$font->setSuperscript(false);
self::assertFalse($font->getSuperscript(), 'False remains unchanged');
self::assertFalse($font->getSubscript(), 'False remains unchanged');
$font->setSubscript(true);
$font->setSuperscript(false);
self::assertFalse($font->getSuperscript(), 'False remains unchanged');
self::assertTrue($font->getSubscript(), 'True remains unchanged');
$font->setSubscript(false);
$font->setSuperscript(true);
self::assertTrue($font->getSuperscript());
self::assertFalse($font->getSubscript(), 'False remains unchanged');
}
public function testSize(): void
{
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$cell = $sheet->getCell('A1');
$cell->setValue('Cell A1');
$font = $cell->getStyle()->getFont();
self::assertEquals(11, $font->getSize(), 'The default is 11');
$font->setSize(12);
self::assertEquals(12, $font->getSize(), 'Accepted new font size');
$invalidFontSizeValues = [
'',
false,
true,
'non_numeric_string',
'-1.0',
-1.0,
0,
[],
(object) [],
null,
];
foreach ($invalidFontSizeValues as $invalidFontSizeValue) {
$font->setSize(12);
$font->setSize($invalidFontSizeValue);
self::assertEquals(10, $font->getSize(), 'Set to 10 after trying to set an invalid value.');
}
}
}