Skip to content

Commit abd53a0

Browse files
committed
Additional Tests
1 parent ffe88c1 commit abd53a0

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

tests/PhpSpreadsheetTests/SpreadsheetCopyCloneTest.php

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace PhpOffice\PhpSpreadsheetTests;
66

77
use PhpOffice\PhpSpreadsheet\Spreadsheet;
8+
use PHPUnit\Framework\Attributes\DataProvider;
89
use PHPUnit\Framework\TestCase;
910

1011
class SpreadsheetCopyCloneTest extends TestCase
@@ -25,7 +26,8 @@ protected function tearDown(): void
2526
}
2627
}
2728

28-
public function runTests(string $type): void
29+
#[DataProvider('providerCopyClone')]
30+
public function testCopyClone(string $type): void
2931
{
3032
$this->spreadsheet = new Spreadsheet();
3133
$sheet = $this->spreadsheet->getActiveSheet();
@@ -41,12 +43,15 @@ public function runTests(string $type): void
4143
$sheet->getCell('B1')->setValue('this is b1');
4244
$sheet->getCell('B2')->setValue('this is b2');
4345
self::assertSame('font1', $sheet->getStyle('A1')->getFont()->getName());
46+
$sheet->setSelectedCells('A3');
4447
if ($type === 'copy') {
4548
$this->spreadsheet2 = $this->spreadsheet->copy();
4649
} else {
4750
$this->spreadsheet2 = clone $this->spreadsheet;
4851
}
52+
self::assertSame('A3', $sheet->getSelectedCells());
4953
$copysheet = $this->spreadsheet2->getActiveSheet();
54+
self::assertSame('A3', $copysheet->getSelectedCells());
5055
self::assertSame('original', $copysheet->getTitle());
5156
$copysheet->setTitle('unoriginal');
5257
self::assertSame('original', $sheet->getTitle());
@@ -77,13 +82,30 @@ public function runTests(string $type): void
7782
self::assertSame('this is b2', $copysheet->getCell('B2')->getValue());
7883
}
7984

80-
public function testClone(): void
85+
#[DataProvider('providerCopyClone')]
86+
public function testCopyCloneActiveSheet(string $type): void
8187
{
82-
$this->runTests('clone');
88+
$this->spreadsheet = new Spreadsheet();
89+
$sheet0 = $this->spreadsheet->getActiveSheet();
90+
$sheet1 = $this->spreadsheet->createSheet();
91+
$sheet2 = $this->spreadsheet->createSheet();
92+
$sheet3 = $this->spreadsheet->createSheet();
93+
$sheet4 = $this->spreadsheet->createSheet();
94+
$sheet3->getStyle('B1')->getFont()->setName('whatever');
95+
$this->spreadsheet->setActiveSheetIndex(2);
96+
if ($type === 'copy') {
97+
$this->spreadsheet2 = $this->spreadsheet->copy();
98+
} else {
99+
$this->spreadsheet2 = clone $this->spreadsheet;
100+
}
101+
self::assertSame(2, $this->spreadsheet2->getActiveSheetIndex());
83102
}
84103

85-
public function testCopy(): void
104+
public static function providerCopyClone(): array
86105
{
87-
$this->runTests('copy');
106+
return [
107+
['copy'],
108+
['clone'],
109+
];
88110
}
89111
}

0 commit comments

Comments
 (0)