1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
<?php
namespace PHPExcel\StyleFixer\Util;
class BookTest extends \PHPUnit_Framework_TestCase
{
public function test_makeSheetMap()
{
$zip = $this->makeZipMock(['xl/workbook.xml', 'xl/_rels/workbook.xml.rels']);
$bookUtil = new Book();
$map = $bookUtil->makeSheetMap($zip);
$this->assertInternalType('array', $map);
$this->assertArrayHasKey('表紙', $map);
$this->assertArrayHasKey('日別_Y', $map);
$this->assertArrayHasKey('日別_YDN', $map);
$this->assertArrayNotHasKey('日別_G', $map);
$this->assertEquals('xl/worksheets/sheet1.xml', $map['表紙']);
}
public function test_makePrintAreaMap()
{
$zip = $this->makeZipMock(['xl/workbook.xml']);
$bookUtil = new Book();
$map = $bookUtil->makePrintAreaMap($zip);
$this->assertInternalType('array', $map);
$this->assertArrayHasKey('表紙', $map);
$this->assertArrayHasKey('日別_Y', $map);
$this->assertArrayHasKey('日別_YDN', $map);
$this->assertArrayNotHasKey('日別_G', $map);
$this->assertEquals('\'日別_Y\'!$A$18:$A$18', $map['日別_Y']);
}
public function test_makeSheetRelationMap()
{
$zip = $this->makeZipMock(['xl/workbook.xml', 'xl/_rels/workbook.xml.rels']);
$bookUtil = new Book();
$map = $bookUtil->makeSheetRelationMap($zip);
$this->assertInternalType('array', $map);
$this->assertArrayHasKey('表紙', $map);
$this->assertArrayHasKey('日別_Y', $map);
$this->assertArrayHasKey('日別_YDN', $map);
$this->assertArrayNotHasKey('日別_G', $map);
$this->assertEquals('xl/worksheets/_rels/sheet1.xml.rels', $map['表紙']);
}
public function test_makeDrawingMap()
{
$zip = $this->makeZipMock(['xl/workbook.xml', 'xl/_rels/workbook.xml.rels', 'xl/worksheets/_rels/sheet1.xml.rels', 'xl/worksheets/_rels/sheet2.xml.rels', 'xl/worksheets/_rels/sheet3.xml.rels']);
$bookUtil = new Book();
$map = $bookUtil->makeDrawingMap($zip);
$this->assertInternalType('array', $map);
$this->assertArrayNotHasKey('表紙', $map);
$this->assertArrayHasKey('日別_Y', $map);
$this->assertArrayHasKey('日別_YDN', $map);
$this->assertEquals(['xl/drawings/drawing1.xml', 'xl/drawings/drawing2.xml'], $map['日別_Y']);
}
/**
* @param string $fileNames
* @return \ZipArchive|\PHPUnit_Framework_MockObject_MockObject
*/
private function makeZipMock($fileNames)
{
$zip = $this->getMock('\ZipArchive');
$zip
->expects($this->exactly(count($fileNames)))
->method('getFromName')
->with($this->callback(
function($fileName) use ($fileNames){
return in_array($fileName, $fileNames);
}))
->will($this->returnCallback([$this, 'getXml']))
;
return $zip;
}
public function getXml($path)
{
return file_get_contents(__DIR__.'/../xml/template/'.$path);
}
}
|