Added tests for StyleRegistry and StyleMerger

This commit is contained in:
Alexander Rakushin 2019-09-29 19:15:25 +03:00
parent 804b668a9c
commit 2cfaa4af77
3 changed files with 51 additions and 1 deletions

View File

@ -41,4 +41,24 @@ class StyleBuilderTest extends TestCase
$this->assertInstanceOf(Border::class, $baseStyle->getBorder(), 'Base style has a border'); $this->assertInstanceOf(Border::class, $baseStyle->getBorder(), 'Base style has a border');
$this->assertInstanceOf(Border::class, $mergedStyle->getBorder(), 'Merged 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');
}
} }

View File

@ -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(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'); $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');
}
} }

View File

@ -236,7 +236,7 @@ class WriterWithStyleTest extends TestCase
$this->assertEquals( $this->assertEquals(
1, 1,
$formatsDomElement->getAttribute('count'), $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'); $cellXfsDomElement = $this->getXmlSectionFromStylesXmlFile($fileName, 'cellXfs');