Files
PhpSpreadsheet/tests/PhpSpreadsheetTests/Functional/ActiveSheetTest.php
T
oleibman 2fac9ee2f7 Stacked Alignment - Use Class Constant Rather than Literal (#1716)
* Stacked Alignment - Use Class Constant Rather than Literal

PR #1580 defined constants for "stacked" alignment in cells.
Using those constants outside of Style/Alignment was beyond the
scope of the original PR, but I said I would get to it.
This PR replaces all uses of literal -165, and appropriate uses of
literal 255, with the named constants, and adds tests to make sure
that the changed code is covered in the test suite.
2021-02-03 23:53:04 +01:00

76 lines
2.1 KiB
PHP

<?php
namespace PhpOffice\PhpSpreadsheetTests\Functional;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Style\Protection;
class ActiveSheetTest extends AbstractFunctional
{
public function providerFormats()
{
return [
['Xls'],
];
}
/**
* Test load file with correct active sheet.
*
* @dataProvider providerFormats
*
* @param string $format
*/
public function testActiveSheet($format): void
{
$spreadsheet = new Spreadsheet();
$spreadsheet->setActiveSheetIndex(0)
->setTitle('Test1')
->setCellValue('D1', 1)
->setCellValue('D2', 2)
->setCellValue('D3', 3)
->setCellValue('D4', 4)
->setCellValue('D5', '=SUM(D1:D4)')
->setSelectedCell('B2');
$spreadsheet->createSheet(1);
$spreadsheet->setActiveSheetIndex(1)
->setTitle('Test2')
->setCellValue('D1', 4)
->setCellValue('E1', 3)
->setCellValue('F1', 2)
->setCellValue('G1', 1)
->setCellValue('H1', '=SUM(D1:G4)')
->setSelectedCells('A1:B2');
$spreadsheet->createSheet(2);
$spreadsheet->setActiveSheetIndex(2)
->setCellValue('F1', 2)
->getCell('F1')
->getStyle()
->getProtection()
->setHidden(Protection::PROTECTION_PROTECTED);
$spreadsheet->setActiveSheetIndex(2)
->setTitle('Test3')
->setCellValue('A1', 4)
->setCellValue('B1', 3)
->setCellValue('C1', 2)
->setCellValue('D1', 1)
->setCellValue('E1', '=SUM(A1:D4)')
->setSelectedCells('A1:D1');
$spreadsheet->setActiveSheetIndex(1);
$reloadedSpreadsheet = $this->writeAndReload($spreadsheet, $format);
// Original object.
self::assertSame(1, $spreadsheet->getActiveSheetIndex());
// Saved and reloaded file.
self::assertSame(1, $reloadedSpreadsheet->getActiveSheetIndex());
}
}