public function testRowRepeating()
 {
     $document = new DOMDocument();
     $document->preserveWhiteSpace = false;
     $document->load(dirname(__FILE__) . '/document.xml');
     $templatePath = dirname(__FILE__) . '/template.docx';
     $template = new ZipArchive();
     $template->open($templatePath, ZipArchive::CREATE);
     $template->addFromString("word/document.xml", $document->saveXML());
     $template->close();
     $docxTemplate = new DocxTemplate($templatePath);
     $outputPath = dirname(__FILE__) . '/mergedOutput.docx';
     if (file_exists($outputPath)) {
         unlink($outputPath);
     }
     $this->assertFalse(file_exists($outputPath));
     //testing merge method
     $data = array("host" => array("name" => "My Company"));
     $record = array("items" => array(array("name" => "item1"), array("name" => "item2"), array("name" => "item3")));
     $data["record"] = $record;
     $docxTemplate->merge($data, $outputPath);
     $resultZip = new ZipArchive();
     $resultZip->open($outputPath);
     $resultZip->extractTo($outputPath . "_");
     $resultDoc = new DOMDocument();
     $resultDoc->load($outputPath . "_" . "/word/document.xml");
     //$expectedXML = '<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"><w:body><w:p w:rsidR="00927B0C" w:rsidRDefault="005E5E04"><w:r><w:t/></w:r><w:r w:rsidRPr="005E5E04"><w:t>My Company</w:t></w:r></w:p><w:p w:rsidR="005E5E04" w:rsidRDefault="005E5E04"/><w:p w:rsidR="005E5E04" w:rsidRDefault="005E5E04" w:rsidP="005E5E04"><w:pPr><w:pStyle w:val="Heading1"/></w:pPr><w:proofErr w:type="spellStart"/><w:r><w:t>Address : [host.addre</w:t><w:t>ss</w:t></w:r><w:proofErr w:type="spellEnd"/></w:p><w:p><w:r><w:t xml:space="preserve">Phone : </w:t><w:t/><w:t>[host.phone] </w:t></w:r></w:p><w:sectPr w:rsidR="005E5E04" w:rsidSect="00927B0C"><w:pgSz w:w="12240" w:h="15840"/><w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440" w:header="720" w:footer="720" w:gutter="0"/><w:cols w:space="720"/><w:docGrid w:linePitch="360"/></w:sectPr></w:body></w:document>';
     //$this->assertTrue($resultDoc->saveXML($resultDoc->documentElement) == $expectedXML);
 }
 public function testMerge()
 {
     $templatePath = dirname(__FILE__) . '/template.docx';
     $docxTemplate = new DocxTemplate($templatePath);
     $outputPath = dirname(__FILE__) . '/mergedOutput.docx';
     if (file_exists($outputPath)) {
         unlink($outputPath);
     }
     $this->assertFalse(file_exists($outputPath));
     $data = array();
     $host = array();
     $host["name"] = "My Company";
     $host["address"] = "No25, Street 1, 2nd Avenue";
     $host["phoneNo"] = "+91 80 2236 1234";
     $host["emailId"] = "*****@*****.**";
     $host["tinNo"] = "021256369974";
     $host["panNo"] = "ABCDE1234Z";
     $host["cst"] = "CST1234546789";
     $host["logo"] = dirname(__FILE__) . '/logo.png';
     $data["host"] = $host;
     $record = array();
     $record["no"] = "PO000001";
     $record["date"] = "26-Mar-2015";
     $quotation = array();
     $quotation["no"] = "QUOT000001";
     $quotation["date"] = "01-Mar-2015";
     $record["quotation"] = $quotation;
     $org = array();
     $org["name"] = "The Other Company";
     $org["address"] = "No65, Street 3, 1st Avenue";
     $record["org"] = $org;
     $record["netAmount"] = "25,000.00";
     $items = array();
     $item = array();
     $item["name"] = "P001";
     $item["quantity"] = "3";
     $item["rate"] = "900.00";
     $item["discount"] = "10";
     $item["totalPrice"] = "2,430.00";
     $items[] = $item;
     $item = array();
     $item["name"] = "P002";
     $item["quantity"] = "10";
     $item["rate"] = "1,500.00";
     $item["discount"] = "5";
     $item["totalPrice"] = "14,250.00";
     $items[] = $item;
     $item = array();
     $item["name"] = "P003";
     $item["quantity"] = "1";
     $item["rate"] = "8,320.00";
     $item["discount"] = "0";
     $item["totalPrice"] = "8,320.00";
     $items[] = $item;
     $record["items"] = $items;
     $data["record"] = $record;
     //testing merge method
     $docxTemplate->merge($data, $outputPath);
     $this->assertTrue(file_exists($outputPath));
 }
 public function testMerge()
 {
     $templatePath = dirname(__FILE__) . '/template.docx';
     $docxTemplate = new DocxTemplate($templatePath);
     $outputPath = dirname(__FILE__) . '/mergedOutput.docx';
     if (file_exists($outputPath)) {
         unlink($outputPath);
     }
     $this->assertFalse(file_exists($outputPath));
     //testing merge method
     $docxTemplate->merge(array(), $outputPath);
     $this->assertTrue(file_exists($outputPath));
 }
 public function testMerge()
 {
     $templatePath = dirname(__FILE__) . '/template.docx';
     $docxTemplate = new DocxTemplate($templatePath);
     $outputDir = dirname(__FILE__) . '/output';
     if (file_exists($outputDir)) {
         DocxTemplate::deleteDir($outputDir);
     }
     $this->assertFalse(file_exists($outputDir));
     mkdir($outputDir, 0777, true);
     $outputPath = $outputDir . '/mergedOutput.docx';
     if (file_exists($outputPath)) {
         unlink($outputPath);
     }
     $record = array();
     $record["headerImage"] = dirname(__FILE__) . '/headerImage.png';
     $record["bodyImage"] = dirname(__FILE__) . '/bodyImage.png';
     $record["footerImage"] = dirname(__FILE__) . '/footerImage.png';
     $this->assertFalse(file_exists($outputPath));
     //testing merge method
     $docxTemplate->merge(array("record" => $record), $outputPath);
     $this->assertTrue(file_exists($outputPath));
     $resultZip = new ZipArchive();
     $resultZip->open($outputPath);
     $resultZip->extractTo($outputPath . "_");
     $resultDoc = new DOMDocument();
     $resultDoc->load($outputPath . "_" . "/word/_rels/header1.xml.rels");
     $relElements = $resultDoc->documentElement->getElementsByTagName('Relationship');
     $this->assertTrue($relElements->length == 2);
     $resultDoc = new DOMDocument();
     $resultDoc->load($outputPath . "_" . "/word/_rels/document.xml.rels");
     $relElements = $resultDoc->documentElement->getElementsByTagName('Relationship');
     $this->assertTrue($relElements->length == 12);
     $resultDoc = new DOMDocument();
     $resultDoc->load($outputPath . "_" . "/word/_rels/footer1.xml.rels");
     $relElements = $resultDoc->documentElement->getElementsByTagName('Relationship');
     $this->assertTrue($relElements->length == 2);
     $this->assertTrue(count(array_diff(scandir($outputPath . "_" . "/word/media"), array(".", ".."))) == 4);
 }