Skip to content

Commit 7ef7852

Browse files
committed
Add Writer Unit Testing For Axis Fonts
1 parent d873141 commit 7ef7852

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

tests/PhpPresentation/Tests/Writer/ODPresentation/ChartsTest.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@
2020
use PhpOffice\PhpPresentation\PhpPresentation;
2121
use PhpOffice\PhpPresentation\Shape\Chart\Series;
2222
use PhpOffice\PhpPresentation\Shape\Chart\Type\Bar3D;
23+
use PhpOffice\PhpPresentation\Shape\Chart\Type\Bar;
2324
use PhpOffice\PhpPresentation\Shape\Chart\Type\Line;
2425
use PhpOffice\PhpPresentation\Shape\Chart\Type\Pie;
2526
use PhpOffice\PhpPresentation\Shape\Chart\Type\Pie3D;
2627
use PhpOffice\PhpPresentation\Shape\Chart\Type\Scatter;
2728
use PhpOffice\PhpPresentation\Style\Color;
2829
use PhpOffice\PhpPresentation\Style\Fill;
30+
use PhpOffice\PhpPresentation\Style\Font;
2931
use PhpOffice\PhpPresentation\Writer\ODPresentation;
3032
use PhpOffice\PhpPresentation\Tests\TestHelperDOCX;
3133

@@ -84,6 +86,45 @@ public function testTitleVisibility()
8486
$this->assertFalse($oXMLDoc->elementExists($elementStyle, 'Object 1/content.xml'));
8587
}
8688

89+
public function testAxisFont()
90+
{
91+
92+
$phpPresentation = new PhpPresentation();
93+
$oSlide = $phpPresentation->getActiveSlide();
94+
$oShape = $oSlide->createChartShape();
95+
$oSeries = new Series('Series', array('Jan' => 1, 'Feb' => 5, 'Mar' => 2));
96+
$oBar = new Bar();
97+
$oBar->addSeries($oSeries);
98+
$oShape->getPlotArea()->setType($oBar);
99+
$oShape->getPlotArea()->getAxisX()->getFont()->getColor()->setRGB('AABBCC');
100+
$oShape->getPlotArea()->getAxisX()->getFont()->setItalic(true);
101+
102+
$oShape->getPlotArea()->getAxisY()->getFont()->getColor()->setRGB('00FF00');
103+
$oShape->getPlotArea()->getAxisY()->getFont()->setSize(16);
104+
$oShape->getPlotArea()->getAxisY()->getFont()->setName('Arial');
105+
106+
$pres = TestHelperDOCX::getDocument($phpPresentation, 'ODPresentation');
107+
108+
$element = '/office:document-content/office:body/office:chart/chart:chart';
109+
$this->assertTrue($pres->elementExists($element, 'Object 1/content.xml'));
110+
$this->assertEquals('chart:bar', $pres->getElementAttribute($element, 'chart:class', 'Object 1/content.xml'));
111+
112+
$element = '/office:document-content/office:automatic-styles/style:style[@style:name=\'styleAxisX\']/style:text-properties';
113+
$this->assertTrue($pres->elementExists($element, 'Object 1/content.xml'));
114+
$this->assertEquals('#AABBCC', $pres->getElementAttribute($element, 'fo:color', 'Object 1/content.xml'));//Color XAxis
115+
$this->assertEquals('italic', $pres->getElementAttribute($element, 'fo:font-style', 'Object 1/content.xml'));//Italic XAxis
116+
$this->assertEquals('10pt', $pres->getElementAttribute($element, 'fo:font-size', 'Object 1/content.xml'));//Size XAxis
117+
$this->assertEquals('Calibri', $pres->getElementAttribute($element, 'fo:font-family', 'Object 1/content.xml'));//Size XAxis
118+
119+
$element = '/office:document-content/office:automatic-styles/style:style[@style:name=\'styleAxisY\']/style:text-properties';
120+
$this->assertTrue($pres->elementExists($element, 'Object 1/content.xml'));
121+
$this->assertEquals('#00FF00', $pres->getElementAttribute($element, 'fo:color', 'Object 1/content.xml'));//Color YAxis
122+
$this->assertEquals('normal', $pres->getElementAttribute($element, 'fo:font-style', 'Object 1/content.xml'));//Italic YAxis
123+
$this->assertEquals('16pt', $pres->getElementAttribute($element, 'fo:font-size', 'Object 1/content.xml'));//Size YAxis
124+
$this->assertEquals('Arial', $pres->getElementAttribute($element, 'fo:font-family', 'Object 1/content.xml'));//Size YAxis
125+
126+
}
127+
87128
public function testChartBar3D()
88129
{
89130
$oSeries = new Series('Series', array('Jan' => 1, 'Feb' => 5, 'Mar' => 2));

tests/PhpPresentation/Tests/Writer/PowerPoint2007/PptChartsTest.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use PhpOffice\PhpPresentation\Shape\Chart\Type\Pie3D;
1919
use PhpOffice\PhpPresentation\Shape\Chart\Type\Scatter;
2020
use PhpOffice\PhpPresentation\Style\Color;
21+
use PhpOffice\PhpPresentation\Style\Font;
2122
use PhpOffice\PhpPresentation\Style\Fill;
2223
use PhpOffice\PhpPresentation\Tests\TestHelperDOCX;
2324

@@ -89,6 +90,42 @@ public function testTitleVisibility()
8990
$this->assertEquals('1', $oXMLDoc->getElementAttribute($element, 'val', 'ppt/charts/'.$oShape->getIndexedFilename()));
9091
}
9192

93+
public function testAxisFont()
94+
{
95+
$oSlide = $this->oPresentation->getActiveSlide();
96+
$oShape = $oSlide->createChartShape();
97+
$oBar = new Bar();
98+
$oSeries = new Series('Downloads', $this->seriesData);
99+
$oBar->addSeries($oSeries);
100+
$oShape->getPlotArea()->setType($oBar);
101+
$oShape->getPlotArea()->getAxisX()->getFont()->getColor()->setRGB('AABBCC');
102+
$oShape->getPlotArea()->getAxisX()->getFont()->setItalic(true);
103+
$oShape->getPlotArea()->getAxisX()->getFont()->setStrikethrough(true);
104+
$oShape->getPlotArea()->getAxisY()->getFont()->getColor()->setRGB('00FF00');
105+
$oShape->getPlotArea()->getAxisY()->getFont()->setSize(16);
106+
$oShape->getPlotArea()->getAxisY()->getFont()->setUnderline(Font::UNDERLINE_DASH);
107+
108+
$oXMLDoc = TestHelperDOCX::getDocument($this->oPresentation, 'PowerPoint2007');
109+
$element = '/c:chartSpace/c:chart/c:plotArea/c:catAx/c:txPr/a:p/a:pPr/a:defRPr/a:solidFill/a:srgbClr';
110+
$this->assertTrue($oXMLDoc->elementExists($element, 'ppt/charts/'.$oShape->getIndexedFilename()));
111+
$this->assertEquals('AABBCC', $oXMLDoc->getElementAttribute($element, 'val', 'ppt/charts/'.$oShape->getIndexedFilename())); //Color XAxis
112+
$element = '/c:chartSpace/c:chart/c:plotArea/c:catAx/c:txPr/a:p/a:pPr/a:defRPr';
113+
$this->assertTrue($oXMLDoc->elementExists($element, 'ppt/charts/'.$oShape->getIndexedFilename()));
114+
$this->assertEquals('true',$oXMLDoc->getElementAttribute($element, 'i', 'ppt/charts/'.$oShape->getIndexedFilename())); //Italic XAxis
115+
$this->assertEquals(10*100, $oXMLDoc->getElementAttribute($element, 'sz', 'ppt/charts/'.$oShape->getIndexedFilename())); //Size XAxis
116+
$this->assertEquals('sngStrike', $oXMLDoc->getElementAttribute($element, 'strike', 'ppt/charts/'.$oShape->getIndexedFilename())); //StrikeThrough XAxis
117+
$this->assertEquals(Font::UNDERLINE_NONE, $oXMLDoc->getElementAttribute($element, 'u', 'ppt/charts/'.$oShape->getIndexedFilename())); //Underline XAxis
118+
$element = '/c:chartSpace/c:chart/c:plotArea/c:valAx/c:txPr/a:p/a:pPr/a:defRPr/a:solidFill/a:srgbClr';
119+
$this->assertTrue($oXMLDoc->elementExists($element, 'ppt/charts/'.$oShape->getIndexedFilename()));
120+
$this->assertEquals('00FF00', $oXMLDoc->getElementAttribute($element, 'val', 'ppt/charts/'.$oShape->getIndexedFilename())); //Color YAxis
121+
$element = '/c:chartSpace/c:chart/c:plotArea/c:valAx/c:txPr/a:p/a:pPr/a:defRPr';
122+
$this->assertTrue($oXMLDoc->elementExists($element, 'ppt/charts/'.$oShape->getIndexedFilename()));
123+
$this->assertEquals('false',$oXMLDoc->getElementAttribute($element, 'i', 'ppt/charts/'.$oShape->getIndexedFilename())); //Italic YAxis
124+
$this->assertEquals(16*100, $oXMLDoc->getElementAttribute($element, 'sz', 'ppt/charts/'.$oShape->getIndexedFilename())); //Size YAxis
125+
$this->assertEquals('noStrike', $oXMLDoc->getElementAttribute($element, 'strike', 'ppt/charts/'.$oShape->getIndexedFilename())); //StrikeThrough YAxis
126+
$this->assertEquals(Font::UNDERLINE_DASH, $oXMLDoc->getElementAttribute($element, 'u', 'ppt/charts/'.$oShape->getIndexedFilename())); //Underline YAxis
127+
}
128+
92129
public function testTypeArea()
93130
{
94131
$oSlide = $this->oPresentation->getActiveSlide();

0 commit comments

Comments
 (0)