mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-09-08 17:16:25 +00:00
14a641f924
A large volume of changes due to "sealed" arrays. Some are sensible; some are very confusing and are handled with `ignore` annotations. Modules in src with changed code (as opposed to doc-blocks or annotations) are: - DateTimeExcelDays - Reader/Xlsx - Reader/Xlsx/AutoFilter - Reader/Xlsx/Chart - Reader/Xlsx/ConditionalStyles - Reader/Xlsx/TableReader
82 lines
2.8 KiB
PHP
82 lines
2.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Style\ConditionalFormatting\Wizard;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Exception;
|
|
use PhpOffice\PhpSpreadsheet\Style\Conditional;
|
|
use PhpOffice\PhpSpreadsheet\Style\ConditionalFormatting\Wizard;
|
|
use PhpOffice\PhpSpreadsheet\Style\Style;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class DateValueWizardTest extends TestCase
|
|
{
|
|
protected Style $style;
|
|
|
|
protected string $range = '$C$3:$E$5';
|
|
|
|
protected Wizard $wizardFactory;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
$this->wizardFactory = new Wizard($this->range);
|
|
$this->style = new Style();
|
|
}
|
|
|
|
#[\PHPUnit\Framework\Attributes\DataProvider('dateValueWizardProvider')]
|
|
public function testDateValueWizard(string $operator, string $expectedReference, string $expectedExpression): void
|
|
{
|
|
$ruleType = Wizard::DATES_OCCURRING;
|
|
/** @var Wizard\DateValue $dateWizard */
|
|
$dateWizard = $this->wizardFactory->newRule($ruleType);
|
|
$dateWizard->setStyle($this->style);
|
|
|
|
$dateWizard->$operator();
|
|
|
|
$conditional = $dateWizard->getConditional();
|
|
self::assertSame(Conditional::CONDITION_TIMEPERIOD, $conditional->getConditionType());
|
|
self::assertSame($expectedReference, $conditional->getText());
|
|
$conditions = $conditional->getConditions();
|
|
self::assertSame([$expectedExpression], $conditions);
|
|
|
|
$newWizard = Wizard::fromConditional($conditional, $this->range);
|
|
$newWizard->getConditional();
|
|
self::assertEquals($newWizard, $dateWizard, 'fromConditional() Failure');
|
|
}
|
|
|
|
public static function dateValueWizardProvider(): array
|
|
{
|
|
return [
|
|
['today', 'today', 'FLOOR(C3,1)=TODAY()'],
|
|
['yesterday', 'yesterday', 'FLOOR(C3,1)=TODAY()-1'],
|
|
['tomorrow', 'tomorrow', 'FLOOR(C3,1)=TODAY()+1'],
|
|
['lastSevenDays', 'last7Days', 'AND(TODAY()-FLOOR(C3,1)<=6,FLOOR(C3,1)<=TODAY())'],
|
|
];
|
|
}
|
|
|
|
public function testInvalidFromConditional(): void
|
|
{
|
|
$ruleType = 'Unknown';
|
|
$this->expectException(Exception::class);
|
|
$this->expectExceptionMessage('Conditional is not a Date Value CF Rule conditional');
|
|
|
|
$conditional = new Conditional();
|
|
$conditional->setConditionType($ruleType);
|
|
Wizard\DateValue::fromConditional($conditional);
|
|
}
|
|
|
|
protected string $unknown = 'UNKNOWN';
|
|
|
|
public function testInvalidOperator(): void
|
|
{
|
|
$this->expectException(Exception::class);
|
|
$this->expectExceptionMessage('Invalid Operation for Date Value CF Rule Wizard');
|
|
$ruleType = Wizard::DATES_OCCURRING;
|
|
/** @var Wizard\DateValue $wizard */
|
|
$wizard = $this->wizardFactory->newRule($ruleType);
|
|
$ruleType = $this->unknown;
|
|
$wizard->$ruleType();
|
|
}
|
|
}
|