summaryrefslogtreecommitdiffstats
path: root/tests/Plugin/ConditionalFormatFixerTest.php
blob: e0d97ac248e5df141f503d3404028a5ca3c7a9c7 (plain)
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
<?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;
    }
}