Add support for styling
Added top level methods on the Writer: - addRowWithStyle() - addRowsWithStyle() Added a style builder, to easily create new styles. Each writer can specify its own default style and all styles will automatically inherit from it. For now, the style properties supported are: - bold - italic - underline - strikethrough - font size - font name - wrap text (alignment)
This commit is contained in:
1 parent
0104714cbd
commit
21263a0730
14 files changed
+1344
-22
No files matched your search
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
|
||||
namespace Box\Spout\Writer\Style;
|
||||
|
||||
/**
|
||||
* Class StyleTest
|
||||
*
|
||||
* @package Box\Spout\Writer\Style
|
||||
*/
|
||||
class StyleTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testSerializeShouldNotTakeIntoAccountId()
|
||||
{
|
||||
$style1 = (new StyleBuilder())->setFontBold()->build();
|
||||
$style1->setId(1);
|
||||
|
||||
$style2 = (new StyleBuilder())->setFontBold()->build();
|
||||
$style2->setId(2);
|
||||
|
||||
$this->assertEquals($style1->serialize(), $style2->serialize());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testMergeWithShouldReturnACopy()
|
||||
{
|
||||
$baseStyle = (new StyleBuilder())->build();
|
||||
$currentStyle = (new StyleBuilder())->build();
|
||||
$mergedStyle = $currentStyle->mergeWith($baseStyle);
|
||||
|
||||
$this->assertNotSame($mergedStyle, $currentStyle);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testMergeWithShouldMergeSetProperties()
|
||||
{
|
||||
$baseStyle = (new StyleBuilder())->setFontSize(99)->setFontBold()->build();
|
||||
$currentStyle = (new StyleBuilder())->setFontName('Font')->setFontUnderline()->build();
|
||||
$mergedStyle = $currentStyle->mergeWith($baseStyle);
|
||||
|
||||
$this->assertNotEquals(99, $currentStyle->getFontSize());
|
||||
$this->assertFalse($currentStyle->isFontBold());
|
||||
|
||||
$this->assertEquals(99, $mergedStyle->getFontSize());
|
||||
$this->assertTrue($mergedStyle->isFontBold());
|
||||
$this->assertEquals('Font', $mergedStyle->getFontName());
|
||||
$this->assertTrue($mergedStyle->isFontUnderline());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testMergeWithShouldPreferCurrentStylePropertyIfSetOnCurrentAndOnBase()
|
||||
{
|
||||
$baseStyle = (new StyleBuilder())->setFontSize(10)->build();
|
||||
$currentStyle = (new StyleBuilder())->setFontSize(99)->build();
|
||||
$mergedStyle = $currentStyle->mergeWith($baseStyle);
|
||||
|
||||
$this->assertEquals(99, $mergedStyle->getFontSize());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testMergeWithShouldPreferCurrentStylePropertyIfSetOnCurrentButNotOnBase()
|
||||
{
|
||||
$baseStyle = (new StyleBuilder())->build();
|
||||
$currentStyle = (new StyleBuilder())->setFontItalic()->setFontStrikeThrough()->build();
|
||||
$mergedStyle = $currentStyle->mergeWith($baseStyle);
|
||||
|
||||
$this->assertFalse($baseStyle->isFontItalic());
|
||||
$this->assertFalse($baseStyle->isFontStrikeThrough());
|
||||
|
||||
$this->assertTrue($mergedStyle->isFontItalic());
|
||||
$this->assertTrue($mergedStyle->isFontStrikeThrough());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testMergeWithShouldPreferBaseStylePropertyIfSetOnBaseButNotOnCurrent()
|
||||
{
|
||||
$baseStyle = (new StyleBuilder())
|
||||
->setFontItalic()
|
||||
->setFontUnderline()
|
||||
->setFontStrikeThrough()
|
||||
->setShouldWrapText()
|
||||
->build();
|
||||
$currentStyle = (new StyleBuilder())->build();
|
||||
$mergedStyle = $currentStyle->mergeWith($baseStyle);
|
||||
|
||||
$this->assertFalse($currentStyle->isFontUnderline());
|
||||
$this->assertTrue($mergedStyle->isFontUnderline());
|
||||
|
||||
$this->assertFalse($currentStyle->shouldWrapText());
|
||||
$this->assertTrue($mergedStyle->shouldWrapText());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testMergeWithShouldDoNothingIfStylePropertyNotSetOnBaseNorCurrent()
|
||||
{
|
||||
$baseStyle = (new StyleBuilder())->build();
|
||||
$currentStyle = (new StyleBuilder())->build();
|
||||
$mergedStyle = $currentStyle->mergeWith($baseStyle);
|
||||
|
||||
$this->assertTrue($baseStyle->serialize() === $currentStyle->serialize());
|
||||
$this->assertTrue($currentStyle->serialize() === $mergedStyle->serialize());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testMergeWithShouldDoNothingIfStylePropertyNotSetOnCurrentAndIsDefaultValueOnBase()
|
||||
{
|
||||
$baseStyle = (new StyleBuilder())
|
||||
->setFontName(Style::DEFAULT_FONT_NAME)
|
||||
->setFontSize(Style::DEFAULT_FONT_SIZE)
|
||||
->build();
|
||||
$currentStyle = (new StyleBuilder())->build();
|
||||
$mergedStyle = $currentStyle->mergeWith($baseStyle);
|
||||
|
||||
$this->assertTrue($currentStyle->serialize() === $mergedStyle->serialize());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace Box\Spout\Writer\XLSX\Helper;
|
||||
|
||||
use Box\Spout\Writer\Style\StyleBuilder;
|
||||
|
||||
/**
|
||||
* Class StyleHelperTest
|
||||
*
|
||||
* @package Box\Spout\Writer\XLSX\Helper
|
||||
*/
|
||||
class StyleHelperTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/** @var \Box\Spout\Writer\Style\Style */
|
||||
protected $defaultStyle;
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
$this->defaultStyle = (new StyleBuilder())->build();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testRegisterStyleShouldUpdateId()
|
||||
{
|
||||
$style1 = (new StyleBuilder())->setFontBold()->build();
|
||||
$style2 = (new StyleBuilder())->setFontUnderline()->build();
|
||||
|
||||
$this->assertEquals(0, $this->defaultStyle->getId(), 'Default style ID should be 0');
|
||||
$this->assertNull($style1->getId());
|
||||
$this->assertNull($style2->getId());
|
||||
|
||||
$styleHelper = new StyleHelper($this->defaultStyle);
|
||||
$registeredStyle1 = $styleHelper->registerStyle($style1);
|
||||
$registeredStyle2 = $styleHelper->registerStyle($style2);
|
||||
|
||||
$this->assertEquals(1, $registeredStyle1->getId());
|
||||
$this->assertEquals(2, $registeredStyle2->getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testRegisterStyleShouldReuseAlreadyRegisteredStyles()
|
||||
{
|
||||
$style = (new StyleBuilder())->setFontBold()->build();
|
||||
|
||||
$styleHelper = new StyleHelper($this->defaultStyle);
|
||||
$registeredStyle1 = $styleHelper->registerStyle($style);
|
||||
$registeredStyle2 = $styleHelper->registerStyle($style);
|
||||
|
||||
$this->assertEquals(1, $registeredStyle1->getId());
|
||||
$this->assertEquals(1, $registeredStyle2->getId());
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ use Box\Spout\Writer\WriterFactory;
|
||||
/**
|
||||
* Class XLSXTest
|
||||
*
|
||||
* @package Box\Spout\Writer
|
||||
* @package Box\Spout\Writer\XLSX
|
||||
*/
|
||||
class WriterTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
@@ -26,8 +26,6 @@ class WriterTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$writer = WriterFactory::create(Type::XLSX);
|
||||
@$writer->openToFile($filePath);
|
||||
$writer->addRow(['xlsx--11', 'xlsx--12']);
|
||||
$writer->close();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -37,17 +35,15 @@ class WriterTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$writer = WriterFactory::create(Type::XLSX);
|
||||
$writer->addRow(['xlsx--11', 'xlsx--12']);
|
||||
$writer->close();
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Box\Spout\Writer\Exception\WriterNotOpenedException
|
||||
*/
|
||||
public function testAddRowShouldThrowExceptionIfCallAddRowsBeforeOpeningWriter()
|
||||
public function testAddRowShouldThrowExceptionIfCalledBeforeOpeningWriter()
|
||||
{
|
||||
$writer = WriterFactory::create(Type::XLSX);
|
||||
$writer->addRows([['xlsx--11', 'xlsx--12']]);
|
||||
$writer->close();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,337 @@
|
||||
<?php
|
||||
|
||||
namespace Box\Spout\Writer\XLSX;
|
||||
|
||||
use Box\Spout\Common\Type;
|
||||
use Box\Spout\TestUsingResource;
|
||||
use Box\Spout\Writer\Style\StyleBuilder;
|
||||
use Box\Spout\Writer\WriterFactory;
|
||||
|
||||
/**
|
||||
* Class WriterWithStyleTest
|
||||
*
|
||||
* @package Box\Spout\Writer\XLSX
|
||||
*/
|
||||
class WriterWithStyleTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
use TestUsingResource;
|
||||
|
||||
/** @var \Box\Spout\Writer\Style\Style */
|
||||
protected $defaultStyle;
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
$this->defaultStyle = (new StyleBuilder())->build();
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Box\Spout\Writer\Exception\WriterNotOpenedException
|
||||
*/
|
||||
public function testAddRowWithStyleShouldThrowExceptionIfCallAddRowBeforeOpeningWriter()
|
||||
{
|
||||
$writer = WriterFactory::create(Type::XLSX);
|
||||
$writer->addRowWithStyle(['xlsx--11', 'xlsx--12'], $this->defaultStyle);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Box\Spout\Writer\Exception\WriterNotOpenedException
|
||||
*/
|
||||
public function testAddRowWithStyleShouldThrowExceptionIfCalledBeforeOpeningWriter()
|
||||
{
|
||||
$writer = WriterFactory::create(Type::XLSX);
|
||||
$writer->addRowWithStyle(['xlsx--11', 'xlsx--12'], $this->defaultStyle);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function dataProviderForInvalidStyle()
|
||||
{
|
||||
return [
|
||||
['style'],
|
||||
[new \stdClass()],
|
||||
[null],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataProviderForInvalidStyle
|
||||
* @expectedException \Box\Spout\Common\Exception\InvalidArgumentException
|
||||
*
|
||||
* @param \Box\Spout\Writer\Style\Style $style
|
||||
*/
|
||||
public function testAddRowWithStyleShouldThrowExceptionIfInvalidStyleGiven($style)
|
||||
{
|
||||
$fileName = 'test_add_row_with_style_should_throw_exception.xlsx';
|
||||
$this->createGeneratedFolderIfNeeded($fileName);
|
||||
$resourcePath = $this->getGeneratedResourcePath($fileName);
|
||||
|
||||
$writer = WriterFactory::create(Type::XLSX);
|
||||
$writer->openToFile($resourcePath);
|
||||
$writer->addRowWithStyle(['xlsx--11', 'xlsx--12'], $style);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataProviderForInvalidStyle
|
||||
* @expectedException \Box\Spout\Common\Exception\InvalidArgumentException
|
||||
*
|
||||
* @param \Box\Spout\Writer\Style\Style $style
|
||||
*/
|
||||
public function testAddRowsWithStyleShouldThrowExceptionIfInvalidStyleGiven($style)
|
||||
{
|
||||
$fileName = 'test_add_row_with_style_should_throw_exception.xlsx';
|
||||
$this->createGeneratedFolderIfNeeded($fileName);
|
||||
$resourcePath = $this->getGeneratedResourcePath($fileName);
|
||||
|
||||
$writer = WriterFactory::create(Type::XLSX);
|
||||
$writer->openToFile($resourcePath);
|
||||
$writer->addRowsWithStyle([['xlsx--11', 'xlsx--12']], $style);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testAddRowWithStyleShouldListAllUsedFontsInCreateStylesXmlFile()
|
||||
{
|
||||
$fileName = 'test_add_row_with_style_should_list_all_used_fonts.xlsx';
|
||||
$dataRows = [
|
||||
['xlsx--11', 'xlsx--12'],
|
||||
['xlsx--21', 'xlsx--22'],
|
||||
];
|
||||
|
||||
$style = (new StyleBuilder())
|
||||
->setFontBold()
|
||||
->setFontItalic()
|
||||
->setFontUnderline()
|
||||
->setFontStrikeThrough()
|
||||
->build();
|
||||
$style2 = (new StyleBuilder())
|
||||
->setFontSize(15)
|
||||
->setFontName('Arial')
|
||||
->build();
|
||||
|
||||
$this->writeToXLSXFileWithMultipleStyles($dataRows, $fileName, [$style, $style2]);
|
||||
|
||||
$fontsDomElement = $this->getXmlSectionFromStylesXmlFile($fileName, 'fonts');
|
||||
$this->assertEquals(3, $fontsDomElement->getAttribute('count'), 'There should be 3 fonts, including the default one.');
|
||||
|
||||
$fontElements = $fontsDomElement->getElementsByTagName('font');
|
||||
$this->assertEquals(3, $fontElements->length, 'There should be 3 associated "font" elements, including the default one.');
|
||||
|
||||
// First font should be the default one
|
||||
$defaultFontElement = $fontElements->item(0);
|
||||
$this->assertChildrenNumEquals(2, $defaultFontElement, 'The default font should only have 2 properties.');
|
||||
$this->assertFirstChildHasAttributeEquals((string) Writer::DEFAULT_FONT_SIZE, $defaultFontElement, 'sz', 'val');
|
||||
$this->assertFirstChildHasAttributeEquals(Writer::DEFAULT_FONT_NAME, $defaultFontElement, 'name', 'val');
|
||||
|
||||
// Second font should contain data from the first created style
|
||||
$secondFontElement = $fontElements->item(1);
|
||||
$this->assertChildrenNumEquals(6, $secondFontElement, 'The font should only have 6 properties (4 custom styles + 2 default styles).');
|
||||
$this->assertChildExists($secondFontElement, 'b');
|
||||
$this->assertChildExists($secondFontElement, 'i');
|
||||
$this->assertChildExists($secondFontElement, 'u');
|
||||
$this->assertChildExists($secondFontElement, 'strike');
|
||||
$this->assertFirstChildHasAttributeEquals((string) Writer::DEFAULT_FONT_SIZE, $secondFontElement, 'sz', 'val');
|
||||
$this->assertFirstChildHasAttributeEquals(Writer::DEFAULT_FONT_NAME, $secondFontElement, 'name', 'val');
|
||||
|
||||
// Third font should contain data from the second created style
|
||||
$thirdFontElement = $fontElements->item(2);
|
||||
$this->assertChildrenNumEquals(2, $thirdFontElement, 'The font should only have 2 properties.');
|
||||
$this->assertFirstChildHasAttributeEquals('15', $thirdFontElement, 'sz', 'val');
|
||||
$this->assertFirstChildHasAttributeEquals('Arial', $thirdFontElement, 'name', 'val');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testAddRowWithStyleShouldAddWrapTextAlignmentInfoInStylesXmlFileIfSpecified()
|
||||
{
|
||||
$fileName = 'test_add_row_with_style_should_add_wrap_text_alignment.xlsx';
|
||||
$dataRows = [
|
||||
['xlsx--11', 'xlsx--12'],
|
||||
];
|
||||
$style = (new StyleBuilder())->setShouldWrapText()->build();
|
||||
|
||||
$this->writeToXLSXFile($dataRows, $fileName,$style);
|
||||
|
||||
$cellXfsDomElement = $this->getXmlSectionFromStylesXmlFile($fileName, 'cellXfs');
|
||||
$xfElement = $cellXfsDomElement->getElementsByTagName('xf')->item(1);
|
||||
$this->assertEquals(1, $xfElement->getAttribute('applyAlignment'));
|
||||
$this->assertFirstChildHasAttributeEquals('1', $xfElement, 'alignment', 'wrapText');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testAddRowWithStyleShouldApplyStyleToCells()
|
||||
{
|
||||
$fileName = 'test_add_row_with_style_should_apply_style_to_cells.xlsx';
|
||||
$dataRows = [
|
||||
['xlsx--11'],
|
||||
['xlsx--21'],
|
||||
['xlsx--31'],
|
||||
];
|
||||
$style = (new StyleBuilder())->setFontBold()->build();
|
||||
$style2 = (new StyleBuilder())->setFontSize(15)->build();
|
||||
|
||||
$this->writeToXLSXFileWithMultipleStyles($dataRows, $fileName, [$style, $style2, null]);
|
||||
|
||||
$cellDomElements = $this->getCellElementsFromSheetXmlFile($fileName);
|
||||
$this->assertEquals(3, count($cellDomElements), 'There should be 3 cells.');
|
||||
|
||||
$this->assertEquals('1', $cellDomElements[0]->getAttribute('s'));
|
||||
$this->assertEquals('2', $cellDomElements[1]->getAttribute('s'));
|
||||
$this->assertEquals('0', $cellDomElements[2]->getAttribute('s'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testAddRowWithStyleShouldReuseDuplicateStyles()
|
||||
{
|
||||
$fileName = 'test_add_row_with_style_should_reuse_duplicate_styles.xlsx';
|
||||
$dataRows = [
|
||||
['xlsx--11'],
|
||||
['xlsx--21'],
|
||||
];
|
||||
$style = (new StyleBuilder())->setFontBold()->build();
|
||||
|
||||
$this->writeToXLSXFile($dataRows, $fileName, $style);
|
||||
|
||||
$cellDomElements = $this->getCellElementsFromSheetXmlFile($fileName);
|
||||
$this->assertEquals('1', $cellDomElements[0]->getAttribute('s'));
|
||||
$this->assertEquals('1', $cellDomElements[1]->getAttribute('s'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $allRows
|
||||
* @param string $fileName
|
||||
* @param \Box\Spout\Writer\Style\Style $style
|
||||
* @return Writer
|
||||
*/
|
||||
private function writeToXLSXFile($allRows, $fileName, $style)
|
||||
{
|
||||
$this->createGeneratedFolderIfNeeded($fileName);
|
||||
$resourcePath = $this->getGeneratedResourcePath($fileName);
|
||||
|
||||
/** @var \Box\Spout\Writer\XLSX\Writer $writer */
|
||||
$writer = WriterFactory::create(Type::XLSX);
|
||||
$writer->setShouldUseInlineStrings(true);
|
||||
|
||||
$writer->openToFile($resourcePath);
|
||||
$writer->addRowsWithStyle($allRows, $style);
|
||||
$writer->close();
|
||||
|
||||
return $writer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $allRows
|
||||
* @param string $fileName
|
||||
* @param \Box\Spout\Writer\Style\Style|null[] $styles
|
||||
* @return Writer
|
||||
*/
|
||||
private function writeToXLSXFileWithMultipleStyles($allRows, $fileName, $styles)
|
||||
{
|
||||
// there should be as many rows as there are styles passed in
|
||||
$this->assertEquals(count($allRows), count($styles));
|
||||
|
||||
$this->createGeneratedFolderIfNeeded($fileName);
|
||||
$resourcePath = $this->getGeneratedResourcePath($fileName);
|
||||
|
||||
/** @var \Box\Spout\Writer\XLSX\Writer $writer */
|
||||
$writer = WriterFactory::create(Type::XLSX);
|
||||
$writer->setShouldUseInlineStrings(true);
|
||||
|
||||
$writer->openToFile($resourcePath);
|
||||
for ($i = 0; $i < count($allRows); $i++) {
|
||||
if ($styles[$i] === null) {
|
||||
$writer->addRow($allRows[$i]);
|
||||
} else {
|
||||
$writer->addRowWithStyle($allRows[$i], $styles[$i]);
|
||||
}
|
||||
}
|
||||
$writer->close();
|
||||
|
||||
return $writer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $fileName
|
||||
* @param string $section
|
||||
* @return \DomElement
|
||||
*/
|
||||
private function getXmlSectionFromStylesXmlFile($fileName, $section)
|
||||
{
|
||||
$resourcePath = $this->getGeneratedResourcePath($fileName);
|
||||
$pathToStylesXmlFile = $resourcePath . '#xl/styles.xml';
|
||||
|
||||
$xmlReader = new \XMLReader();
|
||||
$xmlReader->open('zip://' . $pathToStylesXmlFile);
|
||||
|
||||
while ($xmlReader->read() && ($xmlReader->nodeType !== \XMLReader::ELEMENT || $xmlReader->name !== $section)) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
return $xmlReader->expand();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $fileName
|
||||
* @return \DOMNode[]
|
||||
*/
|
||||
private function getCellElementsFromSheetXmlFile($fileName)
|
||||
{
|
||||
$cellElements = [];
|
||||
|
||||
$resourcePath = $this->getGeneratedResourcePath($fileName);
|
||||
$pathToStylesXmlFile = $resourcePath . '#xl/worksheets/sheet1.xml';
|
||||
|
||||
$xmlReader = new \XMLReader();
|
||||
$xmlReader->open('zip://' . $pathToStylesXmlFile);
|
||||
|
||||
while ($xmlReader->read()) {
|
||||
if ($xmlReader->nodeType === \XMLReader::ELEMENT && $xmlReader->name === 'c') {
|
||||
$cellElements[] = $xmlReader->expand();
|
||||
}
|
||||
}
|
||||
|
||||
return $cellElements;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $expectedValue
|
||||
* @param \DOMNode $parentElement
|
||||
* @param string $childTagName
|
||||
* @param string $attributeName
|
||||
* @return void
|
||||
*/
|
||||
private function assertFirstChildHasAttributeEquals($expectedValue, $parentElement, $childTagName, $attributeName)
|
||||
{
|
||||
$this->assertEquals($expectedValue, $parentElement->getElementsByTagName($childTagName)->item(0)->getAttribute($attributeName));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $expectedNumber
|
||||
* @param \DOMNode $parentElement
|
||||
* @param string $message
|
||||
* @return void
|
||||
*/
|
||||
private function assertChildrenNumEquals($expectedNumber, $parentElement, $message)
|
||||
{
|
||||
$this->assertEquals($expectedNumber, $parentElement->getElementsByTagName('*')->length, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \DOMNode $parentElement
|
||||
* @param string $childTagName
|
||||
* @return void
|
||||
*/
|
||||
private function assertChildExists($parentElement, $childTagName)
|
||||
{
|
||||
$this->assertEquals(1, $parentElement->getElementsByTagName($childTagName)->length);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user