public function testGetSetOutline() { $object = new Gridlines(); $oStub = $this->getMock('PhpOffice\\PhpPresentation\\Style\\Outline'); $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Outline', $object->getOutline()); $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Gridlines', $object->setOutline($oStub)); $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Outline', $object->getOutline()); }
public function testTypeLineGridlines() { $arrayTests = array(array('methodAxis' => 'getAxisX', 'methodGrid' => 'setMajorGridlines', 'expectedElement' => '/c:chartSpace/c:chart/c:plotArea/c:catAx/c:majorGridlines/c:spPr/a:ln', 'expectedElementColor' => '/c:chartSpace/c:chart/c:plotArea/c:catAx/c:majorGridlines/c:spPr/a:ln/a:solidFill/a:srgbClr'), array('methodAxis' => 'getAxisX', 'methodGrid' => 'setMinorGridlines', 'expectedElement' => '/c:chartSpace/c:chart/c:plotArea/c:catAx/c:minorGridlines/c:spPr/a:ln', 'expectedElementColor' => '/c:chartSpace/c:chart/c:plotArea/c:catAx/c:minorGridlines/c:spPr/a:ln/a:solidFill/a:srgbClr'), array('methodAxis' => 'getAxisY', 'methodGrid' => 'setMajorGridlines', 'expectedElement' => '/c:chartSpace/c:chart/c:plotArea/c:valAx/c:majorGridlines/c:spPr/a:ln', 'expectedElementColor' => '/c:chartSpace/c:chart/c:plotArea/c:valAx/c:majorGridlines/c:spPr/a:ln/a:solidFill/a:srgbClr'), array('methodAxis' => 'getAxisY', 'methodGrid' => 'setMinorGridlines', 'expectedElement' => '/c:chartSpace/c:chart/c:plotArea/c:valAx/c:minorGridlines/c:spPr/a:ln', 'expectedElementColor' => '/c:chartSpace/c:chart/c:plotArea/c:valAx/c:minorGridlines/c:spPr/a:ln/a:solidFill/a:srgbClr')); $expectedColor = new Color(Color::COLOR_BLUE); foreach ($arrayTests as $arrayTest) { $expectedSizePts = rand(1, 100); $expectedSizeEmu = round(Drawing::pointsToPixels(Drawing::pixelsToEmu($expectedSizePts))); $oPresentation = new PhpPresentation(); $oSlide = $oPresentation->getActiveSlide(); $oShape = $oSlide->createChartShape(); $oLine = new Line(); $oLine->addSeries(new Series('Downloads', array('A' => 1, 'B' => 2, 'C' => 4, 'D' => 3, 'E' => 2))); $oShape->getPlotArea()->setType($oLine); $oGridlines = new Gridlines(); $oGridlines->getOutline()->getFill()->setFillType(Fill::FILL_SOLID)->setStartColor($expectedColor); $oGridlines->getOutline()->setWidth($expectedSizePts); $oShape->getPlotArea()->{$arrayTest['methodAxis']}()->{$arrayTest['methodGrid']}($oGridlines); $oXMLDoc = TestHelperDOCX::getDocument($oPresentation, 'PowerPoint2007'); $this->assertTrue($oXMLDoc->fileExists('ppt/charts/' . $oShape->getIndexedFilename())); $this->assertTrue($oXMLDoc->elementExists($arrayTest['expectedElement'], 'ppt/charts/' . $oShape->getIndexedFilename())); $this->assertTrue($oXMLDoc->attributeElementExists($arrayTest['expectedElement'], 'w', 'ppt/charts/' . $oShape->getIndexedFilename())); $this->assertEquals($expectedSizeEmu, $oXMLDoc->getElementAttribute($arrayTest['expectedElement'], 'w', 'ppt/charts/' . $oShape->getIndexedFilename())); $this->assertTrue($oXMLDoc->elementExists($arrayTest['expectedElementColor'], 'ppt/charts/' . $oShape->getIndexedFilename())); $this->assertTrue($oXMLDoc->attributeElementExists($arrayTest['expectedElementColor'], 'val', 'ppt/charts/' . $oShape->getIndexedFilename())); $this->assertEquals($expectedColor->getRGB(), $oXMLDoc->getElementAttribute($arrayTest['expectedElementColor'], 'val', 'ppt/charts/' . $oShape->getIndexedFilename())); unset($oPresentation); TestHelperDOCX::clear(); } }
/** * @param XMLWriter $objWriter * @param Gridlines $oGridlines */ protected function writeAxisGridlines(XMLWriter $objWriter, Gridlines $oGridlines) { // c:spPr $objWriter->startElement('c:spPr'); // Outline $this->writeOutline($objWriter, $oGridlines->getOutline()); // ##c:spPr $objWriter->endElement(); }
/** * @param Chart\Gridlines $oGridlines * @param string $styleName */ protected function writeGridlineStyle($oGridlines, $styleName) { if (!$oGridlines instanceof Chart\Gridlines) { return; } // style:style $this->xmlContent->startElement('style:style'); $this->xmlContent->writeAttribute('style:name', $styleName); $this->xmlContent->writeAttribute('style:family', 'chart'); // style:style > style:graphic-properties $this->xmlContent->startElement('style:graphic-properties'); $this->xmlContent->writeAttribute('svg:stroke-width', number_format(CommonDrawing::pointsToCentimeters($oGridlines->getOutline()->getWidth()), 2, '.', '') . 'cm'); $this->xmlContent->writeAttribute('svg:stroke-color', '#' . $oGridlines->getOutline()->getFill()->getStartColor()->getRGB()); $this->xmlContent->endElement(); // ##style:style $this->xmlContent->endElement(); }
public function testTypeLineGridlines() { $arrayTests = array(array('dimension' => 'x', 'styleName' => 'styleAxisXGridlinesMajor', 'styleClass' => 'major', 'methodAxis' => 'getAxisX', 'methodGrid' => 'setMajorGridlines'), array('dimension' => 'x', 'styleName' => 'styleAxisXGridlinesMinor', 'styleClass' => 'minor', 'methodAxis' => 'getAxisX', 'methodGrid' => 'setMinorGridlines'), array('dimension' => 'y', 'styleName' => 'styleAxisYGridlinesMajor', 'styleClass' => 'major', 'methodAxis' => 'getAxisY', 'methodGrid' => 'setMajorGridlines'), array('dimension' => 'y', 'styleName' => 'styleAxisYGridlinesMinor', 'styleClass' => 'minor', 'methodAxis' => 'getAxisY', 'methodGrid' => 'setMinorGridlines')); $expectedColor = new Color(Color::COLOR_BLUE); foreach ($arrayTests as $arrayTest) { $expectedSizePts = rand(1, 100); $expectedSizeCm = number_format(CommonDrawing::pointsToCentimeters($expectedSizePts), 2, '.', '') . 'cm'; $expectedElementGrid = '/office:document-content/office:body/office:chart/chart:chart/chart:plot-area/chart:axis[@chart:dimension=\'' . $arrayTest['dimension'] . '\']/chart:grid'; $expectedElementStyle = '/office:document-content/office:automatic-styles/style:style[@style:name=\'' . $arrayTest['styleName'] . '\']/style:graphic-properties'; $oPresentation = new PhpPresentation(); $oSlide = $oPresentation->getActiveSlide(); $oShape = $oSlide->createChartShape(); $oLine = new Line(); $oLine->addSeries(new Series('Downloads', array('A' => 1, 'B' => 2, 'C' => 4, 'D' => 3, 'E' => 2))); $oShape->getPlotArea()->setType($oLine); $oGridlines = new Gridlines(); $oGridlines->getOutline()->getFill()->setFillType(Fill::FILL_SOLID)->setStartColor($expectedColor); $oGridlines->getOutline()->setWidth($expectedSizePts); $oShape->getPlotArea()->{$arrayTest['methodAxis']}()->{$arrayTest['methodGrid']}($oGridlines); $oXMLDoc = TestHelperDOCX::getDocument($oPresentation, 'ODPresentation'); $this->assertTrue($oXMLDoc->fileExists('Object 1/content.xml')); $this->assertTrue($oXMLDoc->elementExists($expectedElementGrid, 'Object 1/content.xml')); $this->assertTrue($oXMLDoc->attributeElementExists($expectedElementGrid, 'chart:style-name', 'Object 1/content.xml')); $this->assertEquals($arrayTest['styleName'], $oXMLDoc->getElementAttribute($expectedElementGrid, 'chart:style-name', 'Object 1/content.xml')); $this->assertTrue($oXMLDoc->attributeElementExists($expectedElementGrid, 'chart:class', 'Object 1/content.xml')); $this->assertEquals($arrayTest['styleClass'], $oXMLDoc->getElementAttribute($expectedElementGrid, 'chart:class', 'Object 1/content.xml')); $this->assertTrue($oXMLDoc->elementExists($expectedElementStyle, 'Object 1/content.xml')); $this->assertStringStartsWith($expectedSizeCm, $oXMLDoc->getElementAttribute($expectedElementStyle, 'svg:stroke-width', 'Object 1/content.xml')); $this->assertStringEndsWith('cm', $oXMLDoc->getElementAttribute($expectedElementStyle, 'svg:stroke-width', 'Object 1/content.xml')); $this->assertStringStartsWith('#', $oXMLDoc->getElementAttribute($expectedElementStyle, 'svg:stroke-color', 'Object 1/content.xml')); $this->assertStringEndsWith($expectedColor->getRGB(), $oXMLDoc->getElementAttribute($expectedElementStyle, 'svg:stroke-color', 'Object 1/content.xml')); unset($oPresentation); TestHelperDOCX::clear(); } }