summaryrefslogtreecommitdiffstats
path: root/tests/Plugin
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Plugin')
-rw-r--r--tests/Plugin/BasePluginTest.php49
-rw-r--r--tests/Plugin/CellStyleFixerTest.php67
-rw-r--r--tests/Plugin/ConditionalFormatFixerTest.php44
3 files changed, 160 insertions, 0 deletions
diff --git a/tests/Plugin/BasePluginTest.php b/tests/Plugin/BasePluginTest.php
new file mode 100644
index 0000000..0686eb4
--- /dev/null
+++ b/tests/Plugin/BasePluginTest.php
@@ -0,0 +1,49 @@
+<?php
+
+
+namespace PHPExcel\StyleFixer\Plugin;
+
+
+abstract class BasePluginTest extends \PHPUnit_Framework_TestCase
+{
+ private $basePath;
+
+ public function setUp()
+ {
+ $this->basePath = __DIR__.'/../xml';
+ }
+
+ public function getOutputXml($path)
+ {
+ return file_get_contents($this->basePath.'/output/'.$path);
+ }
+
+ public function getTemplateXml($path)
+ {
+ return file_get_contents($this->basePath.'/template/'.$path);
+ }
+
+ /**
+ * @param int $count
+ * @param array $map
+ * @return \PHPUnit_Framework_MockObject_MockObject
+ */
+ protected function createBookUtil($count, $map)
+ {
+ $bookUtil = $this->getMock('PHPExcel\StyleFixer\Util\Book');
+ $bookUtil
+ ->expects($this->exactly($count))
+ ->method('makeSheetMap')
+ ->with($this->isInstanceOf('\ZipArchive'))
+ ->will($this->returnValue($map))
+ ;
+
+ return $bookUtil;
+ }
+
+ public function tearDown()
+ {
+ $this->output_stylesXml = '';
+ $this->template_stylesXml = '';
+ }
+}
diff --git a/tests/Plugin/CellStyleFixerTest.php b/tests/Plugin/CellStyleFixerTest.php
new file mode 100644
index 0000000..a30478a
--- /dev/null
+++ b/tests/Plugin/CellStyleFixerTest.php
@@ -0,0 +1,67 @@
+<?php
+
+
+namespace PHPExcel\StyleFixer\Plugin;
+
+use PHPExcel\StyleFixer\Util\Sheet;
+
+class CellStyleFixerTest extends BasePluginTest
+{
+ public function test_execute()
+ {
+ $output = $this->getMock('\ZipArchive');
+ $template = $this->getMock('\ZipArchive');
+ $bookUtil = $this->createBookUtil(2, ['Sheet1' => 'xl/worksheets/sheet1.xml', 'Sheet2' => 'xl/worksheets/sheet2.xml']);
+ $bookUtil
+ ->expects($this->once())
+ ->method('makePrintAreaMap')
+ ->with($this->isInstanceOf('\ZipArchive'))
+ ->will($this->returnValue(['Sheet1' => 'Sheet1!$A$18:$A$18', 'Sheet2' => 'Sheet2!$A$18:$A$18']))
+ ;
+ $sheetUtil = new Sheet();
+
+ $output
+ ->expects($this->exactly(2))
+ ->method('getFromName')
+ ->with($this->logicalOr('xl/worksheets/sheet1.xml', 'xl/worksheets/sheet2.xml'))
+ ->will($this->returnCallback([$this, 'getOutputXml']))
+ ;
+ $template
+ ->expects($this->exactly(2))
+ ->method('getFromName')
+ ->with($this->logicalOr('xl/worksheets/sheet1.xml', 'xl/worksheets/sheet2.xml'))
+ ->will($this->returnCallback([$this, 'getTemplateXml']))
+ ;
+ $output
+ ->expects($this->exactly(2))
+ ->method('addFromString')
+ ->with($this->logicalOr('xl/worksheets/sheet1.xml', 'xl/worksheets/sheet2.xml'), $this->callback([$this, 'assertXmlHasExpectedContent']))
+ ;
+
+ $fixer = new CellStyleFixer($bookUtil, $sheetUtil);
+ $fixer->execute($output, $template);
+ }
+
+ public function assertXmlHasExpectedContent($xml)
+ {
+ // 行スタイルが修復されている
+ $this->assertContains('<row r="18" s="99">', $xml);
+ $this->assertNotContains('<row r="18" s="11">', $xml);
+ // セルスタイルが修復されている
+ $this->assertContains('<c r="A18" s="33"', $xml);
+ $this->assertNotContains('<c r="A18" s="11"', $xml);
+ if (strpos($xml, 'B18')) {
+ // 印刷範囲外でも値があるセルは修復する
+ $this->assertContains('<c r="B18" s="33"', $xml);
+ $this->assertNotContains('<c r="B18" s="11"', $xml);
+ }
+ if (strpos($xml, 'C18')) {
+ // 印刷範囲外で値もないセルは修復せずスタイル情報を破棄
+ $this->assertContains('<c r="C18"/>', $xml);
+ $this->assertNotContains('<c r="C18" s="33"', $xml);
+ $this->assertNotContains('<c r="C18" s="11"', $xml);
+ }
+
+ return true;
+ }
+}
diff --git a/tests/Plugin/ConditionalFormatFixerTest.php b/tests/Plugin/ConditionalFormatFixerTest.php
new file mode 100644
index 0000000..e0d97ac
--- /dev/null
+++ b/tests/Plugin/ConditionalFormatFixerTest.php
@@ -0,0 +1,44 @@
+<?php
+
+
+namespace PHPExcel\StyleFixer\Plugin;
+
+
+class ConditionalFormatFixerTest extends BasePluginTest
+{
+ public function test_execute()
+ {
+ $output = $this->getMock('\ZipArchive');
+ $template = $this->getMock('\ZipArchive');
+ $bookUtil = $this->createBookUtil(2, ['Sheet1' => 'xl/worksheets/sheet1.xml', 'Sheet2' => 'xl/worksheets/sheet2.xml']);
+
+ $output
+ ->expects($this->exactly(2))
+ ->method('getFromName')
+ ->with($this->logicalOr('xl/worksheets/sheet1.xml', 'xl/worksheets/sheet2.xml'))
+ ->will($this->returnCallback([$this, 'getOutputXml']))
+ ;
+ $template
+ ->expects($this->once())
+ ->method('getFromName')
+ ->with($this->equalTo('xl/worksheets/sheet2.xml'))
+ ->will($this->returnCallback([$this, 'getTemplateXml']))
+ ;
+ $output
+ ->expects($this->once())
+ ->method('addFromString')
+ ->with($this->equalTo('xl/worksheets/sheet2.xml'), $this->callback([$this, 'assertXmlHasExpectedContent']))
+ ;
+
+ $fixer = new ConditionalFormatFixer($bookUtil);
+ $fixer->execute($output, $template);
+ }
+
+ public function assertXmlHasExpectedContent($xml)
+ {
+ $this->assertContains('<conditionalFormatting><font/></conditionalFormatting>', $xml);
+ $this->assertNotContains('<conditionalFormatting/>', $xml);
+
+ return true;
+ }
+}