1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Style; |
4
|
|
|
|
5
|
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet; |
6
|
|
|
use PhpOffice\PhpSpreadsheet\Style\Border; |
7
|
|
|
use PhpOffice\PhpSpreadsheet\Style\Color; |
8
|
|
|
use PHPUnit\Framework\TestCase; |
9
|
|
|
|
10
|
|
|
class BorderRangeTest extends TestCase |
11
|
|
|
{ |
12
|
|
|
public function testBorderRangeInAction() |
13
|
|
|
{ |
14
|
|
|
// testcase for the initial bug problem: setting border+color fails |
15
|
|
|
// set red borders aroundlA1:B3 square. Verify that the borders set are actually correct |
16
|
|
|
|
17
|
|
|
$spreadsheet = new Spreadsheet(); |
18
|
|
|
$sheet = $spreadsheet->getActiveSheet(); |
19
|
|
|
|
20
|
|
|
$argb = 'FFFF0000'; |
21
|
|
|
$color = new Color($argb); |
22
|
|
|
|
23
|
|
|
$sheet->getStyle('A1:C1')->getBorders()->getTop()->setBorderStyle(Border::BORDER_THIN)->setColor($color); |
24
|
|
|
$sheet->getStyle('A1:A3')->getBorders()->getLeft()->setBorderStyle(Border::BORDER_THIN)->setColor($color); |
25
|
|
|
$sheet->getStyle('C1:C3')->getBorders()->getRight()->setBorderStyle(Border::BORDER_THIN)->setColor($color); |
26
|
|
|
$sheet->getStyle('A3:C3')->getBorders()->getBottom()->setBorderStyle(Border::BORDER_THIN)->setColor($color); |
27
|
|
|
|
28
|
|
|
// upper row |
29
|
|
|
$expectations = [ |
30
|
|
|
// cell => Left/Right/Top/Bottom |
31
|
|
|
'A1' => 'LT', |
32
|
|
|
'B1' => 'T', |
33
|
|
|
'C1' => 'RT', |
34
|
|
|
'A2' => 'L', |
35
|
|
|
'B2' => '', |
36
|
|
|
'C2' => 'R', |
37
|
|
|
'A3' => 'LB', |
38
|
|
|
'B3' => 'B', |
39
|
|
|
'C3' => 'RB', |
40
|
|
|
]; |
41
|
|
|
$sides = [ |
42
|
|
|
'L' => 'Left', |
43
|
|
|
'R' => 'Right', |
44
|
|
|
'T' => 'Top', |
45
|
|
|
'B' => 'Bottom', |
46
|
|
|
]; |
47
|
|
|
|
48
|
|
|
foreach ($expectations as $cell => $borders) { |
49
|
|
|
$bs = $sheet->getStyle($cell)->getBorders(); |
50
|
|
|
foreach ($sides as $sidekey => $side) { |
51
|
|
|
$assertion = "setBorderStyle on a range of cells, $cell $side"; |
52
|
|
|
$func = "get$side"; |
53
|
|
|
$b = $bs->$func(); // boo |
54
|
|
|
|
55
|
|
|
if (strpos($borders, $sidekey) === false) { |
56
|
|
|
self::assertSame(Border::BORDER_NONE, $b->getBorderStyle(), $assertion); |
57
|
|
|
} else { |
58
|
|
|
self::assertSame(Border::BORDER_THIN, $b->getBorderStyle(), $assertion); |
59
|
|
|
self::assertSame($argb, $b->getColor()->getARGB(), $assertion); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function testBorderRangeDirectly() |
66
|
|
|
{ |
67
|
|
|
// testcase for the underlying problem directly |
68
|
|
|
$spreadsheet = new Spreadsheet(); |
69
|
|
|
$sheet = $spreadsheet->getActiveSheet(); |
70
|
|
|
$style = $sheet->getStyle('A1:C1')->getBorders()->getTop()->setBorderStyle(Border::BORDER_THIN); |
71
|
|
|
self::assertSame('A1:C1', $style->getSelectedCells(), 'getSelectedCells should not change after a style operation on a border range'); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|