mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-09-11 18:46:49 +00:00
5c94de34a9
Also upgrade Phpstan.
65 lines
2.2 KiB
PHP
65 lines
2.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xls;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Reader\Xls;
|
|
use PhpOffice\PhpSpreadsheet\Style\Conditional;
|
|
use PHPUnit\Framework\Attributes\DataProvider;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class ConditionalFormattingExpressionTest extends TestCase
|
|
{
|
|
/** @param mixed[][] $expectedRule */
|
|
#[DataProvider('conditionalFormattingProvider')]
|
|
public function testReadConditionalFormatting(string $expectedRange, array $expectedRule): void
|
|
{
|
|
$filename = 'tests/data/Reader/XLS/CF_Expression_Comparisons.xls';
|
|
$reader = new Xls();
|
|
$spreadsheet = $reader->load($filename);
|
|
$sheet = $spreadsheet->getActiveSheet();
|
|
$hasConditionalStyles = $sheet->conditionalStylesExists($expectedRange);
|
|
self::assertTrue($hasConditionalStyles);
|
|
|
|
$conditionalStyles = $sheet->getConditionalStyles($expectedRange);
|
|
|
|
foreach ($conditionalStyles as $index => $conditionalStyle) {
|
|
self::assertSame($expectedRule[$index]['type'], $conditionalStyle->getConditionType());
|
|
self::assertSame($expectedRule[$index]['operator'], $conditionalStyle->getOperatorType());
|
|
self::assertSame($expectedRule[$index]['conditions'], $conditionalStyle->getConditions());
|
|
}
|
|
$spreadsheet->disconnectWorksheets();
|
|
}
|
|
|
|
public static function conditionalFormattingProvider(): array
|
|
{
|
|
return [
|
|
[
|
|
'A3:D8',
|
|
[
|
|
[
|
|
'type' => Conditional::CONDITION_EXPRESSION,
|
|
'operator' => Conditional::OPERATOR_NONE,
|
|
'conditions' => [
|
|
'$C1="USA"',
|
|
],
|
|
],
|
|
],
|
|
],
|
|
[
|
|
'A13:D18',
|
|
[
|
|
[
|
|
'type' => Conditional::CONDITION_EXPRESSION,
|
|
'operator' => Conditional::OPERATOR_NONE,
|
|
'conditions' => [
|
|
'AND($C1="USA",$D1="Q4")',
|
|
],
|
|
],
|
|
],
|
|
],
|
|
];
|
|
}
|
|
}
|