Added tests for StyleRegistry and StyleMerger
This commit is contained in:
parent
d4e12b1812
commit
52312b7045
@ -41,4 +41,24 @@ class StyleBuilderTest extends TestCase
|
||||
$this->assertInstanceOf(Border::class, $baseStyle->getBorder(), 'Base style has a border');
|
||||
$this->assertInstanceOf(Border::class, $mergedStyle->getBorder(), 'Merged style has a border');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testStyleBuilderShouldMergeFormats()
|
||||
{
|
||||
$baseStyle = (new StyleBuilder())
|
||||
->setFontBold()
|
||||
->setFormat('0.00')
|
||||
->build();
|
||||
|
||||
$currentStyle = (new StyleBuilder())->build();
|
||||
|
||||
$styleMerger = new StyleMerger();
|
||||
$mergedStyle = $styleMerger->merge($currentStyle, $baseStyle);
|
||||
|
||||
$this->assertNull($currentStyle->getFormat(), 'Current style has no border');
|
||||
$this->assertEquals('0.00', $baseStyle->getFormat(), 'Base style has a format 0.00');
|
||||
$this->assertEquals('0.00', $mergedStyle->getFormat(), 'Merged style has a format 0.00');
|
||||
}
|
||||
}
|
||||
|
@ -74,4 +74,34 @@ class StyleRegistryTest extends TestCase
|
||||
$this->assertEquals(2, $styleRegistry->getBorderIdForStyleId($styleBoderRightBold->getId()), 'Style with border already set should have the same index');
|
||||
$this->assertEquals(0, $styleRegistry->getBorderIdForStyleId($styleNoBorder->getId()), 'Style with no border should have index 0');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testRegisterStyleAlsoRegistersFormats()
|
||||
{
|
||||
$styleRegistry = $this->getStyleRegistry();
|
||||
|
||||
$styleBuiltinFormat = (new StyleBuilder())
|
||||
->setFontBold()
|
||||
->setFormat('0.00')//Builtin format
|
||||
->build();
|
||||
|
||||
$styleUserFormat = (new StyleBuilder())
|
||||
->setFontBold()
|
||||
->setFormat('0.000')
|
||||
->build();
|
||||
$styleNoFormat = (new StyleBuilder())->setFontItalic()->build();
|
||||
|
||||
$styleRegistry->registerStyle($styleBuiltinFormat);
|
||||
$styleRegistry->registerStyle($styleUserFormat);
|
||||
$styleRegistry->registerStyle($styleNoFormat);
|
||||
|
||||
$this->assertCount(2, $styleRegistry->getRegisteredFormats(), 'There should be 2 registered formats');
|
||||
|
||||
$this->assertEquals(2, $styleRegistry->getFormatIdForStyleId($styleBuiltinFormat->getId()), 'First style with builtin format set should have index 2 (0 is for the default style)');
|
||||
$this->assertEquals(164, $styleRegistry->getFormatIdForStyleId($styleUserFormat->getId()), 'Second style with user format set should have index 164 (0 is for the default style)');
|
||||
|
||||
$this->assertEquals(0, $styleRegistry->getFormatIdForStyleId($styleNoFormat->getId()), 'Style with no format should have index 0');
|
||||
}
|
||||
}
|
||||
|
@ -236,7 +236,7 @@ class WriterWithStyleTest extends TestCase
|
||||
$this->assertEquals(
|
||||
1,
|
||||
$formatsDomElement->getAttribute('count'),
|
||||
'There should be 2 formats, including the 1 default ones'
|
||||
'There should be 2 formats, including the default one'
|
||||
);
|
||||
|
||||
$cellXfsDomElement = $this->getXmlSectionFromStylesXmlFile($fileName, 'cellXfs');
|
||||
|
Loading…
x
Reference in New Issue
Block a user