Passed
Pull Request — master (#4263)
by Owen
30:17 queued 17:47
created

IndentTest::tearDown()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
dl 0
loc 4
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpOffice\PhpSpreadsheetTests\Writer\Ods;
6
7
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
8
use PhpOffice\PhpSpreadsheet\Spreadsheet;
9
use PhpOffice\PhpSpreadsheet\Writer\Ods;
10
use PhpOffice\PhpSpreadsheet\Writer\Ods\Content;
11
use PHPUnit\Framework\TestCase;
12
13
class IndentTest extends TestCase
14
{
15
    private string $compatibilityMode;
16
17
    protected function setUp(): void
18
    {
19
        $this->compatibilityMode = Functions::getCompatibilityMode();
20
        Functions::setCompatibilityMode(
21
            Functions::COMPATIBILITY_OPENOFFICE
22
        );
23
    }
24
25
    protected function tearDown(): void
26
    {
27
        parent::tearDown();
28
        Functions::setCompatibilityMode($this->compatibilityMode);
29
    }
30
31
    public function testWriteSpreadsheet(): void
32
    {
33
        $spreadsheet = new Spreadsheet();
34
        $sheet = $spreadsheet->getActiveSheet();
35
        $sheet->setCellValue('A1', 'aa');
36
        $sheet->setCellValue('B1', 'bb');
37
        $sheet->setCellValue('A2', 'cc');
38
        $sheet->setCellValue('B2', 'dd');
39
        $sheet->getStyle('A1')->getAlignment()->setIndent(2);
40
        $writer = new Ods($spreadsheet);
41
        $content = new Content($writer);
42
        $xml = $content->write();
43
        self::assertStringContainsString(
44
            '<style:style style:name="ce0" style:family="table-cell" style:parent-style-name="Default">'
45
                . '<style:table-cell-properties style:vertical-align="bottom" style:rotation-align="none"/>'
46
                . '<style:text-properties fo:color="#000000" fo:font-family="Calibri" fo:font-size="11.0pt"/>'
47
                . '</style:style>',
48
            $xml
49
        );
50
        self::assertStringContainsString(
51
            '<style:style style:name="ce1" style:family="table-cell" style:parent-style-name="Default">'
52
                . '<style:table-cell-properties style:vertical-align="bottom" style:rotation-align="none"/>'
53
                . '<style:paragraph-properties fo:margin-left="0.2086in"/>' // fo:margin-left is what we're looking for
54
                . '<style:text-properties fo:color="#000000" fo:font-family="Calibri" fo:font-size="11.0pt"/>'
55
                . '</style:style>',
56
            $xml
57
        );
58
        self::assertSame(3, substr_count($xml, 'table:style-name="ce0"'));
59
        self::assertSame(1, substr_count($xml, 'table:style-name="ce1"'));
60
        $spreadsheet->disconnectWorksheets();
61
    }
62
}
63