/** * tests the correct replacement of markers with different contents */ public function testMarkerReplacement() { $doc = new OpenDocument_Document(OpenDocument_Document::SPREADSHEET); $table = $doc->getBody()->appendTable('UNITTEST'); $titleText = 'Hello unittest!'; $row = $table->appendRow(); $cell = $row->appendCell($titleText); $row = $table->appendRow(); $row = $table->appendRow(); $cell = $row->appendCell('###MATRIX###'); $row = $table->appendRow(); $row = $table->appendRow(); $cell = $row->appendCell('###MARKER###'); $filename = Tinebase_Config::getInstance()->get('tmpdir') . DIRECTORY_SEPARATOR . Tinebase_Record_Abstract::generateUID(4) . '-ods-unittest.ods'; $ccc = Sales_Controller_CostCenter::getInstance(); $cc1 = $ccc->create(new Sales_Model_CostCenter(array('number' => 'cc1', 'remark' => 'unittest-cc1'))); $cc2 = $ccc->create(new Sales_Model_CostCenter(array('number' => 'cc2', 'remark' => 'unittest-cc2'))); $colInfo = array(); $colInfo[$cc1->getId()] = $cc1->number; $colInfo[$cc2->getId()] = $cc2->number; $matrixArray = array($cc1->getId() => array($cc2->getId() => '100'), $cc2->getId() => array($cc1->getId() => '200')); $matrix = new OpenDocument_Matrix($matrixArray, $colInfo, $colInfo, OpenDocument_Matrix::TYPE_FLOAT); $matrix->setColumnLegendDescription('Cat'); $matrix->setRowLegendDescription('Dog'); $markerText = 'unittest-marker'; $doc->replaceMarker('marker', $markerText)->replaceMatrix('matrix', $matrix); $doc->getDocument($filename); $contentXml = file_get_contents('zip://' . $filename . '#content.xml'); $xml = simplexml_load_string($contentXml); unlink($filename); $spreadSheets = $xml->xpath('//office:body/office:spreadsheet'); $this->assertEquals(1, count($spreadSheets)); $spreadSheet = $spreadSheets[0]; $results = $spreadSheet->xpath("//text()[contains(., '{$markerText}')]"); $this->assertEquals(1, count($results)); $results = $spreadSheet->xpath("//text()[contains(., '{$titleText}')]"); $this->assertEquals(1, count($results)); $results = $spreadSheet->xpath("//text()[contains(., '{$cc1->number}')]"); $this->assertEquals(2, count($results)); $results = $spreadSheet->xpath("//text()[contains(., '{$cc2->number}')]"); $this->assertEquals(2, count($results)); $results = $spreadSheet->xpath("//text()[contains(., 'Sum')]"); $this->assertEquals(2, count($results)); $results = $spreadSheet->xpath("//text()[contains(., 'Cat')]"); $this->assertEquals(1, count($results)); $results = $spreadSheet->xpath("//text()[contains(., 'Dog')]"); $this->assertEquals(1, count($results)); $results = $spreadSheet->xpath("//text()[contains(., '100')]"); $this->assertEquals(3, count($results)); $results = $spreadSheet->xpath("//text()[contains(., '200')]"); $this->assertEquals(3, count($results)); $results = $spreadSheet->xpath("//text()[contains(., '300')]"); $this->assertEquals(1, count($results)); }
/** * add style/width to column * * @param string $_styleName * @param string $_columnWidth (for example: '2,5cm') */ protected function _addColumnStyle($_styleName, $_columnWidth) { $this->_openDocumentObject->addStyle('<style:style style:name="' . $_styleName . '" style:family="table-column" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0"><style:table-column-properties style:column-width="' . $_columnWidth . '"/></style:style>'); }
/** * add style/width to column * * @param string $styleName * @param string $values */ protected function _addColumnStyle($styleName, $values) { $xml = '<style:style style:name="' . $styleName . '" style:family="table-column" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0"><style:table-column-properties'; foreach ($values as $attr => $value) { $xml .= ' style:' . $attr . '="' . $value . '"'; } $xml .= ' /></style:style>'; $this->_openDocumentObject->addStyle(array($xml)); }